Skip to content
Open
Changes from 1 commit
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
53 changes: 53 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,58 @@
*((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);
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.
*/
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);
}


Check warning on line 301 in cpu/kinetis/include/bme.h

View workflow job for this annotation

GitHub Actions / static-tests

too many consecutive empty lines
#ifdef __cplusplus
}
#endif
Expand Down