Skip to content

Commit 3c89bbf

Browse files
henrikbrixandersencarlescufi
authored andcommitted
drivers: can: reset statistics when starting the CAN controller
Reset CAN controller statistics when starting the CAN controller. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent b079316 commit 3c89bbf

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

drivers/can/can_mcux_flexcan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ static int mcux_flexcan_start(const struct device *dev)
204204
}
205205
}
206206

207-
/* Clear error counters */
207+
/* Reset statistics and clear error counters */
208+
CAN_STATS_RESET(dev);
208209
config->base->ECR &= ~(CAN_ECR_TXERRCNT_MASK | CAN_ECR_RXERRCNT_MASK);
209210

210211
/* Delay this until start since setting the timing automatically exits freeze mode */

drivers/can/can_rcar.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ static int can_rcar_start(const struct device *dev)
592592

593593
k_mutex_lock(&data->inst_mutex, K_FOREVER);
594594

595+
CAN_STATS_RESET(dev);
596+
595597
ret = can_rcar_enter_operation_mode(config);
596598
if (ret != 0) {
597599
LOG_ERR("failed to enter operation mode (err %d)", ret);

drivers/can/can_stm32.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ static int can_stm32_start(const struct device *dev)
383383
}
384384
}
385385

386+
CAN_STATS_RESET(dev);
387+
386388
ret = can_stm32_leave_init_mode(can);
387389
if (ret < 0) {
388390
LOG_ERR("Failed to leave init mode");

include/zephyr/drivers/can.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,17 @@ struct can_device_state {
579579
#define CAN_STATS_RX_OVERRUN_INC(dev_) \
580580
STATS_INC(Z_CAN_GET_STATS(dev_), rx_overrun)
581581

582+
/**
583+
* @brief Zero all statistics for a CAN device
584+
*
585+
* The driver is reponsible for resetting the statistics before starting the CAN
586+
* controller.
587+
*
588+
* @param dev_ Pointer to the device structure for the driver instance.
589+
*/
590+
#define CAN_STATS_RESET(dev_) \
591+
stats_reset(&(Z_CAN_GET_STATS(dev_).s_hdr))
592+
582593
/** @cond INTERNAL_HIDDEN */
583594

584595
/**
@@ -647,6 +658,7 @@ struct can_device_state {
647658
#define CAN_STATS_FORM_ERROR_INC(dev_)
648659
#define CAN_STATS_ACK_ERROR_INC(dev_)
649660
#define CAN_STATS_RX_OVERRUN_INC(dev_)
661+
#define CAN_STATS_RESET(dev_)
650662

651663
#define CAN_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, \
652664
prio, api, ...) \

0 commit comments

Comments
 (0)