From 9eb551c127481dfd64254a6d2d3f9510e4ea7043 Mon Sep 17 00:00:00 2001 From: George McCollister Date: Thu, 29 May 2014 14:02:03 -0500 Subject: [PATCH] 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 --- include/libopencm3/stm32/tools.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/libopencm3/stm32/tools.h b/include/libopencm3/stm32/tools.h index e1724339..807aa60b 100644 --- a/include/libopencm3/stm32/tools.h +++ b/include/libopencm3/stm32/tools.h @@ -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