sys_io: Add memory bit manipulation functions
This will be helpful also in drivers mostly, where non-atomic bit setting could be unnecessary. Change-Id: I10c069387d1045f14337b3ac8acfc7b6c1f106c3 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com> Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
c6d0bea109
commit
507decb731
2 changed files with 124 additions and 6 deletions
|
@ -274,7 +274,7 @@ static inline __attribute__((always_inline))
|
|||
}
|
||||
|
||||
|
||||
static inline inline __attribute__((always_inline))
|
||||
static inline __attribute__((always_inline))
|
||||
uint16_t sys_in16(io_port_t port)
|
||||
{
|
||||
uint16_t ret;
|
||||
|
@ -291,7 +291,7 @@ static inline __attribute__((always_inline))
|
|||
}
|
||||
|
||||
|
||||
static inline inline __attribute__((always_inline))
|
||||
static inline __attribute__((always_inline))
|
||||
uint32_t sys_in32(io_port_t port)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
@ -300,7 +300,7 @@ static inline inline __attribute__((always_inline))
|
|||
return ret;
|
||||
}
|
||||
|
||||
static inline inline __attribute__((always_inline))
|
||||
static inline __attribute__((always_inline))
|
||||
void sys_write8(uint8_t data, mm_reg_t addr)
|
||||
{
|
||||
__asm__ volatile("movb %0, %1;\n\t"
|
||||
|
@ -309,7 +309,7 @@ static inline inline __attribute__((always_inline))
|
|||
: "memory");
|
||||
}
|
||||
|
||||
static inline inline __attribute__((always_inline))
|
||||
static inline __attribute__((always_inline))
|
||||
uint8_t sys_read8(mm_reg_t addr)
|
||||
{
|
||||
uint8_t ret;
|
||||
|
@ -331,7 +331,7 @@ static inline __attribute__((always_inline))
|
|||
: "memory");
|
||||
}
|
||||
|
||||
static inline inline __attribute__((always_inline))
|
||||
static inline __attribute__((always_inline))
|
||||
uint16_t sys_read16(mm_reg_t addr)
|
||||
{
|
||||
uint16_t ret;
|
||||
|
@ -344,7 +344,7 @@ static inline inline __attribute__((always_inline))
|
|||
return ret;
|
||||
}
|
||||
|
||||
static inline inline __attribute__((always_inline))
|
||||
static inline __attribute__((always_inline))
|
||||
void sys_write32(uint32_t data, mm_reg_t addr)
|
||||
{
|
||||
__asm__ volatile("movl %0, %1;\n\t"
|
||||
|
@ -367,5 +367,61 @@ static inline __attribute__((always_inline))
|
|||
}
|
||||
|
||||
|
||||
static inline __attribute__((always_inline))
|
||||
void sys_set_bit(mem_addr_t addr, int bit)
|
||||
{
|
||||
__asm__ volatile("btsl %1, %0;\n\t"
|
||||
: "+m" (*(volatile uint32_t *) (addr))
|
||||
: "Ir" (bit)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline __attribute__((always_inline))
|
||||
void sys_clear_bit(mem_addr_t addr, int bit)
|
||||
{
|
||||
__asm__ volatile("btrl %1, %0;\n\t"
|
||||
: "+m" (*(volatile uint32_t *) (addr))
|
||||
: "Ir" (bit));
|
||||
}
|
||||
|
||||
static inline __attribute__((always_inline))
|
||||
int sys_test_bit(mem_addr_t addr, int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
__asm__ volatile("btl %2, %1;\n\t"
|
||||
"sbb %0, %0\n\t"
|
||||
: "=r" (ret), "+m" (*(volatile uint32_t *) (addr))
|
||||
: "Ir" (bit));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline __attribute__((always_inline))
|
||||
int sys_test_and_set_bit(mem_addr_t addr, int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
__asm__ volatile("btsl %2, %1;\n\t"
|
||||
"sbb %0, %0\n\t"
|
||||
: "=r" (ret), "+m" (*(volatile uint32_t *) (addr))
|
||||
: "Ir" (bit));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline __attribute__((always_inline))
|
||||
int sys_test_and_clear_bit(mem_addr_t addr, int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
__asm__ volatile("btrl %2, %1;\n\t"
|
||||
"sbb %0, %0\n\t"
|
||||
: "=r" (ret), "+m" (*(volatile uint32_t *) (addr))
|
||||
: "Ir" (bit));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* _ASMLANGUAGE */
|
||||
#endif /* _ASM_INLINE_GCC_PUBLIC_GCC_H */
|
||||
|
|
|
@ -42,6 +42,7 @@ extern "C" {
|
|||
|
||||
typedef uint32_t io_port_t;
|
||||
typedef uint32_t mm_reg_t;
|
||||
typedef uint32_t mem_addr_t;
|
||||
|
||||
/* Port I/O functions */
|
||||
|
||||
|
@ -176,6 +177,67 @@ typedef uint32_t mm_reg_t;
|
|||
* @return the 32 bits read
|
||||
*/
|
||||
|
||||
/* Memory bits manipulation functions */
|
||||
|
||||
/**
|
||||
* @fn static inline void sys_set_bit(mem_addr_t addr, int bit)
|
||||
* @brief Set the designated bit from addr to 1
|
||||
*
|
||||
* This functions takes the designated bit starting from addr and sets it to 1.
|
||||
*
|
||||
* @param addr the memory address from where to look for the bit
|
||||
* @param bit the designated bit to set (from 0 to n)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fn static inline void sys_clear_bit(mem_addr_t addr, int bit)
|
||||
* @brief Clear the designated bit from addr to 0
|
||||
*
|
||||
* This functions takes the designated bit starting from addr and sets it to 0.
|
||||
*
|
||||
* @param addr the memory address from where to look for the bit
|
||||
* @param bit the designated bit to clear (from 0 to n)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fn static inline int sys_test_bit(mem_addr_t addr, int bit)
|
||||
* @brief Test the bit if it is set or not
|
||||
*
|
||||
* This functions takes the designated bit starting from addr and tests its
|
||||
* current setting. If it return the current setting.
|
||||
*
|
||||
* @param addr the memory address from where to look for the bit
|
||||
* @param bit the designated bit to test (from 0 to n)
|
||||
*
|
||||
* @return 1 if it is set, 0 otherwise
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fn static inline int sys_test_and_set_bit(mem_addr_t addr, int bit)
|
||||
* @brief Test the bit and set it
|
||||
*
|
||||
* This functions takes the designated bit starting from addr, tests its
|
||||
* current setting and sets it. It will return the previous setting.
|
||||
*
|
||||
* @param addr the memory address from where to look for the bit
|
||||
* @param bit the designated bit to test and set (from 0 to n)
|
||||
*
|
||||
* @return 1 if it was set, 0 otherwise
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fn static inline int sys_test_and_clear_bit(mem_addr_t addr, int bit)
|
||||
* @brief Test the bit and clear it
|
||||
*
|
||||
* This functions takes the designated bit starting from addr, test its
|
||||
* current setting and clears it. It will return the previous setting.
|
||||
*
|
||||
* @param addr the memory address from where to look for the bit
|
||||
* @param bit the designated bit to test (from 0 to n)
|
||||
*
|
||||
* @return 0 if it was clear, 1 otherwise
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue