AnsweredAssumed Answered

Possible LPCOpen Clock powerdown bug?

Question asked by otsl on Oct 7, 2016
Latest reply on Nov 17, 2016 by jeremyzhou

I've been getting familiar with LPCOpen for the LPC18xx series.  It seems Chip_Clock_SetBaseClock() might have a bug.  The function documentation says:

BaseClock : CHIP_CGU_BASE_CLK_T value indicating which base clock to set
Input : CHIP_CGU_CLKIN_T value indicating which clock source to use or CLOCKINPUT_PD to power down base clock

 

However, in the function itself, it seems it only ever *tries* to power down a base clock when BaseClock >= CLK_BASE_NONE (which obviously wouldn't power down anything).  I'm not sure if this is by-design, or if the bracketing on the if() statement is just awry.  It seems to me that the base clock powerdown should happen when the if(Input != CLKINPUT_PD) is false.

 

Might I also suggest updating the forum to allow pasting of formatted code snippets?

 

/* Sets a CGU Base Clock clock source */
void Chip_Clock_SetBaseClock(CHIP_CGU_BASE_CLK_T BaseClock, CHIP_CGU_CLKIN_T Input, bool autoblocken, bool powerdn)
{
   uint32_t reg = LPC_CGU->BASE_CLK[BaseClock];

   if (BaseClock < CLK_BASE_NONE) {
      if (Input != CLKINPUT_PD) {
         /* Mask off fields we plan to update */
         reg &= ~((0x1F << 24) | 1 | (1 << 11));

         if (autoblocken) {
            reg |= (1 << 11);
         }
         if (powerdn) {
            reg |= (1 << 0);
         }

         /* Set clock source */
         reg |= (Input << 24);

         LPC_CGU->BASE_CLK[BaseClock] = reg;
      }
   }
   else {
      LPC_CGU->BASE_CLK[BaseClock] = reg | 1; /* Power down this base clock */
   }
}

Outcomes