include: common: Add sys_set_bits and set_clear_bits inline functions

Add new common inline functions sys_set_bits and set_clear_bits to set
and clear multiple bits via bit mask in single function call.

Signed-off-by: Siew Chin Lim <elly.siew.chin.lim@intel.com>
This commit is contained in:
Siew Chin Lim 2021-04-21 17:44:45 +08:00 committed by Anas Nashif
commit 5b6c59397e
2 changed files with 34 additions and 0 deletions

View file

@ -42,6 +42,20 @@ static ALWAYS_INLINE int sys_test_bit(mem_addr_t addr, unsigned int bit)
return temp & (1 << bit);
}
static ALWAYS_INLINE void sys_set_bits(mem_addr_t addr, unsigned int mask)
{
uint32_t temp = *(volatile uint32_t *)addr;
*(volatile uint32_t *)addr = temp | mask;
}
static ALWAYS_INLINE void sys_clear_bits(mem_addr_t addr, unsigned int mask)
{
uint32_t temp = *(volatile uint32_t *)addr;
*(volatile uint32_t *)addr = temp & ~mask;
}
static ALWAYS_INLINE
void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit)
{

View file

@ -245,6 +245,26 @@ typedef uintptr_t mem_addr_t;
* @param bit the designated bit to set (from 0 to 31)
*/
/**
* @fn static inline void sys_set_bits(mem_addr_t addr, unsigned int mask)
* @brief Masking the designated bits from addr to 1
*
* This functions masking designated bits from addr to 1.
*
* @param addr the memory address from where to look for the bits
* @param mask the bit mask of a 32 bits data to set
*/
/**
* @fn static inline void sys_clear_bits(mem_addr_t addr, unsigned int mask)
* @brief Masking the designated bits from addr to 0
*
* This functions masking designated bits from addr to 0.
*
* @param addr the memory address from where to look for the bits
* @param mask the bit mask of a 32 bits data to set
*/
/**
* @fn static inline void sys_clear_bit(mem_addr_t addr, unsigned int bit)
* @brief Clear the designated bit from addr to 0