Bit set and bit clear driver functions in chip

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bit set and bit clear driver functions in chip

1,003 Views
hmyoong
Contributor III

I noticed that some of the driver functions like to read the register again during bit set or bit clear of any bit.

STATIC INLINE void Chip_SYSCTL_EnablePeriphWakeup(uint32_t periphmask)
{
LPC_SYSCTL->STARTERP1 = periphmask | (LPC_SYSCTL->STARTERP0 & ~SYSCTL_STARTERP0_RESERVED);
}

=> There is a bug here, should the code be?

STATIC INLINE void Chip_SYSCTL_EnablePeriphWakeup(uint32_t periphmask)
{
LPC_SYSCTL->STARTERP1 = periphmask | (LPC_SYSCTL->STARTERP1 & ~SYSCTL_STARTERP1_RESERVED);
}

Can this be done like this?

STATIC INLINE void Chip_SYSCTL_EnablePeriphWakeup(uint32_t periphmask)
{
 LPC_SYSCTL->STARTERP1 |= periphmask;
}

Another example

#define WKT_CTRL_RESERVED (~7)
#define WKT_CTRL_ALARMFLAG ((uint32_t) (1 << 1)) /*!< Wake-up or alarm timer flag */

STATIC INLINE void Chip_WKT_ClearIntStatus(LPC_WKT_T *pWKT)
{
 pWKT->CTRL = WKT_CTRL_ALARMFLAG | (pWKT->CTRL & ~WKT_CTRL_RESERVED);
}

Be changed to

STATIC INLINE void Chip_WKT_ClearIntStatus(LPC_WKT_T *pWKT)
{
 pWKT->CTRL &= ~WKT_CTRL_ALARMFLAG;
}
Labels (1)
0 Kudos
Reply
2 Replies

864 Views
jeremyzhou
NXP Employee
NXP Employee

Hi HM Yoong,

Thank you for your interest in NXP Semiconductor products and the opportunity to serve you.

I was wondering if you can tell me the name of  MCU and its correlated LPCopen library you use.
Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

864 Views
hmyoong
Contributor III

I am using LPCXpresso824-MAX evaluation board.

0 Kudos
Reply