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

4.104.114.95
Last change on this file since d34d8692 was d34d8692, checked in by Joel Sherrill <joel.sherrill@…>, on 12/04/07 at 22:22:26

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

  • include/bsp.h, startup/bspstart.c: Move interrupt_stack_size field from CPU Table to Configuration Table. Eliminate CPU Table from all ports. Delete references to CPU Table in all forms.
  • Property mode set to 100644
File size: 7.6 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.rtems.com/license/LICENSE.
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
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 mmu_set_cpu_async_mode(void);
89void bsp_start_default( void )
90{
91    int i;
92
93    /* Set the MCU prescaler to divide by 1 */
94    MC9328MXL_PLL_CSCR &= ~MC9328MXL_PLL_CSCR_PRESC;
95
96    /* Enable the MCU PLL */
97    MC9328MXL_PLL_CSCR |= MC9328MXL_PLL_CSCR_MPEN;
98
99    /* Delay to allow time for PLL to get going */
100    for (i = 0; i < 100; i++) {
101        asm volatile ("nop\n");
102    }
103
104    /* Set the CPU to asynchrous clock mode, so it uses its fastest clock */
105    mmu_set_cpu_async_mode();
106
107    /* disable interrupts */
108    MC9328MXL_AITC_INTENABLEL = 0;
109    MC9328MXL_AITC_INTENABLEH = 0;
110
111    /* Set interrupt priority to -1 (allow all priorities) */
112    MC9328MXL_AITC_NIMASK = 0x1f;
113
114    /* Place RTEMS workspace at beginning of free memory. */
115    BSP_Configuration.work_space_start = (void *)&_bss_free_start;
116   
117    free_mem_start = ((uint32_t)&_bss_free_start +
118                      BSP_Configuration.work_space_size);
119   
120    free_mem_end = ((uint32_t)&_sdram_base + (uint32_t)&_sdram_size);
121
122    /*
123     * Init rtems exceptions management
124     */
125    rtems_exception_init_mngt();
126   
127    /*
128     * Init rtems interrupt management
129     */
130    rtems_irq_mngt_init();
131   
132   
133    /*
134     *  The following information is very useful when debugging.
135     */
136#if 0
137    printk( "work_space_size = 0x%x\n",
138            BSP_Configuration.work_space_size );
139    printk( "maximum_extensions = 0x%x\n",
140            BSP_Configuration.maximum_extensions );
141    printk( "microseconds_per_tick = 0x%x\n",
142            BSP_Configuration.microseconds_per_tick );
143    printk( "ticks_per_timeslice = 0x%x\n",
144            BSP_Configuration.ticks_per_timeslice );
145    printk( "number_of_device_drivers = 0x%x\n",
146            BSP_Configuration.number_of_device_drivers );
147    printk( "Device_driver_table = 0x%x\n",
148            BSP_Configuration.Device_driver_table );
149    printk( "work_space_start = 0x%x\n",
150            BSP_Configuration.work_space_start );
151    printk( "work_space_size = 0x%x\n",
152            BSP_Configuration.work_space_size );
153#endif
154} /* bsp_start */
155
156
157
158/* Calcuate the frequency for perclk1 */
159int get_perclk1_freq(void)
160{
161    unsigned int fin;
162    unsigned int fpll;
163    unsigned int pd;
164    unsigned int mfd;
165    unsigned int mfi;
166    unsigned int mfn;
167    uint32_t reg;
168    int perclk1;
169
170    if (MC9328MXL_PLL_CSCR & MC9328MXL_PLL_CSCR_SYSSEL) {
171        /* Use external oscillator */
172        fin = BSP_OSC_FREQ;
173    } else {
174        /* Use scaled xtal freq */
175        fin = BSP_XTAL_FREQ * 512;
176    }
177
178    /* calculate the output of the system PLL */
179    reg = MC9328MXL_PLL_SPCTL0;
180    pd = ((reg & MC9328MXL_PLL_SPCTL_PD_MASK) >>
181          MC9328MXL_PLL_SPCTL_PD_SHIFT);
182    mfd = ((reg & MC9328MXL_PLL_SPCTL_MFD_MASK) >>
183           MC9328MXL_PLL_SPCTL_MFD_SHIFT);
184    mfi = ((reg & MC9328MXL_PLL_SPCTL_MFI_MASK) >>
185           MC9328MXL_PLL_SPCTL_MFI_SHIFT);
186    mfn = ((reg & MC9328MXL_PLL_SPCTL_MFN_MASK) >>
187           MC9328MXL_PLL_SPCTL_MFN_SHIFT);
188
189#if 0
190    printk("fin = %d\n", fin);
191    printk("pd = %d\n", pd);
192    printk("mfd = %d\n", mfd);
193    printk("mfi = %d\n", mfi);
194    printk("mfn = %d\n", mfn);
195    printk("rounded (fin * mfi) / (pd + 1) = %d\n", (fin * mfi) / (pd + 1));
196    printk("rounded (fin * mfn) / ((pd + 1) * (mfd + 1)) = %d\n",
197           ((long long)fin * mfn) / ((pd + 1) * (mfd + 1)));
198#endif
199
200    fpll = 2 * ( ((fin * mfi  + (pd + 1) / 2) / (pd + 1)) +
201                 (((long long)fin * mfn + ((pd + 1) * (mfd + 1)) / 2) /
202                 ((pd + 1) * (mfd + 1))) );
203
204    /* calculate the output of the PERCLK1 divider */
205    reg = MC9328MXL_PLL_PCDR;
206    perclk1 = fpll / (1 + ((reg & MC9328MXL_PLL_PCDR_PCLK1_MASK) >>
207                           MC9328MXL_PLL_PCDR_PCLK1_SHIFT));
208
209    return perclk1;
210}
211
212/*
213 *  By making this a weak alias for bsp_start_default, a brave soul
214 *  can override the actual bsp_start routine used.
215 */
216
217void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
218
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 */
226/**
227 *  Reset the system.
228 *
229 *  This functions enables the watchdog and waits for it to
230 *  fire, thus resetting the system.
231 */
232void bsp_reset(void)
233{
234    rtems_interrupt_level level;
235
236    _CPU_ISR_Disable(level);
237
238    printk("\n\rI should reset here.\n\r");
239    while(1);
240}
Note: See TracBrowser for help on using the repository browser.