source: rtems/c/src/lib/libbsp/arm/rtl22xx/startup/bspstart.c @ 716f6be

4.104.114.84.95
Last change on this file since 716f6be was e890774, checked in by Joel Sherrill <joel.sherrill@…>, on 05/01/07 at 19:15:38

2007-05-01 Ray Xu <xr@…>

  • README, times, console/lpc22xx_uart.h, console/uart.c, include/bsp.h, start/start.S, startup/bspstart.c, startup/exit.c, startup/linkcmds: Update BSP to address changes between 4.7 and CVS head as well as to address comments from Ralf and Joel.
  • Property mode set to 100644
File size: 9.7 KB
Line 
1/*
2 *  LPC22XX/LPC21xx Startup code
3 *
4 *  Copyright (c) 2007 by Ray Xu <rayx.cn@gmail.com>
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *
12 *  $Id$
13*/
14
15#include <bsp.h>
16#include <rtems/libcsupport.h>
17#include <rtems/libio.h>
18#include <lpc22xx.h>
19
20
21/*************************************************************/
22/* Macros                                                    */
23/*************************************************************/
24
25/*************************************************************/
26/* Data Structures                                           */
27/*************************************************************/
28
29/*************************************************************/
30/* Global Variables                                          */
31/*************************************************************/
32/*FIX ME:we do not have SDRAM, but can I define mutiple SRAM?*/
33
34extern void            *_flash_size;
35extern void            *_flash_base;
36extern void            *_sdram_size;
37extern void            *_sdram_base;
38extern void            *_bss_free_start;
39extern void            *_bss_start_;
40extern void            *_bss_end_;
41
42
43unsigned long           free_mem_start;
44unsigned long           free_mem_end;
45
46/* The original BSP configuration table from the application and our copy of it
47   with some changes. */
48
49extern rtems_configuration_table  Configuration;
50rtems_configuration_table  BSP_Configuration;
51
52rtems_cpu_table Cpu_table;                    /* CPU configuration table.    */
53char            *rtems_progname;              /* Program name - from main(). */
54
55/*************************************************************/
56/* Function prototypes                                       */
57/*************************************************************/
58extern void rtems_irq_mngt_init(void);
59void bsp_libc_init( void *, uint32_t, int );
60void bsp_postdriver_hook(void);
61extern void  UART0_Ini(void);
62extern void printi(unsigned long);
63extern void debug_printk(char*);
64/**************************************************************************/
65/*                                                                        */
66/* NAME: bps_pretasking_hook - Function to setup system before startup    */
67/*                                                                        */
68/* DESCRIPTION:                                                           */
69/*   This function is called before drivers are initialized and used      */
70/*   to setup libc and BSP extensions. It configures non cacheable        */
71/*   SDRAM, SRAM, AIM, and ADM regions and sets up the CPU's memory       */
72/*   protection unit.                                                     */
73/*                                                                        */
74/* GLOBALS USED:                                                          */
75/*   free_mem_start                                                 */
76/*   free_mem_end                                                   */
77/*                                                                        */
78/* RESTRICTIONS/LIMITATIONS:                                              */
79/*   Since this function is setting up libc, it cannot use and libc       */
80/*   functions.                                                           */
81/*                                                                        */
82/**************************************************************************/
83void bsp_pretasking_hook(void)
84{
85    uint32_t   heap_start;
86    uint32_t   heap_size;
87
88    /*
89     * Set up the heap. It uses all free SDRAM except that reserved
90     * for non-cached uses.
91     */
92    heap_start =  free_mem_start;
93
94    /*   heap_size = (free_mem_end - heap_start - MEM_NOCACHE_SIZE); */
95    /*the board seems to have only 512K memory, we use 256K as heap, 256K to
96    store the .text*/
97    heap_size = 0x40000;
98
99    bsp_libc_init((void *)heap_start, heap_size, 0);
100
101#ifdef RTEMS_DEBUG
102
103    rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
104
105#endif /* RTEMS_DEBUG */
106
107} /* bsp_pretasking_hook */
108
109/**************************************************************************/
110/*                                                                        */
111/* NAME: bsp_start_default - BSP initialization function                  */
112/*                                                                        */
113/* DESCRIPTION:                                                           */
114/*   This function is called before RTEMS is initialized and used         */
115/*   adjust the kernel's configuration.                                   */
116/*                                                                        */
117/*   This function also configures the CPU's memory protection unit.      */
118/*                                                                        */
119/* GLOBALS USED:                                                          */
120/*    CPU_table                                                    */
121/*    BSP_Configuration                                            */
122/*    free_mem_start                                               */
123/*    free_mem_end                                                 */
124/*    free_mem_nocache_start                                       */
125/*    _bss_free_start                                              */
126/*    mpu_region_tbl                                               */
127/*                                                                        */
128/*                                                                        */
129/*                                                                        */
130/*                                                                        */
131/* RESTRICTIONS/LIMITATIONS:                                              */
132/*   Since RTEMS is not configured, no RTEMS functions can be called.     */
133/*                                                                        */
134/**************************************************************************/
135void bsp_start_default( void )
136{
137    PINSEL2 =0x0f814914;
138    BCFG0 = 0x1000ffef;
139    BCFG1 = 0x1000ffef;
140
141    MEMMAP = 0x2;  //debug and excute outside chip
142
143    PLLCON = 1;
144#if (Fpclk / (Fcclk / 4)) == 1
145    VPBDIV = 0;
146#endif
147#if (Fpclk / (Fcclk / 4)) == 2
148    VPBDIV = 2;
149#endif
150#if (Fpclk / (Fcclk / 4)) == 4
151    VPBDIV = 1;
152#endif
153
154#if (Fcco / Fcclk) == 2
155    PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
156#endif
157#if (Fcco / Fcclk) == 4
158    PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
159#endif
160#if (Fcco / Fcclk) == 8
161    PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
162#endif
163#if (Fcco / Fcclk) == 16
164    PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
165#endif
166    PLLFEED = 0xaa;
167    PLLFEED = 0x55;
168    while((PLLSTAT & (1 << 10)) == 0);
169    PLLCON = 3;
170    PLLFEED = 0xaa;
171    PLLFEED = 0x55;
172
173    /* memory configure */
174    /* it is not needed in my formatter board */
175    //MAMCR = 0;
176    // MAMTIM = 3;
177    //MAMCR = 2;
178
179    /* init VIC */
180    VICIntEnClr = 0xffffffff;
181    VICVectAddr = 0;
182    VICIntSelect = 0;
183
184    /* disable interrupts */
185    /* Setup interrupt controller.*/
186    VICProtection = 0;
187
188
189    Cpu_table.pretasking_hook        = bsp_pretasking_hook;
190    Cpu_table.postdriver_hook        = bsp_postdriver_hook;
191    Cpu_table.do_zero_of_workspace   = TRUE;
192    BSP_Configuration.microseconds_per_tick=100000;
193    /* Place RTEMS workspace at beginning of free memory. */
194    BSP_Configuration.work_space_start = (void *)&_bss_free_start;
195
196    free_mem_start = ((uint32_t)&_bss_free_start +
197                      BSP_Configuration.work_space_size);
198
199    free_mem_end = ((uint32_t)&_sdram_base + (uint32_t)&_sdram_size);
200
201    UART0_Ini();
202
203    #if 0
204    debug_printk(" bsp_start_defalt");
205    printi((int)&bsp_start_defalt);
206   
207    debug_printk(" _bss_free_start");
208    printi((int)&_bss_free_start);
209
210    debug_printk(" free_mem_start");
211    printi((int)free_mem_start);
212
213    debug_printk(" _sdram_base");
214    printi((int)&_sdram_base);
215
216    debug_printk(" _sdram_size");
217    printi((int)&_sdram_size);
218
219    debug_printk(" free_mem_end");
220    printi((int)free_mem_end);
221    #endif
222
223    /*
224     * Init rtems exceptions management
225     */
226    rtems_exception_init_mngt();
227
228    /*
229     * Init rtems interrupt management
230     */
231    rtems_irq_mngt_init();
232
233    /*
234     *  The following information is very useful when debugging.
235     */
236#if 0
237
238    printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
239    printk( "maximum_extensions = 0x%x\n", BSP_Configuration.maximum_extensions );
240    printk( "microseconds_per_tick = 0x%x\n",
241            BSP_Configuration.microseconds_per_tick );
242    printk( "ticks_per_timeslice = 0x%x\n",
243            BSP_Configuration.ticks_per_timeslice );
244    printk( "maximum_devices = 0x%x\n", BSP_Configuration.maximum_devices );
245    printk( "number_of_device_drivers = 0x%x\n",
246            BSP_Configuration.number_of_device_drivers );
247    printk( "Device_driver_table = 0x%x\n",
248            BSP_Configuration.Device_driver_table );
249
250    /*  printk( "_stack_size = 0x%x\n", _stack_size );*/
251    printk( "work_space_start = 0x%x\n", BSP_Configuration.work_space_start );
252    printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
253#endif
254} /* bsp_start */
255
256
257/**
258 *  Reset the system.
259 *
260 *  This functions enables the watchdog and waits for it to
261 *  fire, thus resetting the system.
262 */
263/**
264 *  Reset the system.
265 *
266 *  This functions enables the watchdog and waits for it to
267 *  fire, thus resetting the system.
268 */
269void bsp_reset(void)
270{
271    rtems_interrupt_level level;
272
273    _CPU_ISR_Disable(level);
274
275    while(1);
276}
277
278/*
279 *  By making this a weak alias for bsp_start_default, a brave soul
280 *  can override the actual bsp_start routine used.
281 */
282
283void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.