43#ifndef _DEV_CAN_CAN_HELPERS_H
44#define _DEV_CAN_CAN_HELPERS_H
53#define RTEMS_CAN_USER_MAGIC 0x05402033
56#define BIT( nr ) ( 1UL << ( nr ) )
59#define GENMASK( h, l ) \
60 ( ( ( ~0UL ) << ( l ) ) & ( ~0UL >> ( sizeof( long ) * 8 - 1 - ( h ) ) ) )
63#define __bf_shf( x ) ( __builtin_ffsll( x ) - 1 )
67#define FIELD_PREP( _mask, _val ) \
68 ( { ( (typeof( _mask )) ( _val ) << __bf_shf( _mask ) ) & ( _mask ); } )
72#define FIELD_GET( _mask, _reg ) \
73 ( { (typeof( _mask )) ( ( ( _reg ) & ( _mask ) ) >> __bf_shf( _mask ) ); } )
77static const uint8_t rtems_can_len2dlc[] = {
78 0, 1, 2, 3, 4, 5, 6, 7, 8,
83 13, 13, 13, 13, 13, 13, 13, 13,
84 14, 14, 14, 14, 14, 14, 14, 14,
85 14, 14, 14, 14, 14, 14, 14, 14,
86 15, 15, 15, 15, 15, 15, 15, 15,
87 15, 15, 15, 15, 15, 15, 15, 15
98static inline uint8_t rtems_canfd_len2dlc( uint8_t len )
104 return rtems_can_len2dlc[ len ];
117static inline void rtems_can_set_bit(
int nr, atomic_uint *addr )
119 atomic_fetch_or( addr, 1 << nr );
132static inline void rtems_can_clear_bit(
int nr, atomic_uint *addr )
134 atomic_fetch_and( addr, ~( 1 << nr ) );
148static inline int rtems_can_test_bit(
int nr, atomic_uint *addr )
150 return ( atomic_load( addr ) ) & ( 1 << nr ) ? 1 : 0;
163static inline int rtems_can_test_and_set_bit(
int nr, atomic_uint *addr )
165 return ( atomic_fetch_or( addr, 1 << nr ) & ( 1 << nr ) ) ? 1 : 0;