Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions cpu/kinetis/include/bme.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C"
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be

Suggested change
return *((volatile uint32_t *)(((uintptr_t)ptr) | BME_AND_MASK)) & (uint32_t)(1ul << bit);
return bme_bitfield32(ptr, bit, 32);

I have openlabs-kw41z-mini at home and can test

Copy link
Contributor Author

@elenaf9 elenaf9 Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, makes sense. I am not familiar with the kinetis bme at all, so I was just implementing it analogous to the other functions and didn't look at the bitfield functions above properly.
Should I already change it in this PR or do you want to do the testing first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Friendly ping @benpicco :)

Copy link
Contributor

@benpicco benpicco Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't get to it before my vaccation - I added a unit test so we can actually test those function and turns out bit_clearXX() is already not working 😕

2025-09-30 00:44:56,723 # START
2025-09-30 00:44:56,723 # .clear bit 0
2025-09-30 00:44:56,723 # clear bit 2
2025-09-30 00:44:56,723 # 
2025-09-30 00:44:56,724 # bit_tests.test_bit8 (tests/unittests/tests-bit/tests-bit.c 36) exp 250 was 251
2025-09-30 00:44:56,724 # .
2025-09-30 00:44:56,735 # bit_tests.test_bit16 (tests/unittests/tests-bit/tests-bit.c 60) exp 65530 was 65531
2025-09-30 00:44:56,735 # .
2025-09-30 00:44:56,740 # bit_tests.test_bit32 (tests/unittests/tests-bit/tests-bit.c 84) exp 4294967290 was 4294967291

If you want to move this forward, you can just set BITBAND_FUNCTIONS_PROVIDED 0 and I'll look into this later since I can actually test it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks!

If you want to move this forward, you can just set BITBAND_FUNCTIONS_PROVIDED 0 and I'll look into this later since I can actually test it.

Opened #21750.

}

/**
* @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
Expand Down
6 changes: 6 additions & 0 deletions sys/include/bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* @brief Flag to check if the CPU has hardware bit band support
*/
#define CPU_HAS_BITBAND 1 || 0 (1 if CPU implements bit-banding, 0 if not)

Check warning on line 36 in sys/include/bit.h

View workflow job for this annotation

GitHub Actions / static-tests

keyword 'if' not followed by a single space
/**
* @brief Flag to check if bit-banding is supported for all of SRAM
*
Expand Down Expand Up @@ -73,7 +73,7 @@
static inline volatile void *bitband_addr(volatile void *ptr, uintptr_t bit)
{
return (volatile void *)((((uintptr_t)ptr) & 0xF0000000ul) + 0x2000000ul +
((((uintptr_t)ptr) & 0xFFFFFul) << 5) + (bit << 2));

Check warning on line 76 in sys/include/bit.h

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure
}

/**
Expand Down Expand Up @@ -207,6 +207,8 @@
*
* @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)
{
Expand All @@ -224,6 +226,8 @@
*
* @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)
{
Expand All @@ -241,6 +245,8 @@
*
* @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)
{
Expand Down
Loading