@@ -80,6 +80,16 @@ extern "C"
8080#define CANARD_MTU_CAN_CLASSIC 8U
8181#define CANARD_MTU_CAN_FD 64U
8282
83+ /// If CAN acceptance filter configuration is enabled, the library will be able to configure at most this many filters.
84+ /// The application can configure a smaller limit at runtime if necessary; this value only affects a stack array size.
85+ /// The default value is large enough to utilize all available filters in most CAN controllers out there,
86+ /// considering that we use filters in the extended ID&mask mode which tends to consume more hardware resources.
87+ /// This value can be reduced to reduce the stack pressure on the filter configuration update path,
88+ /// or increased if more filters are available (e.g., Bosch M_CAN or ST FDCAN support up to 64, SocketCAN up to 512).
89+ #ifndef CANARD_FILTERS_MAX
90+ #define CANARD_FILTERS_MAX 32U
91+ #endif
92+
8393/// All valid transfer kind and version combinations.
8494typedef enum canard_kind_t
8595{
@@ -293,7 +303,8 @@ typedef struct canard_vtable_t
293303
294304 /// Reconfigure the acceptance filters of the CAN controller hardware.
295305 /// The prior configuration, if any, is replaced entirely.
296- /// filter_count is guaranteed to not exceed the value given at initialization.
306+ /// filter_count is guaranteed to not exceed the value given at initialization and CANARD_FILTERS_MAX,
307+ /// whichever is smaller.
297308 /// This function may be NULL if the CAN controller/driver does not support filtering or it is not desired.
298309 /// The implementation is assumed to be infallible; if error handling is necessary, it must be implemented
299310 /// on the application side, perhaps with retries.
@@ -345,9 +356,7 @@ struct canard_t
345356 {
346357 canard_tree_t * subscriptions [CANARD_KIND_COUNT ];
347358 canard_list_t list_session_by_animation ; ///< Oldest at the head.
348-
349- size_t filter_count ;
350- canard_filter_t * filters ; ///< Storage provided by the user.
359+ size_t filter_count ; ///< At most CANARD_FILTERS_MAX.
351360 } rx ;
352361
353362 /// Error counters incremented automatically when the corresponding error condition occurs.
@@ -388,9 +397,9 @@ struct canard_t
388397/// and collisions, and will automatically migrate to a free node-ID shall a collision be detected.
389398/// If manual allocation is desired, use the corresponding function to set the node-ID after initialization.
390399///
391- /// The filter storage is an array of filters that is used by the library to automatically set up the acceptance
392- /// filters when the RX pipeline is reconfigured . The filter count equals the storage size. The storage must
393- /// outlive the library instance. It is possible to pass zero filters & NULL if filtering is unneeded/unsupported.
400+ /// The filter count is the number of CAN acceptance filters that the library can utilize. If there are fewer filters
401+ /// than subscriptions, similar filters will be coalesced . The value will be clamped to CANARD_FILTERS_MAX.
402+ /// It is possible to pass zero filters if filtering is unneeded/unsupported.
394403///
395404/// CAN FD mode is selected by default for outgoing frames; override the fd flag to change the mode if needed.
396405///
@@ -400,8 +409,7 @@ bool canard_new(canard_t* const self,
400409 const canard_mem_set_t memory ,
401410 const size_t tx_queue_capacity ,
402411 const uint64_t prng_seed ,
403- const size_t filter_count ,
404- canard_filter_t * const filter_storage );
412+ const size_t filter_count );
405413
406414/// The application MUST destroy all subscriptions before invoking this (this is asserted).
407415/// The TX queue will be purged automatically if not empty.
0 commit comments