Skip to content

Commit ec576a5

Browse files
martinjaegercfriedt
authored andcommitted
canbus: canopen: Use new API to check number of filters
The previous CONFIG_CAN_MAX_FILTER is specific to certain drivers. Using the new API makes the CAN open driver independent of the used CAN hardware / driver. Signed-off-by: Martin Jäger <[email protected]>
1 parent 5511cba commit ec576a5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

modules/canopennode/CO_driver.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t *CANmodule,
170170
struct canopen_context *ctx = (struct canopen_context *)CANdriverState;
171171
uint16_t i;
172172
int err;
173+
int max_filters;
173174

174175
LOG_DBG("rxSize = %d, txSize = %d", rxSize, txSize);
175176

@@ -178,15 +179,19 @@ CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t *CANmodule,
178179
return CO_ERROR_ILLEGAL_ARGUMENT;
179180
}
180181

181-
if (rxSize > CONFIG_CAN_MAX_FILTER) {
182+
max_filters = can_get_max_filters(ctx->dev, CAN_STANDARD_IDENTIFIER);
183+
if (max_filters < 0) {
184+
LOG_ERR("unable to determine number of CAN RX filters");
185+
return CO_ERROR_SYSCALL;
186+
}
187+
188+
if (rxSize > max_filters) {
182189
LOG_ERR("insufficient number of concurrent CAN RX filters"
183-
" (needs %d, %d available)", rxSize,
184-
CONFIG_CAN_MAX_FILTER);
190+
" (needs %d, %d available)", rxSize, max_filters);
185191
return CO_ERROR_OUT_OF_MEMORY;
186-
} else if (rxSize < CONFIG_CAN_MAX_FILTER) {
192+
} else if (rxSize < max_filters) {
187193
LOG_DBG("excessive number of concurrent CAN RX filters enabled"
188-
" (needs %d, %d available)", rxSize,
189-
CONFIG_CAN_MAX_FILTER);
194+
" (needs %d, %d available)", rxSize, max_filters);
190195
}
191196

192197
canopen_detach_all_rx_filters(CANmodule);

0 commit comments

Comments
 (0)