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 <martin@libre.solar>
This commit is contained in:
Martin Jäger 2021-10-12 11:49:08 +02:00 committed by Christopher Friedt
commit ec576a59d3

View file

@ -170,6 +170,7 @@ CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t *CANmodule,
struct canopen_context *ctx = (struct canopen_context *)CANdriverState;
uint16_t i;
int err;
int max_filters;
LOG_DBG("rxSize = %d, txSize = %d", rxSize, txSize);
@ -178,15 +179,19 @@ CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t *CANmodule,
return CO_ERROR_ILLEGAL_ARGUMENT;
}
if (rxSize > CONFIG_CAN_MAX_FILTER) {
max_filters = can_get_max_filters(ctx->dev, CAN_STANDARD_IDENTIFIER);
if (max_filters < 0) {
LOG_ERR("unable to determine number of CAN RX filters");
return CO_ERROR_SYSCALL;
}
if (rxSize > max_filters) {
LOG_ERR("insufficient number of concurrent CAN RX filters"
" (needs %d, %d available)", rxSize,
CONFIG_CAN_MAX_FILTER);
" (needs %d, %d available)", rxSize, max_filters);
return CO_ERROR_OUT_OF_MEMORY;
} else if (rxSize < CONFIG_CAN_MAX_FILTER) {
} else if (rxSize < max_filters) {
LOG_DBG("excessive number of concurrent CAN RX filters enabled"
" (needs %d, %d available)", rxSize,
CONFIG_CAN_MAX_FILTER);
" (needs %d, %d available)", rxSize, max_filters);
}
canopen_detach_all_rx_filters(CANmodule);