dccloader/dcc/bitutils.c
wrapper 95c7bdd0e7
All checks were successful
ci/woodpecker/push/msm5500_kbb05 Pipeline was successful
ci/woodpecker/push/msm6050 Pipeline was successful
simplify bit related routines
2026-08-07 17:08:01 +07:00

53 lines
No EOL
1.3 KiB
C

#include "plat.h"
#include "bitutils.h"
/*
* Bit Helpers
*/
/* Bit operations routines */
#define GET_BIT_ROUTINE(bit) \
static inline uint## bit ##_t _get_bit## bit(uint32_t offset, uint32_t bit_position, uint32_t bit_mask) \
{ \
return (READ_U## bit(offset) >> bit_position) & bit_mask; \
}
#define SET_BIT_ROUTINE(bit) \
static inline void _set_bit## bit(uint32_t offset, uint32_t bit_position, uint32_t bit_mask, uint## bit ##_t value) \
{ \
WRITE_U## bit(offset, (READ_U## bit(offset) & ~(bit_mask << bit_position)) | ((value & bit_mask) << bit_position)); \
}
/* Bit operations functions */
#define GET_BIT_FUNC(bit) \
uint## bit ##_t GET_BIT## bit(uint32_t offset, const bitmask bitmask) \
{ \
return _get_bit## bit(offset, bitmask.bit_pos, bitmask.bit_mask); \
}
#define SET_BIT_FUNC(bit) \
void SET_BIT## bit(uint32_t offset, const bitmask bitmask, uint## bit ##_t value) \
{ \
_set_bit## bit(offset, bitmask.bit_pos, bitmask.bit_mask, value); \
}
/* 32 */
GET_BIT_ROUTINE(32)
SET_BIT_ROUTINE(32)
GET_BIT_FUNC(32)
SET_BIT_FUNC(32)
/* 16 */
GET_BIT_ROUTINE(16)
SET_BIT_ROUTINE(16)
GET_BIT_FUNC(16)
SET_BIT_FUNC(16)
/* 8 */
GET_BIT_ROUTINE(8)
SET_BIT_ROUTINE(8)
GET_BIT_FUNC(8)
SET_BIT_FUNC(8)