Add pending RX api

This commit is contained in:
Henrik Stickann
2022-12-02 16:24:45 +01:00
parent 02ae632f60
commit 32819c1108
3 changed files with 183 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#include <sta/can/filter.hpp>
#include <sta/can/headers.hpp>
#include <sta/can/iter.hpp>
namespace sta
@@ -60,6 +61,11 @@ namespace sta
*/
virtual uint32_t getRxFifoFlags() = 0;
/**
* @brief Get list of RX FIFO indices with pending messages.
*/
virtual CanPendingRxFifos getPendingRxFifos() = 0;
// RX filter
//
@@ -88,6 +94,25 @@ namespace sta
* @brief Disable and clear all filters.
*/
virtual void clearFilters() = 0;
// Info
//
/**
* @brief Get number of available filters.
*/
virtual uint8_t maxFilterCount() const = 0;
/**
* @brief Get number of available FIFOs.
*/
virtual uint8_t maxFifoCount() const = 0;
/**
* @brief Get maximum supported payload size.
*/
virtual uint8_t maxPayloadSize() const = 0;
};
} // namespace sta

63
include/sta/can/iter.hpp Normal file
View File

@@ -0,0 +1,63 @@
#ifndef STA_CAN_ITER_HPP
#define STA_CAN_ITER_HPP
#include <cstdint>
namespace sta
{
class CanPendingRxFifos
{
public:
using value_type = uint8_t;
using reference = value_type &;
using const_reference = const value_type &;
using size_type = uint8_t;
class const_iterator
{
public:
using value_type = CanPendingRxFifos::value_type;
using reference = const_reference;
using pointer = const value_type *;
public:
const_iterator(const const_iterator & iter);
const_iterator & operator=(const const_iterator & iter);
bool operator==(const const_iterator & iter) const;
bool operator!=(const const_iterator & iter) const;
const_iterator & operator++();
const_iterator operator++(int);
reference operator*() const;
private:
const_iterator(uint32_t rxFlags, uint8_t idx, uint8_t endIdx);
bool isRxPending() const;
friend class CanPendingRxFifos;
private:
uint32_t rxFlags_;
uint8_t idx_;
uint8_t endIdx_;
};
public:
CanPendingRxFifos(uint32_t rxFlags, uint8_t numFifos);
const_iterator begin() const;
const_iterator end() const;
private:
uint32_t rxFlags_;
uint8_t numFifos_;
};
} // namespace sta
#endif // STA_CAN_ITER_HPP