source: rtems/c/src/lib/libbsp/arm/csb336/startup/bspstart.c @ 92c9baf

4.104.114.95
Last change on this file since 92c9baf was 92c9baf, checked in by Joel Sherrill <joel.sherrill@…>, on 05/15/08 at 15:52:58

2008-05-15 Joel Sherrill <joel.sherrill@…>

  • csb336/startup/bspstart.c, csb337/startup/bspstart.c, edb7312/startup/bspstart.c, gba/startup/bspstart.c, gp32/startup/bspstart.c, rtl22xx/startup/bspstart.c: Add capability for bootcard.c BSP Initialization Framework to ask the BSP where it has memory for the RTEMS Workspace and C Program Heap. These collectively are referred to as work area. If the BSP supports this, then it does not have to include code to split the available memory between the two areas. This reduces the amount of code in the BSP specific bspstart.c file. Additionally, the shared framework can initialize the C Library, call rtems_debug_enable(), and dirty the work area memory. Until most/all BSPs support this new capability, if the BSP supports this, it should call RTEMS_BSP_BOOTCARD_HANDLES_RAM_ALLOCATION from its configure.ac. When the transition is complete, this autoconf macro can be removed.
  • Property mode set to 100644
File size: 7.2 KB
RevLine 
[1a3d1f3e]1/*
2 * Cogent CSB336 - MC9328MXL SBC startup code
3 *
4 * Copyright (c) 2004 by Cogent Computer Systems
5 * Written by Jay Monkman <jtm@lopingdog.com>
6 *     
7 * The license and distribution terms for this file may be
8 * found in the file LICENSE in this distribution or at
9 *
[0c0ae29]10 * http://www.rtems.com/license/LICENSE.
[1a3d1f3e]11 *
12 *  $Id$
13 */
14#include <bsp.h>
15#include <rtems/libcsupport.h>
[b1cc4ec9]16#include <rtems/bspIo.h>
[1a3d1f3e]17#include <rtems/libio.h>
18#include <mc9328mxl.h>
19
20/* Global Variables */
21extern void            *_flash_size;
22extern void            *_flash_base;
23extern void            *_sdram_size;
24extern void            *_sdram_base;
25extern void            *_bss_free_start;
26
27unsigned long           free_mem_start;
28unsigned long           free_mem_end;
29
30extern void rtems_irq_mngt_init(void);
[4bd22812]31void bsp_libc_init( void *, uint32_t, int );
[1a3d1f3e]32
33/**************************************************************************/
34/*                                                                        */
35/* NAME: bsp_pretasking_hook - Function to setup system before startup    */
36/*                                                                        */
37/* DESCRIPTION:                                                           */
38/*   This function is called before drivers are initialized and used      */
39/*   to setup libc and BSP extensions.                                    */
40/*                                                                        */
41/* RESTRICTIONS/LIMITATIONS:                                              */
42/*   Since this function is setting up libc, it cannot use and libc       */
43/*   functions.                                                           */
44/*                                                                        */
45/**************************************************************************/
46void bsp_pretasking_hook(void)
47{
[4bd22812]48    uint32_t heap_start;
49    uint32_t heap_size;
[1a3d1f3e]50
51    /*
52     * Set up the heap.
53     */
54    heap_start =  free_mem_start;
55    heap_size = free_mem_end - free_mem_start;
56
57    /* call rtems lib init - malloc stuff */
58    bsp_libc_init((void *)heap_start, heap_size, 0);
59}
60 
61
62/**************************************************************************/
63/*                                                                        */
64/* NAME: bsp_start_default - BSP initialization function                  */
65/*                                                                        */
66/* DESCRIPTION:                                                           */
67/*   This function is called before RTEMS is initialized and used         */
68/*   adjust the kernel's configuration.                                   */
69/*                                                                        */
70/*   This function also configures the CPU's memory protection unit.      */
71/*                                                                        */
72/* RESTRICTIONS/LIMITATIONS:                                              */
73/*   Since RTEMS is not configured, no RTEMS functions can be called.     */
74/*                                                                        */
75/**************************************************************************/
[47dbc76]76void mmu_set_cpu_async_mode(void);
[1a3d1f3e]77void bsp_start_default( void )
78{
[47dbc76]79    int i;
80
81    /* Set the MCU prescaler to divide by 1 */
82    MC9328MXL_PLL_CSCR &= ~MC9328MXL_PLL_CSCR_PRESC;
83
84    /* Enable the MCU PLL */
85    MC9328MXL_PLL_CSCR |= MC9328MXL_PLL_CSCR_MPEN;
86
87    /* Delay to allow time for PLL to get going */
88    for (i = 0; i < 100; i++) {
89        asm volatile ("nop\n");
90    }
91
92    /* Set the CPU to asynchrous clock mode, so it uses its fastest clock */
93    mmu_set_cpu_async_mode();
[1a3d1f3e]94
95    /* disable interrupts */
96    MC9328MXL_AITC_INTENABLEL = 0;
97    MC9328MXL_AITC_INTENABLEH = 0;
98
99    /* Set interrupt priority to -1 (allow all priorities) */
100    MC9328MXL_AITC_NIMASK = 0x1f;
101
102    /* Place RTEMS workspace at beginning of free memory. */
[4130d8e2]103    Configuration.work_space_start = (void *)&_bss_free_start;
[1a3d1f3e]104   
[4bd22812]105    free_mem_start = ((uint32_t)&_bss_free_start +
[4130d8e2]106                      rtems_configuration_get_work_space_size());
[1a3d1f3e]107   
[4bd22812]108    free_mem_end = ((uint32_t)&_sdram_base + (uint32_t)&_sdram_size);
[1a3d1f3e]109
110    /*
111     * Init rtems exceptions management
112     */
113    rtems_exception_init_mngt();
114   
115    /*
116     * Init rtems interrupt management
117     */
118    rtems_irq_mngt_init();
119   
120   
121    /*
122     *  The following information is very useful when debugging.
123     */
124#if 0
125    printk( "work_space_size = 0x%x\n",
[4130d8e2]126            rtems_configuration_get_work_space_size() );
[1a3d1f3e]127    printk( "microseconds_per_tick = 0x%x\n",
[4130d8e2]128            rtems_configuration_get_microseconds_per_tick() );
[1a3d1f3e]129    printk( "ticks_per_timeslice = 0x%x\n",
[4130d8e2]130            rtems_configuration_get_ticks_per_timeslice() );
[1a3d1f3e]131    printk( "work_space_start = 0x%x\n",
[4130d8e2]132            Configuration.work_space_start );
[1a3d1f3e]133    printk( "work_space_size = 0x%x\n",
[4130d8e2]134            rtems_configuration_get_work_space_size() );
[1a3d1f3e]135#endif
136} /* bsp_start */
137
138
139
140/* Calcuate the frequency for perclk1 */
141int get_perclk1_freq(void)
142{
[47dbc76]143    unsigned int fin;
144    unsigned int fpll;
145    unsigned int pd;
146    unsigned int mfd;
147    unsigned int mfi;
148    unsigned int mfn;
[1a3d1f3e]149    uint32_t reg;
150    int perclk1;
151
152    if (MC9328MXL_PLL_CSCR & MC9328MXL_PLL_CSCR_SYSSEL) {
153        /* Use external oscillator */
154        fin = BSP_OSC_FREQ;
155    } else {
156        /* Use scaled xtal freq */
157        fin = BSP_XTAL_FREQ * 512;
158    }
159
160    /* calculate the output of the system PLL */
161    reg = MC9328MXL_PLL_SPCTL0;
162    pd = ((reg & MC9328MXL_PLL_SPCTL_PD_MASK) >>
163          MC9328MXL_PLL_SPCTL_PD_SHIFT);
164    mfd = ((reg & MC9328MXL_PLL_SPCTL_MFD_MASK) >>
165           MC9328MXL_PLL_SPCTL_MFD_SHIFT);
166    mfi = ((reg & MC9328MXL_PLL_SPCTL_MFI_MASK) >>
167           MC9328MXL_PLL_SPCTL_MFI_SHIFT);
168    mfn = ((reg & MC9328MXL_PLL_SPCTL_MFN_MASK) >>
169           MC9328MXL_PLL_SPCTL_MFN_SHIFT);
170
171#if 0
172    printk("fin = %d\n", fin);
173    printk("pd = %d\n", pd);
174    printk("mfd = %d\n", mfd);
175    printk("mfi = %d\n", mfi);
176    printk("mfn = %d\n", mfn);
[47dbc76]177    printk("rounded (fin * mfi) / (pd + 1) = %d\n", (fin * mfi) / (pd + 1));
178    printk("rounded (fin * mfn) / ((pd + 1) * (mfd + 1)) = %d\n",
179           ((long long)fin * mfn) / ((pd + 1) * (mfd + 1)));
[1a3d1f3e]180#endif
181
[47dbc76]182    fpll = 2 * ( ((fin * mfi  + (pd + 1) / 2) / (pd + 1)) +
183                 (((long long)fin * mfn + ((pd + 1) * (mfd + 1)) / 2) /
184                 ((pd + 1) * (mfd + 1))) );
[1a3d1f3e]185
186    /* calculate the output of the PERCLK1 divider */
187    reg = MC9328MXL_PLL_PCDR;
188    perclk1 = fpll / (1 + ((reg & MC9328MXL_PLL_PCDR_PCLK1_MASK) >>
189                           MC9328MXL_PLL_PCDR_PCLK1_SHIFT));
190
191    return perclk1;
192}
193
194/*
195 *  By making this a weak alias for bsp_start_default, a brave soul
196 *  can override the actual bsp_start routine used.
197 */
198
199void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
200
201
202/**
203 *  Reset the system.
204 *
205 *  This functions enables the watchdog and waits for it to
206 *  fire, thus resetting the system.
207 */
208/**
209 *  Reset the system.
210 *
211 *  This functions enables the watchdog and waits for it to
212 *  fire, thus resetting the system.
213 */
214void bsp_reset(void)
215{
216    rtems_interrupt_level level;
217
218    _CPU_ISR_Disable(level);
219
220    printk("\n\rI should reset here.\n\r");
221    while(1);
222}
Note: See TracBrowser for help on using the repository browser.