1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup mpc55xx |
---|
5 | * |
---|
6 | * @brief BSP startup code. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2008 |
---|
11 | * Embedded Brains GmbH |
---|
12 | * Obere Lagerstr. 30 |
---|
13 | * D-82178 Puchheim |
---|
14 | * Germany |
---|
15 | * rtems@embedded-brains.de |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be found in the file |
---|
18 | * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #include <mpc55xx/mpc55xx.h> |
---|
22 | #include <mpc55xx/regs.h> |
---|
23 | #include <mpc55xx/edma.h> |
---|
24 | |
---|
25 | #include <rtems.h> |
---|
26 | #include <rtems/bspIo.h> |
---|
27 | #include <rtems/libcsupport.h> |
---|
28 | |
---|
29 | #include <libcpu/powerpc-utility.h> |
---|
30 | |
---|
31 | #include <bsp.h> |
---|
32 | #include <bsp/irq.h> |
---|
33 | #include <bsp/irq-generic.h> |
---|
34 | #include <bsp/ppc_exc_bspsupp.h> |
---|
35 | |
---|
36 | #define RTEMS_STATUS_CHECKS_USE_PRINTK |
---|
37 | |
---|
38 | #include <rtems/status-checks.h> |
---|
39 | |
---|
40 | #define DEBUG_DONE() DEBUG_PRINT( "Done\n") |
---|
41 | |
---|
42 | #define MPC55XX_INTERRUPT_STACK_SIZE 0x1000 |
---|
43 | |
---|
44 | /* Symbols defined in linker command file */ |
---|
45 | LINKER_SYMBOL( bsp_ram_start); |
---|
46 | LINKER_SYMBOL( bsp_ram_end); |
---|
47 | LINKER_SYMBOL( bsp_external_ram_start); |
---|
48 | LINKER_SYMBOL( bsp_external_ram_size); |
---|
49 | LINKER_SYMBOL( bsp_section_bss_end); |
---|
50 | |
---|
51 | unsigned int bsp_clock_speed = 0; |
---|
52 | |
---|
53 | uint32_t bsp_clicks_per_usec = 0; |
---|
54 | |
---|
55 | void BSP_panic( char *s) |
---|
56 | { |
---|
57 | rtems_interrupt_level level; |
---|
58 | |
---|
59 | rtems_interrupt_disable( level); |
---|
60 | |
---|
61 | printk( "%s PANIC %s\n", _RTEMS_version, s); |
---|
62 | |
---|
63 | while (1) { |
---|
64 | /* Do nothing */ |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | void _BSP_Fatal_error( unsigned n) |
---|
69 | { |
---|
70 | rtems_interrupt_level level; |
---|
71 | |
---|
72 | rtems_interrupt_disable( level); |
---|
73 | |
---|
74 | printk( "%s PANIC ERROR %u\n", _RTEMS_version, n); |
---|
75 | |
---|
76 | while (1) { |
---|
77 | /* Do nothing */ |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | void bsp_pretasking_hook() |
---|
82 | { |
---|
83 | uint32_t heap_start = bsp_external_ram_start; |
---|
84 | uint32_t heap_size = bsp_external_ram_size; |
---|
85 | |
---|
86 | bsp_libc_init( heap_start, heap_size, 0); |
---|
87 | |
---|
88 | #ifdef STACK_CHECKER_ON |
---|
89 | Stack_check_Initialize(); |
---|
90 | #endif |
---|
91 | |
---|
92 | #ifdef RTEMS_DEBUG |
---|
93 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
94 | #endif |
---|
95 | } |
---|
96 | |
---|
97 | void bsp_predriver_hook() |
---|
98 | { |
---|
99 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
100 | |
---|
101 | DEBUG_PRINT( "Initialize eDMA ...\n"); |
---|
102 | sc = mpc55xx_edma_init(); |
---|
103 | if (sc != RTEMS_SUCCESSFUL) { |
---|
104 | BSP_panic( "Cannot initialize eDMA"); |
---|
105 | } else { |
---|
106 | DEBUG_DONE(); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | static void mpc55xx_ebi_init() |
---|
111 | { |
---|
112 | struct EBI_CS_tag cs = { BR : MPC55XX_ZERO_FLAGS, OR : MPC55XX_ZERO_FLAGS }; |
---|
113 | union SIU_PCR_tag pcr = MPC55XX_ZERO_FLAGS; |
---|
114 | int i = 0; |
---|
115 | |
---|
116 | /* External SRAM (0 wait states, 512kB, 4 word burst) */ |
---|
117 | cs.BR.B.BA = 0; |
---|
118 | cs.BR.B.PS = 1; |
---|
119 | cs.BR.B.BL = 1; |
---|
120 | cs.BR.B.WEBS = 0; |
---|
121 | cs.BR.B.TBDIP = 0; |
---|
122 | cs.BR.B.BI = 1; /* TODO: Enable burst */ |
---|
123 | cs.BR.B.V = 1; |
---|
124 | |
---|
125 | cs.OR.B.AM = 0x1fff0; |
---|
126 | cs.OR.B.SCY = 0; |
---|
127 | cs.OR.B.BSCY = 0; |
---|
128 | |
---|
129 | EBI.CS [0] = cs; |
---|
130 | |
---|
131 | /* !CS [0] */ |
---|
132 | SIU.PCR [0].R = 0x443; |
---|
133 | |
---|
134 | /* ADDR [8 : 31] */ |
---|
135 | for (i = 4; i < 4 + 24; ++i) { |
---|
136 | SIU.PCR [i].R = 0x440; |
---|
137 | } |
---|
138 | |
---|
139 | /* DATA [0 : 15] */ |
---|
140 | for (i = 28; i < 28 + 16; ++i) { |
---|
141 | SIU.PCR [i].R = 0x440; |
---|
142 | } |
---|
143 | |
---|
144 | /* RD_!WR */ |
---|
145 | SIU.PCR [62].R = 0x443; |
---|
146 | |
---|
147 | /* !BDIP */ |
---|
148 | SIU.PCR [63].R = 0x443; |
---|
149 | |
---|
150 | /* !WE [0 : 3] */ |
---|
151 | for (i = 64; i < 64 + 4; ++i) { |
---|
152 | SIU.PCR [i].R = 0x443; |
---|
153 | } |
---|
154 | |
---|
155 | /* !OE */ |
---|
156 | SIU.PCR [68].R = 0x443; |
---|
157 | |
---|
158 | /* !TS */ |
---|
159 | SIU.PCR [69].R = 0x443; |
---|
160 | } |
---|
161 | |
---|
162 | /** |
---|
163 | * @brief Start BSP. |
---|
164 | */ |
---|
165 | void bsp_start(void) |
---|
166 | { |
---|
167 | ppc_cpu_id_t myCpu; |
---|
168 | ppc_cpu_revision_t myCpuRevision; |
---|
169 | |
---|
170 | uint32_t ram_start = bsp_ram_start; |
---|
171 | uint32_t ram_end = bsp_ram_end; |
---|
172 | uint32_t interrupt_stack_start = ram_end - 2 * MPC55XX_INTERRUPT_STACK_SIZE; |
---|
173 | uint32_t interrupt_stack_size = MPC55XX_INTERRUPT_STACK_SIZE; |
---|
174 | uint32_t work_space_start = bsp_section_bss_end; |
---|
175 | uint32_t work_space_end = work_space_start + rtems_configuration_get_work_space_size(); |
---|
176 | |
---|
177 | /* ESCI pad configuration */ |
---|
178 | SIU.PCR [89].R = 0x400; |
---|
179 | SIU.PCR [90].R = 0x400; |
---|
180 | |
---|
181 | DEBUG_PRINT( "BSP start ...\n"); |
---|
182 | |
---|
183 | /* Memory layout */ |
---|
184 | |
---|
185 | Configuration.work_space_start = work_space_start; |
---|
186 | |
---|
187 | DEBUG_PRINT( "System clock : %i\n", mpc55xx_get_system_clock()); |
---|
188 | DEBUG_PRINT( "Memory start : 0x%08x\n", ram_start); |
---|
189 | DEBUG_PRINT( "Memory end : 0x%08x\n", ram_end); |
---|
190 | DEBUG_PRINT( "Memory size : 0x%08x\n", ram_end - ram_start); |
---|
191 | DEBUG_PRINT( "Work space start : 0x%08x\n", work_space_start); |
---|
192 | DEBUG_PRINT( "Work space end : 0x%08x\n", work_space_end); |
---|
193 | DEBUG_PRINT( "Work space size : 0x%08x\n", work_space_end - work_space_start); |
---|
194 | DEBUG_PRINT( "Interrupt stack start : 0x%08x\n", interrupt_stack_start); |
---|
195 | DEBUG_PRINT( "Interrupt stack end : 0x%08x\n", interrupt_stack_start + interrupt_stack_size); |
---|
196 | DEBUG_PRINT( "Interrupt stack size : 0x%08x\n", interrupt_stack_size); |
---|
197 | |
---|
198 | if (work_space_end > interrupt_stack_start) { |
---|
199 | BSP_panic( "Not enough memory for the work space"); |
---|
200 | } |
---|
201 | |
---|
202 | /* |
---|
203 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() |
---|
204 | * function store the result in global variables so that it can be used |
---|
205 | * latter... |
---|
206 | */ |
---|
207 | myCpu = get_ppc_cpu_type(); |
---|
208 | myCpuRevision = get_ppc_cpu_revision(); |
---|
209 | |
---|
210 | /* Time reference value */ |
---|
211 | bsp_clicks_per_usec = bsp_clock_speed / 1000000; |
---|
212 | |
---|
213 | /* Initialize External Bus Interface */ |
---|
214 | mpc55xx_ebi_init(); |
---|
215 | |
---|
216 | /* Initialize exceptions */ |
---|
217 | DEBUG_PRINT( "Initialize exceptions ...\n"); |
---|
218 | ppc_exc_initialize( PPC_INTERRUPT_DISABLE_MASK_DEFAULT, interrupt_stack_start, interrupt_stack_size); |
---|
219 | DEBUG_DONE(); |
---|
220 | |
---|
221 | /* Initialize interrupts */ |
---|
222 | DEBUG_PRINT( "Initialize interrupts ...\n"); |
---|
223 | if (bsp_interrupt_initialize() != RTEMS_SUCCESSFUL) { |
---|
224 | BSP_panic( "Cannot initialize interrupts"); |
---|
225 | } else { |
---|
226 | DEBUG_DONE(); |
---|
227 | } |
---|
228 | |
---|
229 | DEBUG_PRINT( "BSP start done\n"); |
---|
230 | |
---|
231 | return; |
---|
232 | |
---|
233 | /* TODO */ |
---|
234 | /* |
---|
235 | * Enable instruction and data caches. Do not force writethrough mode. |
---|
236 | */ |
---|
237 | #if INSTRUCTION_CACHE_ENABLE |
---|
238 | rtems_cache_enable_instruction(); |
---|
239 | #endif |
---|
240 | #if DATA_CACHE_ENABLE |
---|
241 | rtems_cache_enable_data(); |
---|
242 | #endif |
---|
243 | } |
---|
244 | |
---|
245 | /** |
---|
246 | * @brief Idle thread body. |
---|
247 | */ |
---|
248 | Thread _Thread_Idle_body( uint32_t ignored) |
---|
249 | { |
---|
250 | |
---|
251 | while (1) { |
---|
252 | asm volatile( |
---|
253 | "mfmsr 3;" |
---|
254 | "oris 3,3,4;" |
---|
255 | "sync;" |
---|
256 | "mtmsr 3;" |
---|
257 | "isync;" |
---|
258 | "ori 3,3,0;" |
---|
259 | "ori 3,3,0" |
---|
260 | ); |
---|
261 | } |
---|
262 | return 0; |
---|
263 | } |
---|