- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I need to access individual bit values of ControlReg and StatusReg. For that I typically do:
Bit_0 = (StatusReg_1_Status) & 0x01;
Bit_1 = (StatusReg_1_Status >>1) & 0x01;
Bit_2 = (StatusReg_1_Status >>2) & 0x01;
....
Is there any better way to directly read/set individual bits in Status / Control registers?
regards,
odissey1
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I frequently use
#define IsBitSet(Yalue, BitNo) (Value & ((uint32)0x01 << BitNo))
This is not faster (and not slower) than your code, but less prone to errors due to better readability
#define ReadyBit 3
if(IsBitSet(Status,ReadyBit)) DoSomething();
or with another macro you may write
SetBit(Status,ReadyBit);
or
ClearBit(Status,ReadyBit);
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bit Band PSOC 4 no, PSOC 3 no, PSOC 5LP Yes
There is a pointer to the status, control registers you can use,
but that does not help you much.
In the .h file -
/* Status Register */
#define Status_Reg_1_Status (* (reg8 *) Status_Reg_1_sts_sts_reg__STATUS_REG )
#define Status_Reg_1_Status_PTR ( (reg8 *) Status_Reg_1_sts_sts_reg__STATUS_REG )
#define Status_Reg_1_Status_Mask (* (reg8 *) Status_Reg_1_sts_sts_reg__MASK_REG )
#define Status_Reg_1_Status_Aux_Ctrl (* (reg8 *) Status_Reg_1_sts_sts_reg__STATUS_AUX_CTL_REG )
Here is a discussion of bit banding that might be useful -
infocenter.arm.com/help/index.jsp
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I frequently use
#define IsBitSet(Yalue, BitNo) (Value & ((uint32)0x01 << BitNo))
This is not faster (and not slower) than your code, but less prone to errors due to better readability
#define ReadyBit 3
if(IsBitSet(Status,ReadyBit)) DoSomething();
or with another macro you may write
SetBit(Status,ReadyBit);
or
ClearBit(Status,ReadyBit);
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dana and Bob,
Thank you for support.
odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome!
Dana.