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

4.104.114.95
Last change on this file since b5e7018 was b5e7018, checked in by Joel Sherrill <joel.sherrill@…>, on 12/03/07 at 22:24:44

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

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