mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-09-29 05:17:33 +00:00
Add pending RX api
This commit is contained in:
95
src/can/iter.cpp
Normal file
95
src/can/iter.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <sta/can/iter.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
CanPendingRxFifos::const_iterator::const_iterator(uint32_t rxFlags, uint8_t idx, uint8_t endIdx)
|
||||
: rxFlags_{rxFlags}, idx_{idx}, endIdx_{endIdx}
|
||||
{}
|
||||
|
||||
CanPendingRxFifos::const_iterator::const_iterator(const const_iterator & iter)
|
||||
: rxFlags_{iter.rxFlags_}, idx_{iter.idx_}, endIdx_{iter.endIdx_}
|
||||
{}
|
||||
|
||||
|
||||
CanPendingRxFifos::const_iterator & CanPendingRxFifos::const_iterator::operator=(const const_iterator & iter)
|
||||
{
|
||||
rxFlags_ = iter.rxFlags_;
|
||||
idx_ = iter.idx_;
|
||||
endIdx_ = iter.endIdx_;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool CanPendingRxFifos::const_iterator::operator==(const const_iterator & iter) const
|
||||
{
|
||||
return (rxFlags_ == iter.rxFlags_) && (idx_ == iter.idx_) && (endIdx_ == iter.endIdx_);
|
||||
}
|
||||
|
||||
bool CanPendingRxFifos::const_iterator::operator!=(const const_iterator & iter) const
|
||||
{
|
||||
return !(*this == iter);
|
||||
}
|
||||
|
||||
|
||||
CanPendingRxFifos::const_iterator & CanPendingRxFifos::const_iterator::operator++()
|
||||
{
|
||||
while (idx_ < endIdx_)
|
||||
{
|
||||
++idx_;
|
||||
if (isRxPending())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CanPendingRxFifos::const_iterator CanPendingRxFifos::const_iterator::operator++(int)
|
||||
{
|
||||
uint8_t oldIdx = idx_;
|
||||
|
||||
while (idx_ < endIdx_)
|
||||
{
|
||||
++idx_;
|
||||
if (isRxPending())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return const_iterator(rxFlags_, oldIdx, endIdx_);
|
||||
}
|
||||
|
||||
CanPendingRxFifos::const_iterator::reference CanPendingRxFifos::const_iterator::operator*() const
|
||||
{
|
||||
STA_ASSERT_MSG(idx_ != endIdx_, "Dereferencing out-of-bounds iterator");
|
||||
|
||||
return idx_;
|
||||
}
|
||||
|
||||
bool CanPendingRxFifos::const_iterator::isRxPending() const
|
||||
{
|
||||
return ( (rxFlags_ >> idx_) & 0x1 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
CanPendingRxFifos::CanPendingRxFifos(uint32_t rxFlags, uint8_t numFifos)
|
||||
: rxFlags_{rxFlags}, numFifos_{numFifos}
|
||||
{}
|
||||
|
||||
CanPendingRxFifos::const_iterator CanPendingRxFifos::begin() const
|
||||
{
|
||||
return const_iterator(rxFlags_, 0, numFifos_);
|
||||
}
|
||||
|
||||
CanPendingRxFifos::const_iterator CanPendingRxFifos::end() const
|
||||
{
|
||||
return const_iterator(rxFlags_, numFifos_, numFifos_);
|
||||
}
|
||||
} // namespace sta
|
Reference in New Issue
Block a user