tools: Added *REG_BIT_MSK_AND_SET macros

Added CLR_REG_BIT_MSK_AND_SET and TOG_SET_REG_BIT_MSK_AND_SET because we
need version of CLR_REG_BIT_MSK and TOG_SET_REG_BIT_MSK that allow us to
OR in bits before the register is written.

Signed-off-by: George McCollister <george.mccollister@gmail.com>
This commit is contained in:
George McCollister 2014-05-29 14:02:03 -05:00 committed by Karl Palsson
parent 40d9ffcb6b
commit 9eb551c127

View File

@ -34,8 +34,11 @@
#define CLR_REG_BIT(REG, BIT) SET_REG(REG, (~BIT))
/* Clear register bit masking out some bits that must not be touched. */
#define CLR_REG_BIT_MSK_AND_SET(REG, MSK, BIT, EXTRA_BITS) \
SET_REG(REG, (GET_REG(REG) & MSK & (~BIT)) | (EXTRA_BITS))
#define CLR_REG_BIT_MSK(REG, MSK, BIT) \
SET_REG(REG, (GET_REG(REG) & MSK & (~BIT)))
CLR_REG_BIT_MSK_AND_SET(REG, MSK, BIT, 0)
/* Get masked out bit value. */
#define GET_REG_BIT(REG, BIT) (GET_REG(REG) & BIT)
@ -50,7 +53,7 @@
*
* TODO: We may need a faster implementation of that one?
*/
#define TOG_SET_REG_BIT_MSK(REG, MSK, BIT) \
#define TOG_SET_REG_BIT_MSK_AND_SET(REG, MSK, BIT, EXTRA_BITS) \
do { \
register uint16_t toggle_mask = GET_REG(REG) & (MSK); \
register uint16_t bit_selector; \
@ -59,7 +62,10 @@ do { \
toggle_mask ^= bit_selector; \
} \
} \
SET_REG(REG, toggle_mask); \
SET_REG(REG, toggle_mask | (EXTRA_BITS)); \
} while (0)
#define TOG_SET_REG_BIT_MSK(REG, MSK, BIT) \
TOG_SET_REG_BIT_MSK_AND_SET(REG, MSK, BIT, 0)
#endif