Fix indentation. Update doxygen comments

This commit is contained in:
Henrik Stickann
2023-02-02 22:22:14 +01:00
parent fc4eed38d5
commit 59585b2ae5
46 changed files with 2020 additions and 1960 deletions

View File

@@ -6,16 +6,11 @@
#define STA_CORE_CAN_CONTROLLER_HPP
/**
* @defgroup can CAN
* @defgroup sta_core_can CAN
* @ingroup sta_core
* @brief CAN controller driver interface.
*/
/**
* @defgroup canAPI API
* @ingroup can
* @brief Public interface.
*/
#include <sta/can/filter.hpp>
#include <sta/can/headers.hpp>
@@ -24,96 +19,96 @@
namespace sta
{
/**
* @brief CAN controller driver interface.
*
* @ingroup canAPI
*/
class CanController
{
public:
// RX/TX
//
/**
* @brief CAN controller driver interface.
*
* @ingroup sta_core_can
*/
class CanController
{
public:
// RX/TX
//
/**
* @brief Send frame to CAN controller for transmission.
*
* @param header CAN frame TX header
* @param payload CAN frame payload
* @return True on success
*/
virtual bool sendFrame(const CanTxHeader & header, const uint8_t * payload) = 0;
/**
* @brief Send frame to CAN controller for transmission.
*
* @param header CAN frame TX header
* @param payload CAN frame payload
* @return True on success
*/
virtual bool sendFrame(const CanTxHeader & header, const uint8_t * payload) = 0;
/**
* @brief Get received frame from the CAN controller.
*
* @param[in] fifo FIFO storing frame
* @param[out] header CAN frame RX header destination
* @param[out] payload CAN frame payload destination
* @return True on success
*/
virtual bool receiveFrame(uint8_t fifo, CanRxHeader * header, uint8_t * payload) = 0;
/**
* @brief Get received frame from the CAN controller.
*
* @param[in] fifo FIFO storing frame
* @param[out] header CAN frame RX header destination
* @param[out] payload CAN frame payload destination
* @return True on success
*/
virtual bool receiveFrame(uint8_t fifo, CanRxHeader * header, uint8_t * payload) = 0;
/**
* @brief Get RX FIFO flags.
*
* @return FIFO flags
*/
virtual uint32_t getRxFifoFlags() = 0;
/**
* @brief Get RX FIFO flags.
*
* @return FIFO flags
*/
virtual uint32_t getRxFifoFlags() = 0;
/**
* @brief Get list of RX FIFO indices with pending messages.
*/
virtual CanPendingRxFifos getPendingRxFifos() = 0;
/**
* @brief Get list of RX FIFO indices with pending messages.
*/
virtual CanPendingRxFifos getPendingRxFifos() = 0;
// RX filter
//
// RX filter
//
/**
* @brief Change filter settings.
*
* @param idx Filter index
* @param filter Filter configuration
* @param active Enable filter after applying settings
*/
virtual void configureFilter(uint8_t idx, const CanFilter & filter, bool active = false) = 0;
/**
* @brief Enable filter.
*
* @param idx Filter index
*/
virtual void enableFilter(uint8_t idx) = 0;
/**
* @brief Disable filter.
*
* @param idx Filter index
*/
virtual void disableFilter(uint8_t idx) = 0;
/**
* @brief Disable and clear all filters.
*/
virtual void clearFilters() = 0;
/**
* @brief Change filter settings.
*
* @param idx Filter index
* @param filter Filter configuration
* @param active Enable filter after applying settings
*/
virtual void configureFilter(uint8_t idx, const CanFilter & filter, bool active = false) = 0;
/**
* @brief Enable filter.
*
* @param idx Filter index
*/
virtual void enableFilter(uint8_t idx) = 0;
/**
* @brief Disable filter.
*
* @param idx Filter index
*/
virtual void disableFilter(uint8_t idx) = 0;
/**
* @brief Disable and clear all filters.
*/
virtual void clearFilters() = 0;
// Info
//
// Info
//
/**
* @brief Get number of available filters.
*/
virtual uint8_t maxFilterCount() const = 0;
/**
* @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 number of available FIFOs.
*/
virtual uint8_t maxFifoCount() const = 0;
/**
* @brief Get maximum supported payload size.
*/
virtual uint8_t maxPayloadSize() const = 0;
};
/**
* @brief Get maximum supported payload size.
*/
virtual uint8_t maxPayloadSize() const = 0;
};
} // namespace sta

