Skip to content

Commit 5511cba

Browse files
martinjaegercfriedt
authored andcommitted
drivers: can: Add get_max_filters API
The maximum number of concurrent filters depends on the hardware and the driver implementation. This API allows the application to obtain the maximum number of available filters. Signed-off-by: Martin Jäger <[email protected]>
1 parent 9c5a534 commit 5511cba

File tree

7 files changed

+78
-0
lines changed

7 files changed

+78
-0
lines changed

drivers/can/can_loopback.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ int can_loopback_get_core_clock(const struct device *dev, uint32_t *rate)
236236
return 0;
237237
}
238238

239+
int can_loopback_get_max_filters(const struct device *dev, enum can_ide id_type)
240+
{
241+
ARG_UNUSED(id_type);
242+
243+
return CONFIG_CAN_MAX_FILTER;
244+
}
245+
239246
static const struct can_driver_api can_api_funcs = {
240247
.set_mode = can_loopback_set_mode,
241248
.set_timing = can_loopback_set_timing,
@@ -248,6 +255,7 @@ static const struct can_driver_api can_api_funcs = {
248255
#endif
249256
.register_state_change_isr = can_loopback_register_state_change_isr,
250257
.get_core_clock = can_loopback_get_core_clock,
258+
.get_max_filters = can_loopback_get_max_filters,
251259
.timing_min = {
252260
.sjw = 0x1,
253261
.prop_seg = 0x01,

drivers/can/can_mcp2515.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ static int mcp2515_get_core_clock(const struct device *dev, uint32_t *rate)
314314
return 0;
315315
}
316316

317+
int mcp2515_get_max_filters(const struct device *dev, enum can_ide id_type)
318+
{
319+
ARG_UNUSED(id_type);
320+
321+
return CONFIG_CAN_MAX_FILTER;
322+
}
317323

318324
static int mcp2515_set_timing(const struct device *dev,
319325
const struct can_timing *timing,
@@ -785,6 +791,7 @@ static const struct can_driver_api can_api_funcs = {
785791
#endif
786792
.register_state_change_isr = mcp2515_register_state_change_isr,
787793
.get_core_clock = mcp2515_get_core_clock,
794+
.get_max_filters = mcp2515_get_max_filters,
788795
.timing_min = {
789796
.sjw = 0x1,
790797
.prop_seg = 0x01,

drivers/can/can_mcux_flexcan.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ static int mcux_flexcan_get_core_clock(const struct device *dev, uint32_t *rate)
127127
return clock_control_get_rate(config->clock_dev, config->clock_subsys, rate);
128128
}
129129

130+
int mcux_flexcan_get_max_filters(const struct device *dev, enum can_ide id_type)
131+
{
132+
ARG_UNUSED(id_type);
133+
134+
return CONFIG_CAN_MAX_FILTER;
135+
}
136+
130137
static int mcux_flexcan_set_timing(const struct device *dev,
131138
const struct can_timing *timing,
132139
const struct can_timing *timing_data)
@@ -747,6 +754,7 @@ static const struct can_driver_api mcux_flexcan_driver_api = {
747754
#endif
748755
.register_state_change_isr = mcux_flexcan_register_state_change_isr,
749756
.get_core_clock = mcux_flexcan_get_core_clock,
757+
.get_max_filters = mcux_flexcan_get_max_filters,
750758
/*
751759
* FlexCAN timing limits are specified in the "FLEXCANx_CTRL1 field
752760
* descriptions" table in the SoC reference manual.

drivers/can/can_rcar.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,13 @@ static int can_rcar_get_core_clock(const struct device *dev, uint32_t *rate)
981981
return 0;
982982
}
983983

984+
int can_rcar_get_max_filters(const struct device *dev, enum can_ide id_type)
985+
{
986+
ARG_UNUSED(id_type);
987+
988+
return CONFIG_CAN_RCAR_MAX_FILTER;
989+
}
990+
984991
static const struct can_driver_api can_rcar_driver_api = {
985992
.set_mode = can_rcar_set_mode,
986993
.set_timing = can_rcar_set_timing,
@@ -993,6 +1000,7 @@ static const struct can_driver_api can_rcar_driver_api = {
9931000
#endif
9941001
.register_state_change_isr = can_rcar_register_state_change_isr,
9951002
.get_core_clock = can_rcar_get_core_clock,
1003+
.get_max_filters = can_rcar_get_max_filters,
9961004
.timing_min = {
9971005
.sjw = 0x1,
9981006
.prop_seg = 0x00,

drivers/can/can_stm32.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,13 @@ int can_stm32_get_core_clock(const struct device *dev, uint32_t *rate)
412412
return 0;
413413
}
414414

415+
int can_stm32_get_max_filters(const struct device *dev, enum can_ide id_type)
416+
{
417+
ARG_UNUSED(id_type);
418+
419+
return CONFIG_CAN_MAX_FILTER;
420+
}
421+
415422
static int can_stm32_init(const struct device *dev)
416423
{
417424
const struct can_stm32_config *cfg = DEV_CFG(dev);
@@ -1105,6 +1112,7 @@ static const struct can_driver_api can_api_funcs = {
11051112
#endif
11061113
.register_state_change_isr = can_stm32_register_state_change_isr,
11071114
.get_core_clock = can_stm32_get_core_clock,
1115+
.get_max_filters = can_stm32_get_max_filters,
11081116
.timing_min = {
11091117
.sjw = 0x1,
11101118
.prop_seg = 0x00,

drivers/can/can_stm32fd.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ int can_stm32fd_get_core_clock(const struct device *dev, uint32_t *rate)
3838
return 0;
3939
}
4040

41+
int can_stm32fd_get_max_filters(const struct device *dev, enum can_ide id_type)
42+
{
43+
if (id_type == CAN_STANDARD_IDENTIFIER) {
44+
return NUM_STD_FILTER_DATA;
45+
} else {
46+
return NUM_EXT_FILTER_DATA;
47+
}
48+
}
49+
4150
void can_stm32fd_clock_enable(void)
4251
{
4352
LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1);
@@ -175,6 +184,7 @@ static const struct can_driver_api can_api_funcs = {
175184
.recover = can_mcan_recover,
176185
#endif
177186
.get_core_clock = can_stm32fd_get_core_clock,
187+
.get_max_filters = can_stm32fd_get_max_filters,
178188
.register_state_change_isr = can_stm32fd_register_state_change_isr,
179189
.timing_min = {
180190
.sjw = 0x7f,

include/drivers/can.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ typedef void(*can_register_state_change_isr_t)(const struct device *dev,
370370

371371
typedef int (*can_get_core_clock_t)(const struct device *dev, uint32_t *rate);
372372

373+
typedef int (*can_get_max_filters_t)(const struct device *dev,
374+
enum can_ide id_type);
375+
373376
#ifndef CONFIG_CAN_WORKQ_FRAMES_BUF_CNT
374377
#define CONFIG_CAN_WORKQ_FRAMES_BUF_CNT 4
375378
#endif
@@ -404,6 +407,7 @@ __subsystem struct can_driver_api {
404407
can_get_state_t get_state;
405408
can_register_state_change_isr_t register_state_change_isr;
406409
can_get_core_clock_t get_core_clock;
410+
can_get_max_filters_t get_max_filters;
407411
/* Min values for the timing registers */
408412
struct can_timing timing_min;
409413
/* Max values for the timing registers */
@@ -661,6 +665,31 @@ static inline int z_impl_can_get_core_clock(const struct device *dev,
661665
return api->get_core_clock(dev, rate);
662666
}
663667

668+
/**
669+
* @brief Retrieve maximum number of filters
670+
*
671+
* @param dev Pointer to the device structure for the driver instance.
672+
* @param id_type CAN identifier type (standard or extended)
673+
*
674+
* @retval Number of maximum concurrent filters
675+
* @retval -EIO General input / output error, failed to query device
676+
* @retval -ENOSYS If this function is not implemented by the driver
677+
*/
678+
__syscall int can_get_max_filters(const struct device *dev, enum can_ide id_type);
679+
680+
static inline int z_impl_can_get_max_filters(const struct device *dev,
681+
enum can_ide id_type)
682+
{
683+
const struct can_driver_api *api =
684+
(const struct can_driver_api *)dev->api;
685+
686+
if (api->get_max_filters == NULL) {
687+
return -ENOSYS;
688+
}
689+
690+
return api->get_max_filters(dev, id_type);
691+
}
692+
664693
/**
665694
* @brief Calculate timing parameters from bitrate and sample point
666695
*

0 commit comments

Comments
 (0)