-
Notifications
You must be signed in to change notification settings - Fork 2.1k
kinetis/bme: add bit_checkXX() functions #21705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,7 @@ | |||||
*/ | ||||||
|
||||||
#include <stdint.h> | ||||||
#include <stdbool.h> | ||||||
|
||||||
#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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this be
Suggested change
I have There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Friendly ping @benpicco :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
If you want to move this forward, you can just set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, thanks!
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. | ||||||
elenaf9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
* | ||||||
* @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. | ||||||
elenaf9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
* | ||||||
* @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 | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.