Skip to content
Permalink
Browse files

util: Add WRITE_BIT macro to util.h

Macro sets/clears bit in given variable depending on boolean value.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
  • Loading branch information...
Mierunski authored and nashif committed Jul 3, 2018
1 parent e99e363 commit 030a65c468524af14d1f6ab9628d3abc8c58162f
Showing with 10 additions and 0 deletions.
  1. +10 −0 include/misc/util.h
@@ -124,6 +124,16 @@ static inline s64_t arithmetic_shift_right(s64_t value, u8_t shift)
#endif
#endif

/**
* @brief Macro sets or clears bit depending on boolean value
*
* @param var Variable to be altered
* @param bit Bit number
* @param set Value 0 clears bit, any other value sets bit
*/
#define WRITE_BIT(var, bit, set) \
((var) = (set) ? ((var) | BIT(bit)) : ((var) & ~BIT(bit)))

#define BIT_MASK(n) (BIT(n) - 1)

/**

0 comments on commit 030a65c

Please sign in to comment.
You can’t perform that action at this time.