HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
BaseCan.h File Reference

Abstract base class for CAN bus implementations in the HardFOC system. More...

#include "HardwareTypes.h"
#include <atomic>
#include <cstdint>
#include <string_view>
Include dependency graph for BaseCan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hf_can_config_t
 Platform-agnostic CAN bus configuration. More...
 
struct  hf_can_message_t
 Platform-agnostic CAN message structure. More...
 
struct  hf_can_status_t
 CAN bus status information structure. More...
 
struct  hf_can_reception_info_t
 CAN-FD specific receive callback with enhanced information. More...
 
struct  hf_can_statistics_t
 CAN bus statistics structure for performance monitoring. More...
 
struct  hf_can_diagnostics_t
 CAN diagnostics structure for detailed error analysis. More...
 
class  BaseCan
 Abstract base class defining the unified CAN bus API. More...
 

Macros

#define HF_CAN_ERR_LIST(X)
 HardFOC CAN error codes.
 
#define X(NAME, VALUE, DESC)   NAME = VALUE,
 
#define X(NAME, VALUE, DESC)
 

Typedefs

using hf_can_receive_callback_t = void (*)(const hf_can_message_t& message)
 CAN message receive callback function type.
 
using hf_can_fd_receive_callback_t
 

Enumerations

enum class  hf_can_err_t : hf_u8_t {
  X , CAN_SUCCESS = 0 , CAN_ERR_FAILURE = 1 , CAN_ERR_NOT_INITIALIZED = 2 ,
  CAN_ERR_ALREADY_INITIALIZED = 3 , CAN_ERR_INVALID_PARAMETER = 4 , CAN_ERR_NULL_POINTER = 5 , CAN_ERR_OUT_OF_MEMORY = 6 ,
  CAN_ERR_BUS_OFF = 7 , CAN_ERR_BUS_ERROR = 8 , CAN_ERR_BUS_BUSY = 9 , CAN_ERR_BUS_NOT_AVAILABLE = 10 ,
  CAN_ERR_BUS_RECOVERY_FAILED = 11 , CAN_ERR_BUS_ARBITRATION_LOST = 12 , CAN_ERR_MESSAGE_TIMEOUT = 13 , CAN_ERR_MESSAGE_LOST = 14 ,
  CAN_ERR_MESSAGE_INVALID = 15 , CAN_ERR_MESSAGE_TOO_LONG = 16 , CAN_ERR_MESSAGE_INVALID_ID = 17 , CAN_ERR_MESSAGE_INVALID_DLC = 18 ,
  CAN_ERR_QUEUE_FULL = 19 , CAN_ERR_QUEUE_EMPTY = 20 , CAN_ERR_TX_FAILED = 21 , CAN_ERR_TX_ABORTED = 22 ,
  CAN_ERR_TX_ERROR_PASSIVE = 23 , CAN_ERR_TX_ERROR_WARNING = 24 , CAN_ERR_RX_OVERRUN = 25 , CAN_ERR_RX_ERROR_PASSIVE = 26 ,
  CAN_ERR_RX_ERROR_WARNING = 27 , CAN_ERR_RX_FIFO_FULL = 28 , CAN_ERR_HARDWARE_FAULT = 29 , CAN_ERR_COMMUNICATION_FAILURE = 30 ,
  CAN_ERR_DEVICE_NOT_RESPONDING = 31 , CAN_ERR_VOLTAGE_OUT_OF_RANGE = 32 , CAN_ERR_CLOCK_ERROR = 33 , CAN_ERR_TRANSCEIVER_ERROR = 34 ,
  CAN_ERR_INVALID_CONFIGURATION = 35 , CAN_ERR_UNSUPPORTED_OPERATION = 36 , CAN_ERR_INVALID_BAUD_RATE = 37 , CAN_ERR_INVALID_CONTROLLER_ID = 38 ,
  CAN_ERR_FILTER_ERROR = 39 , CAN_ERR_FILTER_FULL = 40 , CAN_ERR_STUFF_ERROR = 41 , CAN_ERR_FORM_ERROR = 42 ,
  CAN_ERR_CRC_ERROR = 43 , CAN_ERR_ACK_ERROR = 44 , CAN_ERR_BIT_ERROR = 45 , CAN_ERR_SYSTEM_ERROR = 46 ,
  CAN_ERR_PERMISSION_DENIED = 47 , CAN_ERR_OPERATION_ABORTED = 48 , CAN_ERR_FAIL = 49 , CAN_ERR_RESOURCE_BUSY = 50 ,
  CAN_ERR_INVALID_STATE = 51 , CAN_ERR_NOT_SUPPORTED = 52 , CAN_ERR_TIMEOUT_ALT = 53 , CAN_ERR_UNKNOWN = 54
}
 

Functions

constexpr std::string_view HfCanErrToString (hf_can_err_t err) noexcept
 Convert hf_can_err_t to human-readable string.
 

