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

4.104.114.84.95
Last change on this file since b1cc4ec was b1cc4ec, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 4, 2005 at 11:27:26 PM

2005-01-04 Joel Sherrill <joel@…>

  • startup/bspstart.c, startup/exit.c: Remove warnings.
  • Property mode set to 100644
File size: 7.4 KB
Line 
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 *
10 * http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14#include <bsp.h>
15#include <rtems/libcsupport.h>
16#include <rtems/bspIo.h>
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
30rtems_configuration_table  BSP_Configuration;
31
32rtems_cpu_table Cpu_table;
33char            *rtems_progname = "RTEMS";
34
35extern void rtems_irq_mngt_init(void);
36void bsp_libc_init( void *, uint32_t, int );
37void bsp_postdriver_hook(void);
38
39/**************************************************************************/
40/*                                                                        */
41/* NAME: bsp_pretasking_hook - Function to setup system before startup    */
42/*                                                                        */
43/* DESCRIPTION:                                                           */
44/*   This function is called before drivers are initialized and used      */
45/*   to setup libc and BSP extensions.                                    */
46/*                                                                        */
47/* RESTRICTIONS/LIMITATIONS:                                              */
48/*   Since this function is setting up libc, it cannot use and libc       */
49/*   functions.                                                           */
50/*                                                                        */
51/**************************************************************************/
52void bsp_pretasking_hook(void)
53{
54    uint32_t heap_start;
55    uint32_t heap_size;
56
57    /*
58     * Set up the heap.
59     */
60    heap_start =  free_mem_start;
61    heap_size = free_mem_end - free_mem_start;
62
63    /* call rtems lib init - malloc stuff */
64    bsp_libc_init((void *)heap_start, heap_size, 0);
65
66#ifdef RTEMS_DEBUG
67
68    rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
69
70#endif /* RTEMS_DEBUG */
71
72} 
73 
74
75/**************************************************************************/
76/*                                                                        */
77/* NAME: bsp_start_default - BSP initialization function                  */
78/*                                                                        */
79/* DESCRIPTION:                                                           */
80/*   This function is called before RTEMS is initialized and used         */
81/*   adjust the kernel's configuration.                                   */
82/*                                                                        */
83/*   This function also configures the CPU's memory protection unit.      */
84/*                                                                        */
85/* RESTRICTIONS/LIMITATIONS:                                              */
86/*   Since RTEMS is not configured, no RTEMS functions can be called.     */
87/*                                                                        */
88/**************************************************************************/
89void bsp_start_default( void )
90{
91
92    /* disable interrupts */
93    MC9328MXL_AITC_INTENABLEL = 0;
94    MC9328MXL_AITC_INTENABLEH = 0;
95
96    /* Set interrupt priority to -1 (allow all priorities) */
97    MC9328MXL_AITC_NIMASK = 0x1f;
98
99    /* tell rtems about the hooks we are using */
100    Cpu_table.pretasking_hook        = bsp_pretasking_hook;
101    Cpu_table.postdriver_hook        = bsp_postdriver_hook;
102
103    /* tell rtems to clear the workspace by default */
104    Cpu_table.do_zero_of_workspace   = TRUE;
105   
106    /* Place RTEMS workspace at beginning of free memory. */
107    BSP_Configuration.work_space_start = (void *)&_bss_free_start;
108   
109    free_mem_start = ((uint32_t)&_bss_free_start + 
110                      BSP_Configuration.work_space_size);
111   
112    free_mem_end = ((uint32_t)&_sdram_base + (uint32_t)&_sdram_size);
113   
114
115    /*
116     * Init rtems exceptions management
117     */
118    rtems_exception_init_mngt();
119   
120    /*
121     * Init rtems interrupt management
122     */
123    rtems_irq_mngt_init();
124   
125   
126    /*
127     *  The following information is very useful when debugging.
128     */
129#if 0
130    printk( "work_space_size = 0x%x\n",
131            BSP_Configuration.work_space_size );
132    printk( "maximum_extensions = 0x%x\n",
133            BSP_Configuration.maximum_extensions );
134    printk( "microseconds_per_tick = 0x%x\n",
135            BSP_Configuration.microseconds_per_tick );
136    printk( "ticks_per_timeslice = 0x%x\n",
137            BSP_Configuration.ticks_per_timeslice );
138    printk( "maximum_devices = 0x%x\n",
139            BSP_Configuration.maximum_devices );
140    printk( "number_of_device_drivers = 0x%x\n",
141            BSP_Configuration.number_of_device_drivers );
142    printk( "Device_driver_table = 0x%x\n",
143            BSP_Configuration.Device_driver_table );
144    printk( "work_space_start = 0x%x\n",
145            BSP_Configuration.work_space_start );
146    printk( "work_space_size = 0x%x\n",
147            BSP_Configuration.work_space_size );
148#endif
149} /* bsp_start */
150
151
152
153/* Calcuate the frequency for perclk1 */
154int get_perclk1_freq(void)
155{
156    int fin;
157    int fpll;
158    int pd;
159    int mfd;
160    int mfi;
161    int mfn;
162    uint32_t reg;
163    int perclk1;
164
165    if (MC9328MXL_PLL_CSCR & MC9328MXL_PLL_CSCR_SYSSEL) {
166        /* Use external oscillator */
167        fin = BSP_OSC_FREQ;
168    } else {
169        /* Use scaled xtal freq */
170        fin = BSP_XTAL_FREQ * 512;
171    }
172
173    /* calculate the output of the system PLL */
174    reg = MC9328MXL_PLL_SPCTL0;
175    pd = ((reg & MC9328MXL_PLL_SPCTL_PD_MASK) >> 
176          MC9328MXL_PLL_SPCTL_PD_SHIFT);
177    mfd = ((reg & MC9328MXL_PLL_SPCTL_MFD_MASK) >> 
178           MC9328MXL_PLL_SPCTL_MFD_SHIFT);
179    mfi = ((reg & MC9328MXL_PLL_SPCTL_MFI_MASK) >> 
180           MC9328MXL_PLL_SPCTL_MFI_SHIFT);
181    mfn = ((reg & MC9328MXL_PLL_SPCTL_MFN_MASK) >> 
182           MC9328MXL_PLL_SPCTL_MFN_SHIFT);
183
184#if 0
185    printk("fin = %d\n", fin);
186    printk("pd = %d\n", pd);
187    printk("mfd = %d\n", mfd);
188    printk("mfi = %d\n", mfi);
189    printk("mfn = %d\n", mfn);
190    printk("(fin * mfi) / (pd + 1) = %d\n", (fin * mfi) / (pd + 1));
191    printk("(fin * mfn) / ((pd + 1) * (mfd + 1)) = %d\n",
192           (fin * mfn) / ((pd + 1) * (mfd + 1)));
193#endif
194
195    fpll = 2 * ( ((fin * mfi) / (pd + 1)) +
196                 ((fin * mfn) / ((pd + 1) * (mfd + 1))) );
197
198    /* calculate the output of the PERCLK1 divider */
199    reg = MC9328MXL_PLL_PCDR;
200    perclk1 = fpll / (1 + ((reg & MC9328MXL_PLL_PCDR_PCLK1_MASK) >>
201                           MC9328MXL_PLL_PCDR_PCLK1_SHIFT));
202
203    return perclk1;
204}
205
206/*
207 *  By making this a weak alias for bsp_start_default, a brave soul
208 *  can override the actual bsp_start routine used.
209 */
210
211void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
212
213
214/**
215 *  Reset the system.
216 *
217 *  This functions enables the watchdog and waits for it to
218 *  fire, thus resetting the system.
219 */
220/**
221 *  Reset the system.
222 *
223 *  This functions enables the watchdog and waits for it to
224 *  fire, thus resetting the system.
225 */
226void bsp_reset(void)
227{
228    rtems_interrupt_level level;
229
230    _CPU_ISR_Disable(level);
231
232    printk("\n\rI should reset here.\n\r");
233    while(1);
234}
Note: See TracBrowser for help on using the repository browser.