From 6fc8ba72f8df33c42b13b264e49709b24141e9c3 Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Mon, 8 Sep 2025 11:48:58 +0200 Subject: [PATCH 1/3] kinetis/bme: add bit_checkXX() functions A general `bit_checkXX` implementation was added with #16522 to `sys/bit.h`, but still missing for kinetis MCUs. --- cpu/kinetis/include/bme.h | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/cpu/kinetis/include/bme.h b/cpu/kinetis/include/bme.h index 5649201ff55e..ed43fcab2042 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,58 @@ 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. + */ +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. + */ +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. + */ +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 From 3886ffbf7e6e547ff6b14d3cfb2328fac4fddedd Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Mon, 8 Sep 2025 13:31:47 +0200 Subject: [PATCH 2/3] fixup! kinetis/bme: add bit_checkXX() functions --- cpu/kinetis/include/bme.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpu/kinetis/include/bme.h b/cpu/kinetis/include/bme.h index ed43fcab2042..35e276c74ff0 100644 --- a/cpu/kinetis/include/bme.h +++ b/cpu/kinetis/include/bme.h @@ -258,6 +258,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) { @@ -275,6 +277,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) { @@ -292,13 +296,14 @@ 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) { return *((volatile uint8_t *)(((uintptr_t)ptr) | BME_AND_MASK)) & (uint8_t)(1ul << bit); } - #ifdef __cplusplus } #endif From db2077f8a6c543319b6e9db8499df7c5ad45c974 Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Mon, 8 Sep 2025 13:32:46 +0200 Subject: [PATCH 3/3] sys/bit: document return values --- sys/include/bit.h | 6 ++++++ 1 file changed, 6 insertions(+) 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) {