2024-01-07 23:23:35 +01:00

114 lines
3.1 KiB
C++

/**
* @file
* @brief Custom iterators for CAN controllers.
*/
#ifndef STA_CORE_CAN_ITER_HPP
#define STA_CORE_CAN_ITER_HPP
#include <cstdint>
namespace sta
{
/**
* @brief Iterable container interface for CAN RX flags.
*
* @ingroup sta_core_can_ids
*/
class CanPendingRxFifos
{
public:
/// @brief Value type.
using value_type = uint8_t;
/// @brief Pointer to value type.
using reference = value_type &;
/// @brief Const pointer to value type.
using const_reference = const value_type &;
/// @brief Size of type.
using size_type = uint8_t;
/**
* @brief Custom iterator for active RX queues.
*/
class const_iterator
{
public:
/// @brief Value type.
using value_type = CanPendingRxFifos::value_type;
/// @brief Const pointer to value type.
using reference = const_reference;
/// @brief Pointer to value type.
using pointer = const value_type *;
public:
/// @brief Default constructor.
const_iterator(const const_iterator & iter);
/// @brief Copies the contents of the given iterator.
/// @param iter Iterator to be copied.
const_iterator & operator=(const const_iterator & iter);
/**
* @brief Compare iterators by flags, index and end index.
*/
bool operator==(const const_iterator & iter) const;
/**
* @brief Compare iterators by flags, index and end index.
*/
bool operator!=(const const_iterator & iter) const;
/**
* @brief Increment iterator to next pending RX queue.
*/
const_iterator & operator++();
/**
* @brief Increment iterator to next pending RX queue.
*/
const_iterator operator++(int);
/**
* @brief Dereference iterator at index.
*/
reference operator*() const;
private:
const_iterator(uint32_t rxFlags, uint8_t idx, uint8_t endIdx);
/**
* @brief Check if current RX queue has pending data.
*/
bool isRxPending() const;
friend class CanPendingRxFifos;
private:
uint32_t rxFlags_; /**< RX flag bits */
uint8_t idx_; /**< Current flag index */
uint8_t endIdx_; /**< Iterator end index */
};
public:
/**
* @param rxFlags RX flag bits
* @param numFifos Number of RX FIFOs
*/
CanPendingRxFifos(uint32_t rxFlags, uint8_t numFifos);
/**
* @brief Get iterator to first pending RX queue.
*/
const_iterator begin() const;
/**
* @brief Get iterator to end of RX queues.
*/
const_iterator end() const;
private:
uint32_t rxFlags_; /**< RX flag bits */
uint8_t numFifos_; /**< Number of RX FIFOs */
};
} // namespace sta
#endif // STA_CORE_CAN_ITER_HPP