View File

@@ -12,37 +12,37 @@
namespace sta
{
/**
* @defgroup canFilter Filters
* @ingroup canAPI
* @brief CAN message filter types.
*/
/**
* @defgroup sta_core_can_filters Filters
* @ingroup sta_core_can
* @brief CAN message filter types.
* @{
*/
/**
* @brief ID format matched by CAN filter.
*
* @ingroup canFilter
*/
enum class CanFilterIdFormat
{
ANY, /**< Match both ID formats */
STD, /**< Match standard format IDs */
EXT /**< Match extended format IDs */
};
/**
* @brief ID format matched by CAN filter.
*/
enum class CanFilterIdFormat
{
ANY, /**< Match both ID formats */
STD, /**< Match standard format IDs */
EXT /**< Match extended format IDs */
};
/**
* @brief CAN filter settings.
*
* @ingroup canFilter
*/
struct CanFilter
{
CanId obj; /**< ID object */
CanId mask; /**< ID mask */
CanFilterIdFormat type; /**< ID format to match */
uint8_t fifo; /**< FIFO to store matches */
};
/**
* @brief CAN filter settings.
*/
struct CanFilter
{
CanId obj; /**< ID object */
CanId mask; /**< ID mask */
CanFilterIdFormat type; /**< ID format to match */
uint8_t fifo; /**< FIFO to store matches */
};
/** @} */
} // namespace sta

View File

@@ -12,36 +12,36 @@
namespace sta
{
/**
* @defgroup canHeader Frame headers
* @ingroup canAPI
* @brief CAN header types for transmitted / received frames.
*/
/**
* @defgroup sta_core_can_headers Frame headers
* @ingroup sta_core_can
* @brief CAN header types for transmitted / received frames.
* @{
*/
/**
* @brief CAN TX frame header.
*
* @ingroup canHeader
*/
struct CanTxHeader
{
CanFrameId id; /**< Frame ID */
uint8_t payloadLength; /**< Size of data to send */
};
/**
* @brief CAN TX frame header.
*/
struct CanTxHeader
{
CanFrameId id; /**< Frame ID */
uint8_t payloadLength; /**< Size of data to send */
};
/**
* @brief CAN RX frame header.
*
* @ingroup canHeader
*/
struct CanRxHeader
{
CanFrameId id; /**< Frame ID */
uint8_t payloadLength; /**< Size of received data */
uint32_t timestamp; /**< RX timestamp */
uint8_t filter; /**< RX filter match */
};
/**
* @brief CAN RX frame header.
*/
struct CanRxHeader
{
CanFrameId id; /**< Frame ID */
uint8_t payloadLength; /**< Size of received data */
uint32_t timestamp; /**< RX timestamp */
uint8_t filter; /**< RX filter match */
};
/** @} */
} // namespace sta

View File

