295 #define CLOCK_SETUP 1
296 #define SCS_Val 0x00000020
297 #define CLKSRCSEL_Val 0x00000001
299 #define PLL0CFG_Val 0x00050063
301 #define PLL1CFG_Val 0x00000023
302 #define CCLKCFG_Val 0x00000003
303 #define USBCLKCFG_Val 0x00000000
304 #define PCLKSEL0_Val 0x00000000
305 #define PCLKSEL1_Val 0x00000000
306 #define PCONP_Val 0x042887DE
307 #define CLKOUTCFG_Val 0x00000000
323 #define FLASH_SETUP 1
324 #define FLASHCFG_Val 0x0000303A
333 #define CHECK_RANGE(val, min, max) ((val < min) || (val > max))
334 #define CHECK_RSVD(val, mask) (val & mask)
337 #if (CHECK_RSVD((SCS_Val), ~0x00000030))
338 #error "SCS: Invalid values of reserved bits!"
341 #if (CHECK_RANGE((CLKSRCSEL_Val), 0, 2))
342 #error "CLKSRCSEL: Value out of range!"
345 #if (CHECK_RSVD((PLL0CFG_Val), ~0x00FF7FFF))
346 #error "PLL0CFG: Invalid values of reserved bits!"
349 #if (CHECK_RSVD((PLL1CFG_Val), ~0x0000007F))
350 #error "PLL1CFG: Invalid values of reserved bits!"
353 #if ((CCLKCFG_Val != 0) && (((CCLKCFG_Val - 1) % 2)))
354 #error "CCLKCFG: CCLKSEL field does not contain only odd values or 0!"
357 #if (CHECK_RSVD((USBCLKCFG_Val), ~0x0000000F))
358 #error "USBCLKCFG: Invalid values of reserved bits!"
361 #if (CHECK_RSVD((PCLKSEL0_Val), 0x000C0C00))
362 #error "PCLKSEL0: Invalid values of reserved bits!"
365 #if (CHECK_RSVD((PCLKSEL1_Val), 0x03000300))
366 #error "PCLKSEL1: Invalid values of reserved bits!"
369 #if (CHECK_RSVD((PCONP_Val), 0x10100821))
370 #error "PCONP: Invalid values of reserved bits!"
373 #if (CHECK_RSVD((CLKOUTCFG_Val), ~0x000001FF))
374 #error "CLKOUTCFG: Invalid values of reserved bits!"
378 #if (CHECK_RSVD((FLASHCFG_Val), ~0x0000F07F))
379 #error "FLASHCFG: Invalid values of reserved bits!"
390 #define XTAL (12000000UL)
391 #define OSC_CLK ( XTAL)
392 #define RTC_CLK ( 32768UL)
393 #define IRC_OSC ( 4000000UL)
397 #define __M (((PLL0CFG_Val ) & 0x7FFF) + 1)
398 #define __N (((PLL0CFG_Val >> 16) & 0x00FF) + 1)
399 #define __FCCO(__F_IN) ((2 * __M * __F_IN) / __N)
400 #define __CCLK_DIV (((CCLKCFG_Val ) & 0x00FF) + 1)
404 #if ((CLKSRCSEL_Val & 0x03) == 1)
405 #define __CORE_CLK (__FCCO(OSC_CLK) / __CCLK_DIV)
406 #elif ((CLKSRCSEL_Val & 0x03) == 2)
407 #define __CORE_CLK (__FCCO(RTC_CLK) / __CCLK_DIV)
409 #define __CORE_CLK (__FCCO(IRC_OSC) / __CCLK_DIV)
412 #if ((CLKSRCSEL_Val & 0x03) == 1)
413 #define __CORE_CLK (OSC_CLK / __CCLK_DIV)
414 #elif ((CLKSRCSEL_Val & 0x03) == 2)
415 #define __CORE_CLK (RTC_CLK / __CCLK_DIV)
417 #define __CORE_CLK (IRC_OSC / __CCLK_DIV)
451 if (((
LPC_SC->PLL0STAT >> 24) & 3) == 3) {
452 switch (
LPC_SC->CLKSRCSEL & 0x03) {
456 ((2 * ((
LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
457 (((
LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
458 ((
LPC_SC->CCLKCFG & 0xFF)+ 1));
462 ((2 * ((
LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
463 (((
LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
464 ((
LPC_SC->CCLKCFG & 0xFF)+ 1));
468 ((2 * ((
LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
469 (((
LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
470 ((
LPC_SC->CCLKCFG & 0xFF)+ 1));
474 switch (
LPC_SC->CLKSRCSEL & 0x03) {
503 if (
LPC_SC->SCS & (1 << 5)) {
504 while ((
LPC_SC->SCS & (1<<6)) == 0);
524 while (!(
LPC_SC->PLL0STAT & (1<<26)));
529 while (!(
LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));
540 while (!(
LPC_SC->PLL1STAT & (1<<10)));
545 while (!(
LPC_SC->PLL1STAT & ((1<< 9) | (1<< 8))));
554 #if (FLASH_SETUP == 1)
559 #if (__RAM_MODE__==1)
560 SCB->VTOR = 0x10000000 & 0x3FFFFF80;
562 SCB->VTOR = 0x00000000 & 0x3FFFFF80;