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

4.104.114.84.95
Last change on this file since fac9d066 was 4bd22812, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/21/04 at 13:46:02

2004-10-21 Ralf Corsepius <ralf_corsepius@…>

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