directly read /set bits values in ControlReg and StatusReg

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

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

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

View solution in original post

0 Likes
4 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Dana and Bob,

   

Thank you for support.

   

odissey1

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You are always welcome!

   

 

   

Dana.

0 Likes