@@ -10,107 +10,99 @@
namespace sta
{
/**
* @defgroup canID Frame IDs
* @ingroup canAPI
* @brief Types for working with CAN ID values and formats.
*/
/**
* @defgroup sta_core_can_ids Frame IDs
* @ingroup sta_core_can
* @brief Types for working with CAN ID values and formats.
*/
/**
* @brief CAN frame ID format.
*
* @ingroup canID
*/
enum class CanIdFormat : uint8_t
{
STD, /**< Standard format */
EXT /**< Extended format */
};
/**
* @brief CAN frame ID format.
*
* @ingroup sta_core_can_ids
*/
enum class CanIdFormat : uint8_t
{
STD, /**< Standard format */
EXT /**< Extended format */
};
/**
* @brief CAN frame ID.
*
* @ingroup canID
*/
struct CanId
{
uint32_t sid; /**< Standard ID field (11 bits) */
uint32_t eid; /**< Extended ID field (18 bits) */
};
/**
* @brief CAN frame ID.
*
* @ingroup sta_core_can_ids
*/
struct CanId
{
uint32_t sid; /**< Standard ID field (11 bits) */
uint32_t eid; /**< Extended ID field (18 bits) */
};
/**
* @brief CAN frame ID and format.
*
* @ingroup canID
*/
struct CanFrameId
{
CanIdFormat format; /**< ID format */
uint32_t sid; /**< Standard ID field (11 bits) */
uint32_t eid; /**< Extended ID field (18 bits) */
};
/**
* @brief CAN frame ID and format.
*
* @ingroup sta_core_can_ids
*/
struct CanFrameId
{
CanIdFormat format; /**< ID format */
uint32_t sid; /**< Standard ID field (11 bits) */
uint32_t eid; /**< Extended ID field (18 bits) */
};
// Comparison operators
//
// Comparison operators
//
/**
* @brief Equal to operator.
*
* @param lhs Left hand side CAN ID
* @param rhs Right hand side CAN ID
* @return True if CAN IDs are equal
*
* @ingroup canID
*/
bool operator ==(const CanId & lhs, const CanId & rhs);
/**
* @brief Not equal to operator.
*
* @param lhs Left hand side CAN ID
* @param rhs Right hand side CAN ID
* @return True if CAN IDs are not equal
*
* @ingroup canID
*/
bool operator !=(const CanId & lhs, const CanId & rhs);
/**
* @brief Equal to operator.
*
* @param lhs Left hand side CAN ID
* @param rhs Right hand side CAN ID
* @return True if CAN IDs are equal
*/
bool operator ==(const CanId & lhs, const CanId & rhs);
/**
* @brief Not equal to operator.
*
* @param lhs Left hand side CAN ID
* @param rhs Right hand side CAN ID
* @return True if CAN IDs are not equal
*/
bool operator !=(const CanId & lhs, const CanId & rhs);
/**
* @brief Equal to operator.
*
* @param lhs Left hand side CAN Frame ID
* @param rhs Right hand side CAN Frame ID
* @return True if CAN Frame IDs are equal
*
* @ingroup canID
*/
bool operator ==(const CanFrameId & lhs, const CanFrameId & rhs);
/**
* @brief Not equal to operator.
*
* @param lhs Left hand side CAN Frame ID
* @param rhs Right hand side CAN Frame ID
* @return True if CAN Frame IDs are not equal
*
* @ingroup canID
*/
bool operator !=(const CanFrameId & lhs, const CanFrameId & rhs);
/**
* @brief Equal to operator.
*
* @param lhs Left hand side CAN Frame ID
* @param rhs Right hand side CAN Frame ID
* @return True if CAN Frame IDs are equal
*/
bool operator ==(const CanFrameId & lhs, const CanFrameId & rhs);
/**
* @brief Not equal to operator.
*
* @param lhs Left hand side CAN Frame ID
* @param rhs Right hand side CAN Frame ID
* @return True if CAN Frame IDs are not equal
*/
bool operator !=(const CanFrameId & lhs, const CanFrameId & rhs);
} // namespace sta
/**
* @brief Maximum CAN standard ID value.
*
* @ingroup canID
* @ingroup sta_core_can_ids
*/
#define CAN_SID_MAX UINT32_C(0x7FF)
/**
* @brief Maximum CAN extended ID value.
*
* @ingroup canID
* @ingroup sta_core_can_ids
*/
#define CAN_EID_MAX UINT32_C(0x3FFFF)

View File

@@ -10,57 +10,72 @@
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;
/**
* @brief Iterable container interface for CAN RX flags.
*
* @ingroup sta_core_can_ids
*/
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 *;
/**
* @brief Custom iterator for active RX queues.
*/
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);
public:
const_iterator(const const_iterator & iter);
const_iterator & operator=(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;
bool operator==(const const_iterator & iter) const;
bool operator!=(const const_iterator & iter) const;
const_iterator & operator++();
const_iterator operator++(int);
const_iterator & operator++();
const_iterator operator++(int);
reference operator*() const;
reference operator*() const;
private:
const_iterator(uint32_t rxFlags, uint8_t idx, uint8_t endIdx);
private:
const_iterator(uint32_t rxFlags, uint8_t idx, uint8_t endIdx);
bool isRxPending() const;
/**
* @brief Check if current RX queue has pending data.
*/
bool isRxPending() const;
friend class CanPendingRxFifos;
friend class CanPendingRxFifos;
private:
uint32_t rxFlags_;
uint8_t idx_;
uint8_t endIdx_;
};
private:
uint32_t rxFlags_; /**< RX flag bits */
uint8_t idx_; /**< Current flag index */
uint8_t endIdx_; /**< Iterator end index */
};
public:
CanPendingRxFifos(uint32_t rxFlags, uint8_t numFifos);
public:
/**
* @param rxFlags RX flag bits
* @param numFifos Number of RX FIFOs
*/
CanPendingRxFifos(uint32_t rxFlags, uint8_t numFifos);
const_iterator begin() const;
const_iterator end() const;
const_iterator begin() const;
const_iterator end() const;
private:
uint32_t rxFlags_;
uint8_t numFifos_;
};
private:
uint32_t rxFlags_; /**< RX flag bits */
uint8_t numFifos_; /**< Number of RX FIFOs */
};
} // namespace sta

