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 */ |
---|
23 | extern void *_flash_size; |
---|
24 | extern void *_flash_base; |
---|
25 | extern void *_sdram_size; |
---|
26 | extern void *_sdram_base; |
---|
27 | extern void *_bss_free_start; |
---|
28 | |
---|
29 | unsigned long free_mem_start; |
---|
30 | unsigned long free_mem_end; |
---|
31 | |
---|
32 | /* Function prototypes */ |
---|
33 | extern void rtems_irq_mngt_init(void); |
---|
34 | void bsp_libc_init( void *, uint32_t, int ); |
---|
35 | static void fix_mac_addr(); |
---|
36 | |
---|
37 | /**************************************************************************/ |
---|
38 | /* */ |
---|
39 | /* NAME: bsp_pretasking_hook - Function to setup system before startup */ |
---|
40 | /* */ |
---|
41 | /* DESCRIPTION: */ |
---|
42 | /* This function is called before drivers are initialized and used */ |
---|
43 | /* to setup libc and BSP extensions. */ |
---|
44 | /* */ |
---|
45 | /* RESTRICTIONS/LIMITATIONS: */ |
---|
46 | /* Since this function is setting up libc, it cannot use and libc */ |
---|
47 | /* functions. */ |
---|
48 | /* */ |
---|
49 | /**************************************************************************/ |
---|
50 | void bsp_pretasking_hook(void) |
---|
51 | { |
---|
52 | uint32_t heap_start; |
---|
53 | uint32_t heap_size; |
---|
54 | |
---|
55 | /* |
---|
56 | * Set up the heap. |
---|
57 | */ |
---|
58 | heap_start = free_mem_start; |
---|
59 | heap_size = free_mem_end - free_mem_start; |
---|
60 | |
---|
61 | /* call rtems lib init - malloc stuff */ |
---|
62 | bsp_libc_init((void *)heap_start, heap_size, 0); |
---|
63 | |
---|
64 | #ifdef RTEMS_DEBUG |
---|
65 | |
---|
66 | rtems_debug_enable(RTEMS_DEBUG_ALL_MASK); |
---|
67 | |
---|
68 | #endif /* RTEMS_DEBUG */ |
---|
69 | |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | /**************************************************************************/ |
---|
74 | /* */ |
---|
75 | /* NAME: bsp_start_default - BSP initialization function */ |
---|
76 | /* */ |
---|
77 | /* DESCRIPTION: */ |
---|
78 | /* This function is called before RTEMS is initialized and used */ |
---|
79 | /* adjust the kernel's configuration. */ |
---|
80 | /* */ |
---|
81 | /* This function also configures the CPU's memory protection unit. */ |
---|
82 | /* */ |
---|
83 | /* RESTRICTIONS/LIMITATIONS: */ |
---|
84 | /* Since RTEMS is not configured, no RTEMS functions can be called. */ |
---|
85 | /* */ |
---|
86 | /**************************************************************************/ |
---|
87 | void bsp_start_default( void ) |
---|
88 | { |
---|
89 | /* disable interrupts */ |
---|
90 | AIC_CTL_REG(AIC_IDCR) = 0xffffffff; |
---|
91 | |
---|
92 | /* |
---|
93 | * Some versions of the bootloader have the MAC address |
---|
94 | * reversed. This fixes it, if necessary. |
---|
95 | */ |
---|
96 | fix_mac_addr(); |
---|
97 | |
---|
98 | /* Place RTEMS workspace at beginning of free memory. */ |
---|
99 | Configuration.work_space_start = (void *)&_bss_free_start; |
---|
100 | |
---|
101 | free_mem_start = ((uint32_t)&_bss_free_start + |
---|
102 | rtems_configuration_get_work_space_size()); |
---|
103 | |
---|
104 | free_mem_end = ((uint32_t)&_sdram_base + (uint32_t)&_sdram_size); |
---|
105 | |
---|
106 | |
---|
107 | /* |
---|
108 | * Init rtems exceptions management |
---|
109 | */ |
---|
110 | rtems_exception_init_mngt(); |
---|
111 | |
---|
112 | /* |
---|
113 | * Init rtems interrupt management |
---|
114 | */ |
---|
115 | rtems_irq_mngt_init(); |
---|
116 | |
---|
117 | /* |
---|
118 | * The following information is very useful when debugging. |
---|
119 | */ |
---|
120 | #if 0 |
---|
121 | printk( "work_space_size = 0x%x\n\r", |
---|
122 | rtems_configuration_get_work_space_size() ); |
---|
123 | printk( "microseconds_per_tick = 0x%x\n\r", |
---|
124 | rtems_configuration_get_microseconds_per_tick() ); |
---|
125 | printk( "ticks_per_timeslice = 0x%x\n\r", |
---|
126 | rtems_configuration_get_ticks_per_timeslice() ); |
---|
127 | printk( "work_space_size = 0x%x\n\r", |
---|
128 | rtems_configuration_get_work_space_size() ); |
---|
129 | #endif |
---|
130 | } /* bsp_start */ |
---|
131 | |
---|
132 | /* |
---|
133 | * Some versions of the bootloader shipped with the CSB337 |
---|
134 | * reverse the MAC address. This function tests for that, |
---|
135 | * and fixes the MAC address. |
---|
136 | */ |
---|
137 | static void fix_mac_addr() |
---|
138 | { |
---|
139 | uint8_t addr[6]; |
---|
140 | |
---|
141 | /* Read the MAC address */ |
---|
142 | addr[0] = (EMAC_REG(EMAC_SA1L) >> 0) & 0xff; |
---|
143 | addr[1] = (EMAC_REG(EMAC_SA1L) >> 8) & 0xff; |
---|
144 | addr[2] = (EMAC_REG(EMAC_SA1L) >> 16) & 0xff; |
---|
145 | addr[3] = (EMAC_REG(EMAC_SA1L) >> 24) & 0xff; |
---|
146 | addr[4] = (EMAC_REG(EMAC_SA1H) >> 0) & 0xff; |
---|
147 | addr[5] = (EMAC_REG(EMAC_SA1H) >> 8) & 0xff; |
---|
148 | |
---|
149 | /* Check which 3 bytes have Cogent's OUI */ |
---|
150 | if ((addr[5] == 0x00) && (addr[4] == 0x23) && (addr[3] == 0x31)) { |
---|
151 | EMAC_REG(EMAC_SA1L) = ((addr[5] << 0) | |
---|
152 | (addr[4] << 8) | |
---|
153 | (addr[3] << 16) | |
---|
154 | (addr[2] << 24)); |
---|
155 | |
---|
156 | EMAC_REG(EMAC_SA1H) = ((addr[1] << 0) | |
---|
157 | (addr[0] << 8)); |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | /* |
---|
163 | * By making this a weak alias for bsp_start_default, a brave soul |
---|
164 | * can override the actual bsp_start routine used. |
---|
165 | */ |
---|
166 | void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default"))); |
---|
167 | |
---|
168 | /** |
---|
169 | * Reset the system. |
---|
170 | * |
---|
171 | * This functions enables the watchdog and waits for it to |
---|
172 | * fire, thus resetting the system. |
---|
173 | */ |
---|
174 | void bsp_reset(void) |
---|
175 | { |
---|
176 | rtems_interrupt_level level; |
---|
177 | |
---|
178 | rtems_interrupt_disable(level); |
---|
179 | |
---|
180 | /* Enable the watchdog timer, then wait for the world to end. */ |
---|
181 | ST_REG(ST_WDMR) = ST_WDMR_RSTEN | 1; |
---|
182 | |
---|
183 | while(1); |
---|
184 | } |
---|