C:/nxpdrv/LPC1700CMSIS/Drivers/source/lpc17xx_clkpwr.c
Go to the documentation of this file.00001 00021 /* Peripheral group ----------------------------------------------------------- */ 00026 /* Includes ------------------------------------------------------------------- */ 00027 #include "lpc17xx_clkpwr.h" 00028 00029 00030 /* Public Functions ----------------------------------------------------------- */ 00035 /*********************************************************************/ 00074 void CLKPWR_SetPCLKDiv (uint32_t ClkType, uint32_t DivVal) 00075 { 00076 uint32_t bitpos; 00077 00078 bitpos = (ClkType < 32) ? (ClkType) : (ClkType - 32); 00079 00080 /* PCLKSEL0 selected */ 00081 if (ClkType < 32) 00082 { 00083 /* Clear two bit at bit position */ 00084 LPC_SC->PCLKSEL0 &= (~(CLKPWR_PCLKSEL_BITMASK(bitpos))); 00085 00086 /* Set two selected bit */ 00087 LPC_SC->PCLKSEL0 |= (CLKPWR_PCLKSEL_SET(bitpos, DivVal)); 00088 } 00089 /* PCLKSEL1 selected */ 00090 else 00091 { 00092 /* Clear two bit at bit position */ 00093 LPC_SC->PCLKSEL1 &= ~(CLKPWR_PCLKSEL_BITMASK(bitpos)); 00094 00095 /* Set two selected bit */ 00096 LPC_SC->PCLKSEL1 |= (CLKPWR_PCLKSEL_SET(bitpos, DivVal)); 00097 } 00098 } 00099 00100 00101 /*********************************************************************/ 00135 uint32_t CLKPWR_GetPCLKSEL (uint32_t ClkType) 00136 { 00137 uint32_t bitpos, retval; 00138 00139 if (ClkType < 32) 00140 { 00141 bitpos = ClkType; 00142 retval = LPC_SC->PCLKSEL0; 00143 } 00144 else 00145 { 00146 bitpos = ClkType - 32; 00147 retval = LPC_SC->PCLKSEL1; 00148 } 00149 00150 retval = CLKPWR_PCLKSEL_GET(bitpos, retval); 00151 return retval; 00152 } 00153 00154 00155 00156 /*********************************************************************/ 00190 uint32_t CLKPWR_GetPCLK (uint32_t ClkType) 00191 { 00192 uint32_t retval, div; 00193 00194 retval = SystemCoreClock; 00195 div = CLKPWR_GetPCLKSEL(ClkType); 00196 00197 switch (div) 00198 { 00199 case 0: 00200 div = 4; 00201 break; 00202 00203 case 1: 00204 div = 1; 00205 break; 00206 00207 case 2: 00208 div = 2; 00209 break; 00210 00211 case 3: 00212 div = 8; 00213 break; 00214 } 00215 retval /= div; 00216 00217 return retval; 00218 } 00219 00220 00221 00222 /*********************************************************************/ 00260 void CLKPWR_ConfigPPWR (uint32_t PPType, FunctionalState NewState) 00261 { 00262 if (NewState == ENABLE) 00263 { 00264 LPC_SC->PCONP |= PPType & CLKPWR_PCONP_BITMASK; 00265 } 00266 else if (NewState == DISABLE) 00267 { 00268 LPC_SC->PCONP &= (~PPType) & CLKPWR_PCONP_BITMASK; 00269 } 00270 } 00271 00272 00278 void CLKPWR_Sleep(void) 00279 { 00280 LPC_SC->PCON = 0x00; 00281 /* Sleep Mode*/ 00282 __WFI(); 00283 } 00284 00285 00291 void CLKPWR_DeepSleep(void) 00292 { 00293 /* Deep-Sleep Mode, set SLEEPDEEP bit */ 00294 SCB->SCR = 0x4; 00295 LPC_SC->PCON = 0x00; 00296 /* Sleep Mode*/ 00297 __WFI(); 00298 } 00299 00300 00306 void CLKPWR_PowerDown(void) 00307 { 00308 /* Deep-Sleep Mode, set SLEEPDEEP bit */ 00309 SCB->SCR = 0x4; 00310 LPC_SC->PCON = 0x01; 00311 /* Sleep Mode*/ 00312 __WFI(); 00313 } 00314 00315 00321 void CLKPWR_DeepPowerDown(void) 00322 { 00323 /* Deep-Sleep Mode, set SLEEPDEEP bit */ 00324 SCB->SCR = 0x4; 00325 LPC_SC->PCON = 0x03; 00326 /* Sleep Mode*/ 00327 __WFI(); 00328 } 00329 00330 00344 /* --------------------------------- End Of File ------------------------------ */
Generated on Mon Feb 8 10:01:37 2010 for LPC1700CMSIS Standard Peripheral Firmware Library by 1.5.9