source: rtems/c/src/lib/libbsp/arm/csb337/startup/bspstart.c @ f3343c6e

4.104.114.84.95
Last change on this file since f3343c6e was f3343c6e, checked in by Joel Sherrill <joel.sherrill@…>, on 09/12/07 at 15:15:32

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

PR 1257/bsps

  • csb336/network/lan91c11x.c, csb337/startup/bspstart.c, edb7312/irq/irq.c, gba/irq/irq.c, gba/irq/irq_init.c, gp32/startup/bspstart.c, rtl22xx/startup/bspstart.c, shared/abort/abort.c, shared/abort/simple_abort.c, shared/irq/irq_init.c: Code outside of cpukit should use the public API for rtems_interrupt_disable/rtems_interrupt_enable. By bypassing the public API and directly accessing _CPU_ISR_Disable and _CPU_ISR_Enable, they were bypassing the compiler memory barrier directive which could lead to problems. This patch also changes the type of the variable passed into these routines and addresses minor style issues.
  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Cogent CSB337 - AT91RM9200 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 *
13 *  $Id$
14*/
15#include <bsp.h>
16#include <rtems/libcsupport.h>
17#include <rtems/libio.h>
18#include <at91rm9200.h>
19#include <at91rm9200_pmc.h>
20#include <at91rm9200_emac.h>
21
22/* Global Variables */
23extern void            *_flash_size;
24extern void            *_flash_base;
25extern void            *_sdram_size;
26extern void            *_sdram_base;
27extern void            *_bss_free_start;
28
29unsigned long           free_mem_start;
30unsigned long           free_mem_end;
31
32rtems_configuration_table  BSP_Configuration; 
33rtems_cpu_table Cpu_table;
34char            *rtems_progname = "RTEMS";
35
36/* Function prototypes */
37extern void rtems_irq_mngt_init(void);
38void bsp_libc_init( void *, uint32_t, int );
39void bsp_postdriver_hook(void);
40static void fix_mac_addr();
41
42/**************************************************************************/
43/*                                                                        */
44/* NAME: bsp_pretasking_hook - Function to setup system before startup    */
45/*                                                                        */
46/* DESCRIPTION:                                                           */
47/*   This function is called before drivers are initialized and used      */
48/*   to setup libc and BSP extensions.                                    */
49/*                                                                        */
50/* RESTRICTIONS/LIMITATIONS:                                              */
51/*   Since this function is setting up libc, it cannot use and libc       */
52/*   functions.                                                           */
53/*                                                                        */
54/**************************************************************************/
55void bsp_pretasking_hook(void)
56{
57    uint32_t heap_start;
58    uint32_t heap_size;
59
60    /*
61     * Set up the heap.
62     */
63    heap_start =  free_mem_start;
64    heap_size = free_mem_end - free_mem_start;
65
66    /* call rtems lib init - malloc stuff */
67    bsp_libc_init((void *)heap_start, heap_size, 0);
68
69#ifdef RTEMS_DEBUG
70
71    rtems_debug_enable(RTEMS_DEBUG_ALL_MASK);
72
73#endif /* RTEMS_DEBUG */
74
75}
76 
77
78/**************************************************************************/
79/*                                                                        */
80/* NAME: bsp_start_default - BSP initialization function                  */
81/*                                                                        */
82/* DESCRIPTION:                                                           */
83/*   This function is called before RTEMS is initialized and used         */
84/*   adjust the kernel's configuration.                                   */
85/*                                                                        */
86/*   This function also configures the CPU's memory protection unit.      */
87/*                                                                        */
88/* RESTRICTIONS/LIMITATIONS:                                              */
89/*   Since RTEMS is not configured, no RTEMS functions can be called.     */
90/*                                                                        */
91/**************************************************************************/
92void bsp_start_default( void )
93{
94    /* disable interrupts */
95    AIC_CTL_REG(AIC_IDCR) = 0xffffffff;
96
97    /*
98     * Some versions of the bootloader have the MAC address
99     * reversed. This fixes it, if necessary.
100     */
101    fix_mac_addr();
102
103    /* tell RTEMS about the hooks we are using */
104    Cpu_table.pretasking_hook        = bsp_pretasking_hook;
105    Cpu_table.postdriver_hook        = bsp_postdriver_hook;
106   
107    /* Place RTEMS workspace at beginning of free memory. */
108    BSP_Configuration.work_space_start = (void *)&_bss_free_start;
109   
110    free_mem_start = ((uint32_t)&_bss_free_start +
111                      BSP_Configuration.work_space_size);
112   
113    free_mem_end = ((uint32_t)&_sdram_base + (uint32_t)&_sdram_size);
114   
115   
116    /*
117     * Init rtems exceptions management
118     */
119    rtems_exception_init_mngt();
120   
121    /*
122     * Init rtems interrupt management
123     */
124    rtems_irq_mngt_init();
125   
126    /*
127     *  The following information is very useful when debugging.
128     */
129#if 0
130    printk( "work_space_size = 0x%x\n\r",
131            BSP_Configuration.work_space_size );
132    printk( "maximum_extensions = 0x%x\n\r",
133            BSP_Configuration.maximum_extensions );
134    printk( "microseconds_per_tick = 0x%x\n\r",
135            BSP_Configuration.microseconds_per_tick );
136    printk( "ticks_per_timeslice = 0x%x\n\r",
137            BSP_Configuration.ticks_per_timeslice );
138    printk( "number_of_device_drivers = 0x%x\n\r",
139            BSP_Configuration.number_of_device_drivers );
140    printk( "Device_driver_table = 0x%x\n\r",
141            BSP_Configuration.Device_driver_table );
142    printk( "work_space_start = 0x%x\n\r",
143            BSP_Configuration.work_space_start );
144    printk( "work_space_size = 0x%x\n\r",
145            BSP_Configuration.work_space_size );
146#endif
147} /* bsp_start */
148
149/*
150 * Some versions of the bootloader shipped with the CSB337
151 * reverse the MAC address. This function tests for that,
152 * and fixes the MAC address.
153 */
154static void fix_mac_addr()
155{
156    uint8_t addr[6];
157
158    /* Read the MAC address */
159    addr[0] = (EMAC_REG(EMAC_SA1L) >>  0) & 0xff;
160    addr[1] = (EMAC_REG(EMAC_SA1L) >>  8) & 0xff;
161    addr[2] = (EMAC_REG(EMAC_SA1L) >> 16) & 0xff;
162    addr[3] = (EMAC_REG(EMAC_SA1L) >> 24) & 0xff;
163    addr[4] = (EMAC_REG(EMAC_SA1H) >>  0) & 0xff;
164    addr[5] = (EMAC_REG(EMAC_SA1H) >>  8) & 0xff;
165
166    /* Check which 3 bytes have Cogent's OUI */
167    if ((addr[5] == 0x00) && (addr[4] == 0x23) && (addr[3] == 0x31)) {
168        EMAC_REG(EMAC_SA1L) = ((addr[5] <<  0) |
169                               (addr[4] <<  8) |
170                               (addr[3] << 16) |
171                               (addr[2] << 24));
172
173        EMAC_REG(EMAC_SA1H) = ((addr[1] <<  0) |
174                               (addr[0] <<  8));
175    }
176}
177
178
179/*
180 *  By making this a weak alias for bsp_start_default, a brave soul
181 *  can override the actual bsp_start routine used.
182 */
183void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
184
185/**
186 *  Reset the system.
187 *
188 *  This functions enables the watchdog and waits for it to
189 *  fire, thus resetting the system.
190 */
191void bsp_reset(void)
192{
193    rtems_interrupt_level level;
194
195    rtems_interrupt_disable(level);
196
197    /* Enable the watchdog timer, then wait for the world to end. */
198    ST_REG(ST_WDMR) = ST_WDMR_RSTEN | 1;
199
200    while(1);
201}
Note: See TracBrowser for help on using the repository browser.