View File

@@ -11,90 +11,88 @@
namespace sta
{
/**
* @defgroup canSub Subscription
* @ingroup canAPI
* @brief Subscription interface for CAN controller drivers.
*/
/**
* @defgroup sta_core_can_sub Subscription
* @ingroup sta_core_can
* @brief Subscription interface for CAN controller drivers.
* @{
*/
/**
* @brief Callback for handling received frames.
*
* @param header Frame header
* @param buffer Frame payload buffer
*
* @ingroup canSub
*/
using CanRxCallback = void (*) (const CanRxHeader & header, const uint8_t * buffer);
/**
* @brief Callback for handling received frames.
*
* @param header Frame header
* @param buffer Frame payload buffer
*/
using CanRxCallback = void (*) (const CanRxHeader & header, const uint8_t * buffer);
/**
* @brief Filter configuration and message handler.
*
* @ingroup canSub
*/
struct CanFilterConfig
{
CanFilter filter; /**< Filter handled by callback */
CanRxCallback callback; /**< Callback for message handling */
};
/**
* @brief Filter configuration and message handler.
*/
struct CanFilterConfig
{
CanFilter filter; /**< Filter handled by callback */
CanRxCallback callback; /**< Callback for message handling */
};
/**
* @brief CAN controller with subscriptions.
*
* @tparam T Implementation of CanController interface
*
* @ingroup canSub
*/
template <typename T>
class SubscribableCanController : public T
{
public:
using T::T;
/**
* @brief CAN controller with subscriptions.
*
* @tparam T Implementation of CanController interface
*/
template <typename T>
class SubscribableCanController : public T
{
public:
using T::T;
// Subscriptions
//
// Subscriptions
//
/**
* @brief Subscribe to specific message types.
*
* @param subscriptions Array of message filters and handlers
* @param num Number of array entries
*/
bool subscribe(const CanFilterConfig * subscriptions, uint8_t num);
/**
* @brief Subscribe to specific message types.
*
* @param subscriptions Array of message filters and handlers
* @param num Number of array entries
*/
bool subscribe(const CanFilterConfig * subscriptions, uint8_t num);
/**
* @brief Subscribe to all messages.
*
* @param callback Called when message is received
* @param fifo FIFO used for received messages
*/
void subscribeAll(CanRxCallback callback, uint8_t fifo);
/**
* @brief Subscribe to all messages.
*
* @param callback Called when message is received
* @param fifo FIFO used for received messages
*/
void subscribeAll(CanRxCallback callback, uint8_t fifo);
/**
* @brief Unsubscribe from all messages.
*
* No more messages will be received.
*/
void unsubscribeAll();
/**
* @brief Unsubscribe from all messages.
*
* No more messages will be received.
*/
void unsubscribeAll();
/**
* @brief Read message from RX FIFO and notify subscriber.
*/
void receiveAndNotify(uint8_t fifo);
/**
* @brief Read message from RX FIFO and notify subscriber.
*/
void receiveAndNotify(uint8_t fifo);
/**
* @brief Process pending frames from RX FIFOs.
*/
void processMessages();
/**
* @brief Process pending frames from RX FIFOs.
*/
void processMessages();
private:
CanRxCallback filterCallbacks_[T::MAX_FILTER_COUNT]; /**< Callbacks for RX filters */
};
private:
CanRxCallback filterCallbacks_[T::MAX_FILTER_COUNT]; /**< Callbacks for RX filters */
};
/** @} */
} // namespace sta

View File

