diff --git a/cpu/kinetis/include/bme.h b/cpu/kinetis/include/bme.h index 5649201ff55e..35e276c74ff0 100644 --- a/cpu/kinetis/include/bme.h +++ b/cpu/kinetis/include/bme.h @@ -22,6 +22,7 @@ */ #include +#include #ifdef __cplusplus extern "C" @@ -246,6 +247,63 @@ static inline void bit_clear8(volatile uint8_t *ptr, uint8_t bit) *((volatile uint8_t *)(((uintptr_t)ptr) | BME_AND_MASK)) = (uint8_t)(~(1ul << bit)); } +/** + * @brief Checks if a single bit in the 32 bit word pointed to by @p ptr is set. + * + * The effect is the same as for the following snippet: + * + * @code{c} + * *ptr & (1 << bit); + * @endcode + * + * @param[in] ptr Pointer to target word. + * @param[in] bit Bit number within the word. + * + * @return True if the bit was set, false otherwise. + */ +static inline bool bit_check32(volatile uint32_t *ptr, uint8_t bit) +{ + return *((volatile uint32_t *)(((uintptr_t)ptr) | BME_AND_MASK)) & (uint32_t)(1ul << bit); +} + +/** + * @brief Checks if a single bit in the 16 bit word pointed to by @p ptr is set. + * + * The effect is the same as for the following snippet: + * + * @code{c} + * *ptr & (1 << bit); + * @endcode + * + * @param[in] ptr Pointer to target word. + * @param[in] bit Bit number within the word. + * + * @return True if the bit was set, false otherwise. + */ +static inline bool bit_check16(volatile uint16_t *ptr, uint8_t bit) +{ + return *((volatile uint16_t *)(((uintptr_t)ptr) | BME_AND_MASK)) & (uint16_t)(1ul << bit); +} + +/** + * @brief Checks if a single bit in the 8 bit byte pointed to by @p ptr is set. + * + * The effect is the same as for the following snippet: + * + * @code{c} + * *ptr & (1 << bit); + * @endcode + * + * @param[in] ptr Pointer to target byte. + * @param[in] bit Bit number within the byte. + * + * @return True if the bit was set, false otherwise. + */ +static inline bool bit_check8(volatile uint8_t *ptr, uint8_t bit) +{ + return *((volatile uint8_t *)(((uintptr_t)ptr) | BME_AND_MASK)) & (uint8_t)(1ul << bit); +} + #ifdef __cplusplus } #endif diff --git a/sys/include/bit.h b/sys/include/bit.h index d2fa09652fbf..ed31b61d3b0b 100644 --- a/sys/include/bit.h +++ b/sys/include/bit.h @@ -207,6 +207,8 @@ static inline void bit_clear8(volatile uint8_t *ptr, uint8_t bit) * * @param[in] ptr pointer to target word * @param[in] bit bit number within the word + * + * @return True if the bit was set, false otherwise. */ static inline bool bit_check32(volatile uint32_t *ptr, uint8_t bit) { @@ -224,6 +226,8 @@ static inline bool bit_check32(volatile uint32_t *ptr, uint8_t bit) * * @param[in] ptr pointer to target word * @param[in] bit bit number within the word + * + * @return True if the bit was set, false otherwise. */ static inline bool bit_check16(volatile uint16_t *ptr, uint8_t bit) { @@ -241,6 +245,8 @@ static inline bool bit_check16(volatile uint16_t *ptr, uint8_t bit) * * @param[in] ptr pointer to target byte * @param[in] bit bit number within the byte + * + * @return True if the bit was set, false otherwise. */ static inline bool bit_check8(volatile uint8_t *ptr, uint8_t bit) {