26 #include "bsp_board_def.h"
27 #include "../../LPC2xxx/Include/lpc2xxx_pllclk.h"
28 #include "../../LPC2xxx/Include/lpc2xxx_pclk.h"
29 #include "../../LPC2xxx/Include/lpc2xxx_pconp.h"
301 #define CLOCK_SETUP 1
304 #define SCS_Val 0x00000020
306 #ifndef CLKSRCSEL_Val
307 #define CLKSRCSEL_Val 0x00000001
313 #define PLL0CFG_Val 0x00050063
319 #define PLL1CFG_Val 0x00000023
322 #define CCLKCFG_Val 0x00000003
324 #ifndef USBCLKCFG_Val
325 #define USBCLKCFG_Val 0x00000000
328 #define PCLKSEL0_Val 0x00000000
331 #define PCLKSEL1_Val 0x00000000
334 #define PCONP_Val 0x042887DE
336 #ifndef CLKOUTCFG_Val
337 #define CLKOUTCFG_Val 0x00000000
354 #define FLASH_SETUP 1
355 #define FLASHCFG_Val 0x0000303A
364 #define CHECK_RANGE(val, min, max) ((val < min) || (val > max))
365 #define CHECK_RSVD(val, mask) (val & mask)
368 #if (CHECK_RSVD((SCS_Val), ~0x00000030))
369 #error "SCS: Invalid values of reserved bits!"
372 #if (CHECK_RANGE((CLKSRCSEL_Val), 0, 2))
373 #error "CLKSRCSEL: Value out of range!"
376 #if (CHECK_RSVD((PLL0CFG_Val), ~0x00FF7FFF))
377 #error "PLL0CFG: Invalid values of reserved bits!"
380 #if (CHECK_RSVD((PLL1CFG_Val), ~0x0000007F))
381 #error "PLL1CFG: Invalid values of reserved bits!"
384 #if (CHECK_RANGE(CCLKCFG_Val, 2, 255))
385 #error "CCLKCFG: CCLKSEL field does not contain value in range from 2 to 255!"
388 #if (CHECK_RSVD((USBCLKCFG_Val), ~0x0000000F))
389 #error "USBCLKCFG: Invalid values of reserved bits!"
392 #if (CHECK_RSVD((PCLKSEL0_Val), 0x000C0C00))
393 #error "PCLKSEL0: Invalid values of reserved bits!"
396 #if (CHECK_RSVD((PCLKSEL1_Val), 0x03000300))
397 #error "PCLKSEL1: Invalid values of reserved bits!"
400 #if (CHECK_RSVD((PCONP_Val), 0x10100821))
401 #error "PCONP: Invalid values of reserved bits!"
404 #if (CHECK_RSVD((CLKOUTCFG_Val), ~0x000001FF))
405 #error "CLKOUTCFG: Invalid values of reserved bits!"
409 #if (CHECK_RSVD((FLASHCFG_Val), ~0x0000F07F))
410 #error "FLASHCFG: Invalid values of reserved bits!"
422 #define XTAL_HZ (12000000UL)
425 #define OSC_CLK ( XTAL_HZ)
428 #define RTC_CLK ( 32768UL)
431 #define IRC_OSC ( 4000000UL)
436 #define __M (((PLL0CFG_Val ) & 0x7FFF) + 1)
437 #define __N (((PLL0CFG_Val >> 16) & 0x00FF) + 1)
438 #define __FCCO(__F_IN) ((2 * __M * __F_IN) / __N)
439 #define __CCLK_DIV (((CCLKCFG_Val ) & 0x00FF) + 1)
443 #if ((CLKSRCSEL_Val & 0x03) == 1)
444 #define __CORE_CLK (__FCCO(OSC_CLK) / __CCLK_DIV)
445 #elif ((CLKSRCSEL_Val & 0x03) == 2)
446 #define __CORE_CLK (__FCCO(RTC_CLK) / __CCLK_DIV)
448 #define __CORE_CLK (__FCCO(IRC_OSC) / __CCLK_DIV)
451 #if ((CLKSRCSEL_Val & 0x03) == 1)
452 #define __CORE_CLK (OSC_CLK / __CCLK_DIV)
453 #elif ((CLKSRCSEL_Val & 0x03) == 2)
454 #define __CORE_CLK (RTC_CLK / __CCLK_DIV)
456 #define __CORE_CLK (IRC_OSC / __CCLK_DIV)
490 if (((
LPC_SC->PLL0STAT >> 24) & 3) == 3) {
491 switch (
LPC_SC->CLKSRCSEL & 0x03) {
495 ((2 * ((
LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
496 (((
LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
497 ((
LPC_SC->CCLKCFG & 0xFF)+ 1));
501 ((2 * ((
LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
502 (((
LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
503 ((
LPC_SC->CCLKCFG & 0xFF)+ 1));
507 ((2 * ((
LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
508 (((
LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
509 ((
LPC_SC->CCLKCFG & 0xFF)+ 1));
513 switch (
LPC_SC->CLKSRCSEL & 0x03) {
541 const uint32_t PLL0_CONNECT_FLG = (1<<25) | (1<<24);
542 const uint32_t PLL1_CONNECT_FLG = (1<<8) | (1<<9);
546 if (
LPC_SC->SCS & (1 << 5)) {
547 while ((
LPC_SC->SCS & (1<<6)) == 0);
567 while (!(
LPC_SC->PLL0STAT & (1<<26)));
572 while ((
LPC_SC->PLL0STAT & PLL0_CONNECT_FLG) != PLL0_CONNECT_FLG);
583 while (!(
LPC_SC->PLL1STAT & (1<<10)));
588 while ((
LPC_SC->PLL1STAT & PLL1_CONNECT_FLG) != PLL1_CONNECT_FLG);
597 #if (FLASH_SETUP == 1)