HM Yoong

Bit set and bit clear driver functions in chip

Discussion created by HM Yoong on Apr 22, 2017
Latest reply on Apr 24, 2017 by HM Yoong

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;
}

Outcomes