@@ -15,105 +15,105 @@
namespace sta
{
template <typename T>
bool SubscribableCanController<T>::subscribe(const CanFilterConfig * subscriptions, uint8_t num)
{
// Check bounds
if (num > T::MAX_FILTER_COUNT)
return false;
template <typename T>
bool SubscribableCanController<T>::subscribe(const CanFilterConfig * subscriptions, uint8_t num)
{
// Check bounds
if (num > T::MAX_FILTER_COUNT)
return false;
// Clear previous subscriptions
unsubscribeAll();
// Clear previous subscriptions
unsubscribeAll();
for (uint8_t i = 0; i < num; ++i)
{
// Save handler callback
filterCallbacks_[i] = subscriptions[i].callback;
for (uint8_t i = 0; i < num; ++i)
{
// Save handler callback
filterCallbacks_[i] = subscriptions[i].callback;
// Configure and enable filter
T::configureFilter(i, subscriptions[i].filter, true);
}
// Configure and enable filter
T::configureFilter(i, subscriptions[i].filter, true);
}
return true;
}
return true;
}
template <typename T>
void SubscribableCanController<T>::subscribeAll(CanRxCallback callback, uint8_t fifo)
{
uint8_t filterIdx = 0;
template <typename T>
void SubscribableCanController<T>::subscribeAll(CanRxCallback callback, uint8_t fifo)
{
uint8_t filterIdx = 0;
// Clear previous subscriptions
unsubscribeAll();
// Clear previous subscriptions
unsubscribeAll();
// Setup default filter
CanFilter filter{};
filter.type = CanFilterIdFormat::ANY;
filter.fifo = fifo;
// Setup default filter
CanFilter filter{};
filter.type = CanFilterIdFormat::ANY;
filter.fifo = fifo;
// Store callback
filterCallbacks_[filterIdx] = callback;
// Store callback
filterCallbacks_[filterIdx] = callback;
// Configure and enable default filter
T::configureFilter(filterIdx, filter, true);
}
// Configure and enable default filter
T::configureFilter(filterIdx, filter, true);
}
template <typename T>
void SubscribableCanController<T>::unsubscribeAll()
{
// Disable all filters
T::clearFilters();
template <typename T>
void SubscribableCanController<T>::unsubscribeAll()
{
// Disable all filters
T::clearFilters();
// Clear filter callbacks
// Clear filter callbacks
#ifndef STA_STDLIB_DISABLE
std::fill_n(filterCallbacks_, T::MAX_FILTER_COUNT, nullptr);
std::fill_n(filterCallbacks_, T::MAX_FILTER_COUNT, nullptr);
#else // STA_STDLIB_DISABLE
for (uint8_t i = 0; i < T::MAX_FILTER_COUNT; ++i)
{
filterCallbacks_[i] = nullptr;
}
for (uint8_t i = 0; i < T::MAX_FILTER_COUNT; ++i)
{
filterCallbacks_[i] = nullptr;
}
#endif // STA_STDLIB_DISABLE
}
}
template <typename T>
void SubscribableCanController<T>::receiveAndNotify(uint8_t fifo)
{
CanRxHeader header;
uint8_t payload[T::MAX_PAYLOAD_SIZE];
template <typename T>
void SubscribableCanController<T>::receiveAndNotify(uint8_t fifo)
{
CanRxHeader header;
uint8_t payload[T::MAX_PAYLOAD_SIZE];
if (T::receiveFrame(fifo, &header, payload))
{
//displayFrameUART(frame);
if (T::receiveFrame(fifo, &header, payload))
{
//displayFrameUART(frame);
// Forward frame to filter callback
if (fifo <= T::MAX_FILTER_COUNT && filterCallbacks_[header.filter])
{
filterCallbacks_[header.filter](header, payload);
}
}
}
// Forward frame to filter callback
if (fifo <= T::MAX_FILTER_COUNT && filterCallbacks_[header.filter])
{
filterCallbacks_[header.filter](header, payload);
}
}
}
template <typename T>
void SubscribableCanController<T>::processMessages()
{
// Read RX interrupt flags
uint32_t RFIF = T::getRxFifoFlags();
template <typename T>
void SubscribableCanController<T>::processMessages()
{
// Read RX interrupt flags
uint32_t RFIF = T::getRxFifoFlags();
if (RFIF != 0)
{
// Check all flags
for (uint8_t fifo = 0; fifo < T::MAX_FIFO_COUNT; ++fifo)
{
// Process messages if flag is set
if (RFIF & 0x1)
{
receiveAndNotify(fifo);
}
if (RFIF != 0)
{
// Check all flags
for (uint8_t fifo = 0; fifo < T::MAX_FIFO_COUNT; ++fifo)
{
// Process messages if flag is set
if (RFIF & 0x1)
{
receiveAndNotify(fifo);
}
// Shift next RX flag to LSB
RFIF >>= 1;
}
}
}
// Shift next RX flag to LSB
RFIF >>= 1;
}
}
}
} // namespace sta