source: rtems/c/src/lib/libbsp/arm/rtl22xx/startup/bspstart.c @ 4130d8e2

4.104.114.95
Last change on this file since 4130d8e2 was 4130d8e2, checked in by Joel Sherrill <joel.sherrill@…>, on 12/11/07 at 15:50:25

2007-12-11 Joel Sherrill <joel.sherrill@…>

  • include/bsp.h, startup/bspstart.c: Eliminate copies of the Configuration Table. Use the RTEMS provided accessor macros to obtain configuration fields.
  • Property mode set to 100644
File size: 8.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
42unsigned long           free_mem_start;
43unsigned long           free_mem_end;
44
45/*************************************************************/
46/* Function prototypes                                       */
47/*************************************************************/
48extern void rtems_irq_mngt_init(void);
49void bsp_libc_init( void *, uint32_t, int );
50void bsp_postdriver_hook(void);
51extern void  UART0_Ini(void);
52extern void printi(unsigned long);
53/**************************************************************************/
54/*                                                                        */
55/* NAME: bps_pretasking_hook - Function to setup system before startup    */
56/*                                                                        */
57/* DESCRIPTION:                                                           */
58/*   This function is called before drivers are initialized and used      */
59/*   to setup libc and BSP extensions. It configures non cacheable        */
60/*   SDRAM, SRAM, AIM, and ADM regions and sets up the CPU's memory       */
61/*   protection unit.                                                     */
62/*                                                                        */
63/* GLOBALS USED:                                                          */
64/*   free_mem_start                                                 */
65/*   free_mem_end                                                   */
66/*                                                                        */
67/* RESTRICTIONS/LIMITATIONS:                                              */
68/*   Since this function is setting up libc, it cannot use and libc       */
69/*   functions.                                                           */
70/*                                                                        */
71/**************************************************************************/
72void bsp_pretasking_hook(void)
73{
74    uint32_t   heap_start;
75    uint32_t   heap_size;
76
77    /*
78     * Set up the heap. It uses all free SDRAM except that reserved
79     * for non-cached uses.
80     */
81    heap_start =  free_mem_start;
82
83    /*   heap_size = (free_mem_end - heap_start - MEM_NOCACHE_SIZE); */
84    /*the board seems to have only 512K memory, we use 256K as heap, 256K to
85    store the .text*/
86    heap_size = 0x40000;
87
88    bsp_libc_init((void *)heap_start, heap_size, 0);
89
90#ifdef RTEMS_DEBUG
91
92    rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
93
94#endif /* RTEMS_DEBUG */
95
96} /* bsp_pretasking_hook */
97
98/**************************************************************************/
99/*                                                                        */
100/* NAME: bsp_start_default - BSP initialization function                  */
101/*                                                                        */
102/* DESCRIPTION:                                                           */
103/*   This function is called before RTEMS is initialized and used         */
104/*   adjust the kernel's configuration.                                   */
105/*                                                                        */
106/*   This function also configures the CPU's memory protection unit.      */
107/*                                                                        */
108/* GLOBALS USED:                                                          */
109/*    Configuration                                                       */
110/*    free_mem_start                                                      */
111/*    free_mem_end                                                        */
112/*    free_mem_nocache_start                                              */
113/*    _bss_free_start                                                     */
114/*    mpu_region_tbl                                                      */
115/*                                                                        */
116/*                                                                        */
117/*                                                                        */
118/*                                                                        */
119/* RESTRICTIONS/LIMITATIONS:                                              */
120/*   Since RTEMS is not configured, no RTEMS functions can be called.     */
121/*                                                                        */
122/**************************************************************************/
123void bsp_start_default( void )
124{
125    PINSEL2 =0x0f814914;
126    BCFG0 = 0x1000ffef;
127    BCFG1 = 0x1000ffef;
128
129    MEMMAP = 0x2;  //debug and excute outside chip
130
131    PLLCON = 1;
132#if (Fpclk / (Fcclk / 4)) == 1
133    VPBDIV = 0;
134#endif
135#if (Fpclk / (Fcclk / 4)) == 2
136    VPBDIV = 2;
137#endif
138#if (Fpclk / (Fcclk / 4)) == 4
139    VPBDIV = 1;
140#endif
141
142#if (Fcco / Fcclk) == 2
143    PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
144#endif
145#if (Fcco / Fcclk) == 4
146    PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
147#endif
148#if (Fcco / Fcclk) == 8
149    PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
150#endif
151#if (Fcco / Fcclk) == 16
152    PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
153#endif
154    PLLFEED = 0xaa;
155    PLLFEED = 0x55;
156    while((PLLSTAT & (1 << 10)) == 0);
157    PLLCON = 3;
158    PLLFEED = 0xaa;
159    PLLFEED = 0x55;
160
161    /* memory configure */
162    /* it is not needed in my formatter board */
163    //MAMCR = 0;
164    // MAMTIM = 3;
165    //MAMCR = 2;
166
167    /* init VIC */
168    VICIntEnClr = 0xffffffff;
169    VICVectAddr = 0;
170    VICIntSelect = 0;
171
172    /* disable interrupts */
173    /* Setup interrupt controller.*/
174    VICProtection = 0;
175
176    /* Place RTEMS workspace at beginning of free memory. */
177    Configuration.work_space_start = (void *)&_bss_free_start;
178
179    free_mem_start = ((uint32_t)&_bss_free_start +
180                      rtems_configuration_get_work_space_size());
181
182    free_mem_end = ((uint32_t)&_sdram_base + (uint32_t)&_sdram_size);
183
184    UART0_Ini();
185
186    #if 0
187    printk(" bsp_start_default 0x%08x\n", (int)&bsp_start_defalt);
188    printk(" _bss_free_start 0x%08x\n", (int)&_bss_free_start);
189    printk(" free_mem_start 0x%08x\n", (int)free_mem_start);
190    printk(" _sdram_base 0x%08x\n", (int)&_sdram_base);
191    printk(" _sdram_size 0x%08x\n", (int)&_sdram_size);
192    printk(" free_mem_end 0x%08x\n", (int)free_mem_end);
193    #endif
194
195    /*
196     * Init rtems exceptions management
197     */
198    rtems_exception_init_mngt();
199
200    /*
201     * Init rtems interrupt management
202     */
203    rtems_irq_mngt_init();
204
205    /*
206     *  The following information is very useful when debugging.
207     */
208#if 0
209
210    printk( "work_space_size = 0x%x\n",
211            rtems_configuration_get_work_space_size() );
212    printk( "microseconds_per_tick = 0x%x\n",
213            rtems_configuration_get_microseconds_per_tick() );
214    printk( "ticks_per_timeslice = 0x%x\n",
215            rtems_configuration_get_ticks_per_timeslice() );
216
217    /*  printk( "_stack_size = 0x%x\n", _stack_size );*/
218    printk( "work_space_start = 0x%x\n", Configuration.work_space_start );
219    printk( "work_space_size = 0x%x\n", rtems_configuration_get_work_space_size() );
220#endif
221} /* bsp_start */
222
223
224/**
225 *  Reset the system.
226 *
227 *  This functions enables the watchdog and waits for it to
228 *  fire, thus resetting the system.
229 */
230/**
231 *  Reset the system.
232 *
233 *  This functions enables the watchdog and waits for it to
234 *  fire, thus resetting the system.
235 */
236void bsp_reset(void)
237{
238    rtems_interrupt_level level;
239
240    rtems_interrupt_disable(level);
241
242    while(1);
243}
244
245/*
246 *  By making this a weak alias for bsp_start_default, a brave soul
247 *  can override the actual bsp_start routine used.
248 */
249
250void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.