11#ifndef CAN_COREX_CAN_COREX_H_
12#define CAN_COREX_CAN_COREX_H_
22#define CCX_VERSION_MAJOR 2
23#define CCX_VERSION_MINOR 3
24#define CCX_VERSION_PATCH 1
25#define CCX_VERSION_STRING "2.3.1"
45#ifndef CCX_TICK_FROM_FUNC
46#define CCX_TICK_FROM_FUNC 0
55#ifndef CCX_HR_TICK_FROM_FUNC
56#define CCX_HR_TICK_FROM_FUNC 0
65#ifndef CCX_RX_BUFFER_SIZE
66#define CCX_RX_BUFFER_SIZE 48
75#ifndef CCX_TX_BUFFER_SIZE
76#define CCX_TX_BUFFER_SIZE 48
87#define CCX_ENABLE_CANFD 1
88#elif !defined(CCX_ENABLE_CANFD)
89#define CCX_ENABLE_CANFD 0
110#define CCX_DLC_ANY 16
112#define CCX_DLC_ANY 15
123#ifndef CCX_RX_HASH_SIZE
124#define CCX_RX_HASH_SIZE 64
148#ifdef CCX_TIME_BASE_TYPE_CUSTOM
150 "CCX_TIME_BASE_TYPE_CUSTOM is no longer supported. Define exactly one of CCX_TIME_BASE_TYPE_CUSTOM_IS_UINT8/16/32/64."
153#ifdef CCX_HR_TIME_BASE_TYPE_CUSTOM
155 "CCX_HR_TIME_BASE_TYPE_CUSTOM is no longer supported. Define exactly one of CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_UINT8/16/32/64."
158#if defined(CCX_TIME_BASE_TYPE_CUSTOM_IS_INT8) || defined(CCX_TIME_BASE_TYPE_CUSTOM_IS_INT16) || \
159 defined(CCX_TIME_BASE_TYPE_CUSTOM_IS_INT32) || defined(CCX_TIME_BASE_TYPE_CUSTOM_IS_INT64)
161 "Signed primary time base types were a bug and must not be used. Use exactly one of CCX_TIME_BASE_TYPE_CUSTOM_IS_UINT16/32/64."
164#if defined(CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_INT8) || defined(CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_INT16) || \
165 defined(CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_INT32) || defined(CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_INT64)
167 "Signed high-resolution time base types were a bug and must not be used. Use exactly one of CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_UINT16/32/64."
170#if defined(CCX_TIME_BASE_TYPE_CUSTOM_IS_UINT8)
172 "CCX_TIME_BASE_TYPE_CUSTOM_IS_UINT8 is not supported because uint8_t has too small a range for this library. Use exactly one of CCX_TIME_BASE_TYPE_CUSTOM_IS_UINT16/32/64."
173 typedef volatile uint16_t CCX_TIME_t;
174#define CCX_TIME_BASE_SCALAR uint16_t
175#define CCX_MAX_TIMEOUT UINT16_MAX
176#elif defined(CCX_TIME_BASE_TYPE_CUSTOM_IS_UINT16)
177typedef volatile uint16_t CCX_TIME_t;
178#define CCX_TIME_BASE_SCALAR uint16_t
179#define CCX_MAX_TIMEOUT UINT16_MAX
180#elif defined(CCX_TIME_BASE_TYPE_CUSTOM_IS_UINT32)
181typedef volatile uint32_t CCX_TIME_t;
182#define CCX_TIME_BASE_SCALAR uint32_t
183#define CCX_MAX_TIMEOUT UINT32_MAX
184#elif defined(CCX_TIME_BASE_TYPE_CUSTOM_IS_UINT64)
185typedef volatile uint64_t CCX_TIME_t;
186#define CCX_TIME_BASE_SCALAR uint64_t
187#define CCX_MAX_TIMEOUT UINT64_MAX
189typedef volatile uint32_t CCX_TIME_t;
190#define CCX_TIME_BASE_SCALAR uint32_t
191#define CCX_MAX_TIMEOUT UINT32_MAX
194#ifndef CCX_DISABLE_HIGH_RES_TIMEBASE
196#if defined(CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_UINT8)
198 "CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_UINT8 is not supported because uint8_t has too small a range for this library. Use exactly one of CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_UINT16/32/64."
199 typedef volatile uint16_t CCX_HR_TIME_t;
200#define CCX_HR_TIME_BASE_SCALAR uint16_t
201#define CCX_HR_MAX_TIMEOUT UINT16_MAX
202#elif defined(CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_UINT16)
203 typedef volatile uint16_t CCX_HR_TIME_t;
204#define CCX_HR_TIME_BASE_SCALAR uint16_t
205#define CCX_HR_MAX_TIMEOUT UINT16_MAX
206#elif defined(CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_UINT32)
207 typedef volatile uint32_t CCX_HR_TIME_t;
208#define CCX_HR_TIME_BASE_SCALAR uint32_t
209#define CCX_HR_MAX_TIMEOUT UINT32_MAX
210#elif defined(CCX_HR_TIME_BASE_TYPE_CUSTOM_IS_UINT64)
211 typedef volatile uint64_t CCX_HR_TIME_t;
212#define CCX_HR_TIME_BASE_SCALAR uint64_t
213#define CCX_HR_MAX_TIMEOUT UINT64_MAX
215 typedef volatile uint16_t CCX_HR_TIME_t;
216#define CCX_HR_TIME_BASE_SCALAR uint16_t
217#define CCX_HR_MAX_TIMEOUT UINT16_MAX
222typedef CCX_TIME_t CCX_HR_TIME_t;
223#define CCX_HR_TIME_BASE_SCALAR CCX_TIME_BASE_SCALAR
224#define CCX_HR_MAX_TIMEOUT CCX_MAX_TIMEOUT
228#define CCX_INTERNAL_MS_FROM_US_CEIL(us) (((us) == 0U) ? 0U : (((us)-1U) / 1000U) + 1U)
230#ifdef CCX_DISABLE_HIGH_RES_TIMEBASE
231#define CCX_HR_TIME(us) ((CCX_HR_TIME_t)CCX_INTERNAL_MS_FROM_US_CEIL(us))
233#define CCX_HR_TIME(us) ((CCX_HR_TIME_t)(us))
315 } CCX_MsgRegStatus_t;
344 uint8_t IDE_flag : 1;
346 uint8_t FrameFormat : 2;
394 uint8_t IDE_flag : 1;
395 uint8_t FrameFormat : 2;
398 uint8_t IDE_flag : 1;
403 void (*TimeoutCallback)(
CCX_instance_t *Instance, uint16_t Slot,
void *UserData);
449 uint8_t IDE_flag : 1;
451 uint8_t FrameFormat : 2;
455 void (*Parser)(
const CCX_instance_t *Instance, uint8_t *DataToSend, uint16_t Slot,
void *UserData);
467 volatile uint16_t RxTail, RxHead, TxTail, TxHead;
472 uint16_t RxTableSize, TxTableSize;
482#if defined(CCX_RX_SEARCH_HASH)
499 uint16_t RxTableSize, uint16_t TxTableSize,
504#if CCX_TICK_FROM_FUNC
513 void CCX_tick_function_register(CCX_TIME_BASE_SCALAR (*Function)(
void));
526#ifndef CCX_DISABLE_HIGH_RES_TIMEBASE
527#if CCX_HR_TICK_FROM_FUNC
528 void CCX_high_res_tick_function_register(CCX_HR_TIME_BASE_SCALAR (*Function)(
void));
530 void CCX_high_res_tick_variable_register(CCX_HR_TIME_t *Variable);
534 uint8_t CCX_IsPrimaryTickRegistered(
void);
535 uint8_t CCX_IsHighResTickRegistered(
void);
537#if CCX_TICK_FROM_FUNC
538 extern CCX_TIME_BASE_SCALAR (*CCX_get_tick)(void);
539#define CCX_GetPrimaryTick() ((CCX_get_tick != NULL) ? (CCX_TIME_t)CCX_get_tick() : ((CCX_TIME_t)0))
541extern CCX_TIME_t *CCX_tick;
542#define CCX_GetPrimaryTick() ((CCX_tick != NULL) ? (*CCX_tick) : ((CCX_TIME_t)0))
545#ifdef CCX_DISABLE_HIGH_RES_TIMEBASE
546#define CCX_GetHighResTick() ((CCX_HR_TIME_t)CCX_GetPrimaryTick())
548#if CCX_HR_TICK_FROM_FUNC
549extern CCX_HR_TIME_BASE_SCALAR (*CCX_get_high_res_tick)(void);
550#define CCX_GetHighResTick() \
551 ((CCX_get_high_res_tick != NULL) ? (CCX_HR_TIME_t)CCX_get_high_res_tick() : ((CCX_HR_TIME_t)0))
553extern CCX_HR_TIME_t *CCX_high_res_tick;
554#define CCX_GetHighResTick() ((CCX_high_res_tick != NULL) ? (*CCX_high_res_tick) : ((CCX_HR_TIME_t)0))
683 static inline uint8_t CCX_MsgPayloadLen(
const CCX_message_t *msg)
Bus monitoring public API.
CCX_BusIsFree_t
Enumeration indicating the status of the CAN bus.
Definition can_corex.h:247
void CCX_ResetGlobalStats(CCX_instance_t *Instance)
Reset global statistics.
void CCX_RX_RebuildHash(CCX_instance_t *Instance)
Rebuild hash table for RX message lookup.
void CCX_tick_variable_register(CCX_TIME_t *Variable)
Registers the system tick source variable.
const CCX_GlobalStats_t * CCX_GetGlobalStats(const CCX_instance_t *Instance)
Get global statistics.
#define CCX_TX_BUFFER_SIZE
Size of the CAN transmit buffer.
Definition can_corex.h:76
CCX_FD_DLC_t
Named CAN FD DLC values.
Definition can_corex.h:642
uint8_t CCX_FD_LenToDLC(uint8_t len)
Convert byte length to the smallest valid CAN FD DLC.
#define CCX_RX_HASH_SIZE
Size of the hash table for RX message lookup (used when CCX_RX_SEARCH_HASH is defined).
Definition can_corex.h:124
CCX_frame_format_t
CAN frame format selection.
Definition can_corex.h:276
#define CCX_RX_BUFFER_SIZE
Size of the CAN receive buffer.
Definition can_corex.h:66
void CCX_OnMessageTransmitted(CCX_instance_t *Instance, const CCX_message_t *msg)
Notify library that a message was successfully transmitted.
const uint8_t CCX_FD_DLC_TO_LEN[16]
DLC-to-payload-length lookup table: index 0-15, values {0,1,2,3,4,5,6,7,8,12,16,20,...
CCX_ide_t
CAN identifier type (standard 11-bit or extended 29-bit).
Definition can_corex.h:256
@ CCX_FRAME_FORMAT_CLASSIC
Classic CAN 2.0, max 8-byte payload.
Definition can_corex.h:277
@ CCX_FRAME_FORMAT_FD
CAN FD without bit-rate switch (BRS=0).
Definition can_corex.h:278
@ CCX_FRAME_FORMAT_FD_BRS
CAN FD with bit-rate switch (BRS=1).
Definition can_corex.h:279
@ CCX_ID_EXTENDED
Extended 29-bit identifier.
Definition can_corex.h:258
@ CCX_ID_STANDARD
Standard 11-bit identifier.
Definition can_corex.h:257
Bus monitor configuration and state.
Definition can_corex_bus.h:150
Global statistics for CAN instance.
Definition can_corex.h:299
uint32_t parser_calls_count
Total number of parser function invocations.
Definition can_corex.h:305
uint32_t tx_buffer_overflows
Number of times TX buffer was full.
Definition can_corex.h:304
uint32_t timeout_calls_count
Total number of timeout callback invocations.
Definition can_corex.h:306
uint16_t peak_tx_depth
Highest TX buffer depth observed since stats reset.
Definition can_corex.h:308
uint32_t total_rx_messages
Total messages received and pushed to RX buffer.
Definition can_corex.h:300
uint32_t rx_buffer_overflows
Number of times RX buffer was full.
Definition can_corex.h:303
uint32_t total_tx_messages
Total messages successfully transmitted (call CCX_OnMessageTransmitted from ISR).
Definition can_corex.h:302
uint16_t peak_rx_depth
Highest RX buffer depth observed since stats reset.
Definition can_corex.h:307
CAN RX table entry structure.
Definition can_corex.h:390
CAN TX table entry structure.
Definition can_corex.h:445
Definition can_corex.h:460
void(* OnMessageTransmitted)(CCX_instance_t *Instance, const CCX_message_t *msg)
Callback for TX complete (optional, for user notification).
Definition can_corex.h:478
CCX_BusMonitor_t * BusMonitor
Bus monitoring (NULL = disabled).
Definition can_corex.h:477
CCX_GlobalStats_t GlobalStats
Global statistics (always enabled).
Definition can_corex.h:476
Structure representing a CAN message.
Definition can_corex.h:336