[c4e05c26] | 1 | /* |
---|
[e890774] | 2 | * LPC22XX/LPC21xx Startup code |
---|
[c4e05c26] | 3 | * |
---|
[e890774] | 4 | * Copyright (c) 2007 by Ray Xu <rayx.cn@gmail.com> |
---|
[c4e05c26] | 5 | * |
---|
| 6 | * The license and distribution terms for this file may be |
---|
| 7 | * found in the file LICENSE in this distribution or at |
---|
| 8 | * http://www.rtems.com/license/LICENSE. |
---|
[f560d0a] | 9 | */ |
---|
[c4e05c26] | 10 | |
---|
| 11 | #include <bsp.h> |
---|
[336d67a] | 12 | #include <bsp/irq-generic.h> |
---|
[c4e05c26] | 13 | #include <lpc22xx.h> |
---|
| 14 | |
---|
[f560d0a] | 15 | /* |
---|
| 16 | * Function prototypes |
---|
| 17 | */ |
---|
[c193baad] | 18 | extern void rtems_exception_init_mngt(void); |
---|
[c4e05c26] | 19 | extern void UART0_Ini(void); |
---|
| 20 | extern void printi(unsigned long); |
---|
[f560d0a] | 21 | |
---|
| 22 | /* |
---|
| 23 | * bsp_start_default - BSP initialization function |
---|
| 24 | * |
---|
| 25 | * This function is called before RTEMS is initialized and used |
---|
| 26 | * adjust the kernel's configuration. |
---|
| 27 | * |
---|
| 28 | * This function also configures the CPU's memory protection unit. |
---|
| 29 | * |
---|
| 30 | * RESTRICTIONS/LIMITATIONS: |
---|
| 31 | * Since RTEMS is not configured, no RTEMS functions can be called. |
---|
| 32 | * |
---|
| 33 | */ |
---|
[c4e05c26] | 34 | void bsp_start_default( void ) |
---|
| 35 | { |
---|
[f560d0a] | 36 | PINSEL2 =0x0f814914; |
---|
| 37 | BCFG0 = 0x1000ffef; |
---|
| 38 | BCFG1 = 0x1000ffef; |
---|
[c4e05c26] | 39 | |
---|
[f560d0a] | 40 | MEMMAP = 0x2; //debug and excute outside chip |
---|
[c4e05c26] | 41 | |
---|
[f560d0a] | 42 | PLLCON = 1; |
---|
| 43 | #if (Fpclk / (Fcclk / 4)) == 1 |
---|
[c4e05c26] | 44 | VPBDIV = 0; |
---|
[f560d0a] | 45 | #endif |
---|
| 46 | #if (Fpclk / (Fcclk / 4)) == 2 |
---|
[c4e05c26] | 47 | VPBDIV = 2; |
---|
[f560d0a] | 48 | #endif |
---|
| 49 | #if (Fpclk / (Fcclk / 4)) == 4 |
---|
[c4e05c26] | 50 | VPBDIV = 1; |
---|
[f560d0a] | 51 | #endif |
---|
[c4e05c26] | 52 | |
---|
[f560d0a] | 53 | #if (Fcco / Fcclk) == 2 |
---|
[c4e05c26] | 54 | PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5); |
---|
[f560d0a] | 55 | #endif |
---|
| 56 | #if (Fcco / Fcclk) == 4 |
---|
[c4e05c26] | 57 | PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5); |
---|
[f560d0a] | 58 | #endif |
---|
| 59 | #if (Fcco / Fcclk) == 8 |
---|
[c4e05c26] | 60 | PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5); |
---|
[f560d0a] | 61 | #endif |
---|
| 62 | #if (Fcco / Fcclk) == 16 |
---|
[c4e05c26] | 63 | PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5); |
---|
[f560d0a] | 64 | #endif |
---|
| 65 | PLLFEED = 0xaa; |
---|
| 66 | PLLFEED = 0x55; |
---|
| 67 | while((PLLSTAT & (1 << 10)) == 0); |
---|
| 68 | PLLCON = 3; |
---|
| 69 | PLLFEED = 0xaa; |
---|
| 70 | PLLFEED = 0x55; |
---|
| 71 | |
---|
| 72 | /* memory configure */ |
---|
| 73 | /* it is not needed in my formatter board */ |
---|
| 74 | //MAMCR = 0; |
---|
| 75 | // MAMTIM = 3; |
---|
| 76 | //MAMCR = 2; |
---|
| 77 | |
---|
| 78 | UART0_Ini(); |
---|
| 79 | |
---|
| 80 | /* |
---|
| 81 | * Init rtems exceptions management |
---|
| 82 | */ |
---|
| 83 | rtems_exception_init_mngt(); |
---|
| 84 | |
---|
| 85 | /* |
---|
| 86 | * Init rtems interrupt management |
---|
| 87 | */ |
---|
[dd8df59] | 88 | bsp_interrupt_initialize(); |
---|
[c4e05c26] | 89 | } /* bsp_start */ |
---|
| 90 | |
---|
| 91 | /* |
---|
| 92 | * By making this a weak alias for bsp_start_default, a brave soul |
---|
| 93 | * can override the actual bsp_start routine used. |
---|
| 94 | */ |
---|
| 95 | |
---|
| 96 | void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default"))); |
---|