42#ifndef _DEV_CAN_CAN_HELPERS_H
43#define _DEV_CAN_CAN_HELPERS_H
48#define CAN_DEFAULT_FIFO_SIZE 64
54#define RTEMS_CAN_USER_MAGIC 0x05402033
57#define BIT(nr) (1UL << (nr))
60#define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (sizeof(long) * 8 - 1 - (h))))
63#define __bf_shf(x) (__builtin_ffsll(x) - 1)
67#define FIELD_PREP(_mask, _val) \
69 ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \
74#define FIELD_GET(_mask, _reg) \
76 (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \
81 CAN_STATE_ERROR_ACTIVE = 0,
82 CAN_STATE_ERROR_WARNING,
83 CAN_STATE_ERROR_PASSIVE,
90static const uint8_t rtems_len2dlc[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8,
95 13, 13, 13, 13, 13, 13, 13, 13,
96 14, 14, 14, 14, 14, 14, 14, 14,
97 14, 14, 14, 14, 14, 14, 14, 14,
98 15, 15, 15, 15, 15, 15, 15, 15,
99 15, 15, 15, 15, 15, 15, 15, 15
109static inline uint8_t rtems_canfd_len2dlc( uint8_t len )
115 return rtems_len2dlc[len];
128static inline void can_set_bit(
int nr, atomic_uint *addr )
130 atomic_fetch_or( addr, 1 << nr );
143static inline void can_clear_bit(
int nr, atomic_uint *addr )
145 atomic_fetch_and( addr, ~( 1 << nr ) );
158static inline int can_test_bit(
int nr, atomic_uint *addr )
160 return ( atomic_load( addr ) ) & ( 1 << nr ) ? 1 : 0;
173static inline int can_test_and_set_bit(
int nr, atomic_uint *addr )
175 return ( atomic_fetch_or( addr, 1 << nr ) & ( 1 << nr ) ) ? 1 : 0;