drivers: can: add accessor for the CAN bit error counter

Add accessor function for the CAN bit error counter.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2023-10-27 13:11:09 +02:00 committed by Carles Cufí
parent 0891448ac9
commit 043e6ecbf6
4 changed files with 37 additions and 2 deletions

View file

@ -246,6 +246,14 @@ static inline int z_vrfy_can_recover(const struct device *dev, k_timeout_t timeo
#ifdef CONFIG_CAN_STATS
static inline uint32_t z_vrfy_can_stats_get_bit_errors(const struct device *dev)
{
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
return z_impl_can_stats_get_bit_errors(dev);
}
#include <syscalls/can_stats_get_bit_errors_mrsh.c>
static inline uint32_t z_vrfy_can_stats_get_bit0_errors(const struct device *dev)
{
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));

View file

@ -364,8 +364,9 @@ static int cmd_can_show(const struct shell *sh, size_t argc, char **argv)
#ifdef CONFIG_CAN_STATS
shell_print(sh, "statistics:");
shell_print(sh, " bit0 errors: %u", can_stats_get_bit0_errors(dev));
shell_print(sh, " bit1 errors: %u", can_stats_get_bit1_errors(dev));
shell_print(sh, " bit errors: %u", can_stats_get_bit_errors(dev));
shell_print(sh, " bit0 errors: %u", can_stats_get_bit0_errors(dev));
shell_print(sh, " bit1 errors: %u", can_stats_get_bit1_errors(dev));
shell_print(sh, " stuff errors: %u", can_stats_get_stuff_errors(dev));
shell_print(sh, " crc errors: %u", can_stats_get_crc_errors(dev));
shell_print(sh, " form errors: %u", can_stats_get_form_errors(dev));

View file

@ -1384,6 +1384,27 @@ static inline void can_set_state_change_callback(const struct device *dev,
* @{
*/
/**
* @brief Get the bit error counter for a CAN device
*
* The bit error counter is incremented when the CAN controller is unable to
* transmit either a dominant or a recessive bit.
*
* @note @kconfig{CONFIG_CAN_STATS} must be selected for this function to be
* available.
*
* @param dev Pointer to the device structure for the driver instance.
* @return bit error counter
*/
__syscall uint32_t can_stats_get_bit_errors(const struct device *dev);
#ifdef CONFIG_CAN_STATS
static inline uint32_t z_impl_can_stats_get_bit_errors(const struct device *dev)
{
return Z_CAN_GET_STATS(dev).bit_error;
}
#endif /* CONFIG_CAN_STATS */
/**
* @brief Get the bit0 error counter for a CAN device
*
@ -1393,6 +1414,8 @@ static inline void can_set_state_change_callback(const struct device *dev,
* @note @kconfig{CONFIG_CAN_STATS} must be selected for this function to be
* available.
*
* @see can_stats_get_bit_errors()
*
* @param dev Pointer to the device structure for the driver instance.
* @return bit0 error counter
*/
@ -1414,6 +1437,8 @@ static inline uint32_t z_impl_can_stats_get_bit0_errors(const struct device *dev
* @note @kconfig{CONFIG_CAN_STATS} must be selected for this function to be
* available.
*
* @see can_stats_get_bit_errors()
*
* @param dev Pointer to the device structure for the driver instance.
* @return bit1 error counter
*/

View file

@ -23,6 +23,7 @@ ZTEST_USER(can_stats, test_can_stats_accessors)
{
uint32_t val;
val = can_stats_get_bit_errors(can_dev);
val = can_stats_get_bit0_errors(can_dev);
val = can_stats_get_bit1_errors(can_dev);
val = can_stats_get_stuff_errors(can_dev);