Detailed Description

Abstract base class for CAN bus implementations in the HardFOC system.

This header-only file defines the abstract base class for CAN bus communication that provides a consistent API across different CAN controller implementations. Concrete implementations for various microcontrollers inherit from this class.

ERROR HANDLING:

  • All CAN error codes are defined in this file using the hf_can_err_t enumeration
  • Lower-level types (McuTypes_CAN.h) maintain minimal error constants for compatibility
  • All virtual methods return hf_can_err_t for comprehensive error reporting
  • No legacy compatibility code - use hf_can_message_t structure for all operations
Author
Nebiyu Tadesse
Date
2025
Note
This is a header-only abstract base class following the same pattern as BaseAdc.
Users should program against this interface, not specific implementations.
All legacy camelCase types and bool-returning methods have been removed.

Macro Definition Documentation

◆ X [1/2]

#define X ( NAME,
VALUE,
DESC )   NAME = VALUE,

◆ X [2/2]

#define X ( NAME,
VALUE,
DESC )
Value:
case hf_can_err_t::NAME: \
return DESC;

Typedef Documentation

◆ hf_can_fd_receive_callback_t

Initial value:
void (*)(const hf_can_message_t& message, const hf_can_reception_info_t& info)
Platform-agnostic CAN message structure.
Definition BaseCan.h:165
CAN-FD specific receive callback with enhanced information.
Definition BaseCan.h:340

◆ hf_can_receive_callback_t

using hf_can_receive_callback_t = void (*)(const hf_can_message_t& message)

CAN message receive callback function type.

Note
Updated to use new hf_can_message_t structure

Enumeration Type Documentation

◆ hf_can_err_t

enum class hf_can_err_t : hf_u8_t
strong
Enumerator
CAN_SUCCESS 
CAN_ERR_FAILURE 
CAN_ERR_NOT_INITIALIZED 
CAN_ERR_ALREADY_INITIALIZED 
CAN_ERR_INVALID_PARAMETER 
CAN_ERR_NULL_POINTER 
CAN_ERR_OUT_OF_MEMORY 
CAN_ERR_BUS_OFF 
CAN_ERR_BUS_ERROR 
CAN_ERR_BUS_BUSY 
CAN_ERR_BUS_NOT_AVAILABLE 
CAN_ERR_BUS_RECOVERY_FAILED 
CAN_ERR_BUS_ARBITRATION_LOST 
CAN_ERR_MESSAGE_TIMEOUT 
CAN_ERR_MESSAGE_LOST 
CAN_ERR_MESSAGE_INVALID 
CAN_ERR_MESSAGE_TOO_LONG 
CAN_ERR_MESSAGE_INVALID_ID 
CAN_ERR_MESSAGE_INVALID_DLC 
CAN_ERR_QUEUE_FULL 
CAN_ERR_QUEUE_EMPTY 
CAN_ERR_TX_FAILED 
CAN_ERR_TX_ABORTED 
CAN_ERR_TX_ERROR_PASSIVE 
CAN_ERR_TX_ERROR_WARNING 
CAN_ERR_RX_OVERRUN 
CAN_ERR_RX_ERROR_PASSIVE 
CAN_ERR_RX_ERROR_WARNING 
CAN_ERR_RX_FIFO_FULL 
CAN_ERR_HARDWARE_FAULT 
CAN_ERR_COMMUNICATION_FAILURE 
CAN_ERR_DEVICE_NOT_RESPONDING 
CAN_ERR_VOLTAGE_OUT_OF_RANGE 
CAN_ERR_CLOCK_ERROR 
CAN_ERR_TRANSCEIVER_ERROR 
CAN_ERR_INVALID_CONFIGURATION 
CAN_ERR_UNSUPPORTED_OPERATION 
CAN_ERR_INVALID_BAUD_RATE 
CAN_ERR_INVALID_CONTROLLER_ID 
CAN_ERR_FILTER_ERROR 
CAN_ERR_FILTER_FULL 
CAN_ERR_STUFF_ERROR 
CAN_ERR_FORM_ERROR 
CAN_ERR_CRC_ERROR 
CAN_ERR_ACK_ERROR 
CAN_ERR_BIT_ERROR 
CAN_ERR_SYSTEM_ERROR 
CAN_ERR_PERMISSION_DENIED 
CAN_ERR_OPERATION_ABORTED 
CAN_ERR_FAIL 
CAN_ERR_RESOURCE_BUSY 
CAN_ERR_INVALID_STATE 
CAN_ERR_NOT_SUPPORTED 
CAN_ERR_TIMEOUT_ALT 
CAN_ERR_UNKNOWN 

Function Documentation

◆ HfCanErrToString()

constexpr std::string_view HfCanErrToString ( hf_can_err_t err)
constexprnoexcept

Convert hf_can_err_t to human-readable string.

Parameters
errThe error code to convert
Returns
String view of the error description