1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS generic MPC5200 BSP | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | File: irq_init.c |
---|
5 | +-----------------------------------------------------------------+ |
---|
6 | | Partially based on the code references which are named below. | |
---|
7 | | Adaptions, modifications, enhancements and any recent parts of | |
---|
8 | | the code are: | |
---|
9 | | Copyright (c) 2005 | |
---|
10 | | Embedded Brains GmbH | |
---|
11 | | Obere Lagerstr. 30 | |
---|
12 | | D-82178 Puchheim | |
---|
13 | | Germany | |
---|
14 | | rtems@embedded-brains.de | |
---|
15 | +-----------------------------------------------------------------+ |
---|
16 | | The license and distribution terms for this file may be | |
---|
17 | | found in the file LICENSE in this distribution or at | |
---|
18 | | | |
---|
19 | | http://www.rtems.com/license/LICENSE. | |
---|
20 | | | |
---|
21 | +-----------------------------------------------------------------+ |
---|
22 | | this file contains the IRQ controller/system initialization | |
---|
23 | +-----------------------------------------------------------------+ |
---|
24 | | date history ID | |
---|
25 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
---|
26 | | 01.12.05 creation doe | |
---|
27 | |*****************************************************************| |
---|
28 | |*CVS information: | |
---|
29 | |*(the following information is created automatically, | |
---|
30 | |*do not edit here) | |
---|
31 | |*****************************************************************| |
---|
32 | |* $Log$ |
---|
33 | |* Revision 1.6 2005/12/09 08:57:03 thomas |
---|
34 | |* added/modifed file headers |
---|
35 | |* |
---|
36 | |* Revision 1.5 2005/12/06 14:30:42 thomas |
---|
37 | |* updated name for peripheral register block |
---|
38 | |* |
---|
39 | |* Revision 1.4 2005/12/06 14:11:12 thomas |
---|
40 | |* added EB file headers |
---|
41 | |* |
---|
42 | * |
---|
43 | |*****************************************************************| |
---|
44 | \*===============================================================*/ |
---|
45 | /***********************************************************************/ |
---|
46 | /* */ |
---|
47 | /* Module: irq_init.c */ |
---|
48 | /* Date: 07/17/2003 */ |
---|
49 | /* Purpose: RTEMS MPC5x00 CPU interrupt initialization */ |
---|
50 | /* */ |
---|
51 | /*---------------------------------------------------------------------*/ |
---|
52 | /* */ |
---|
53 | /* Description: This file contains the implementation of rtems */ |
---|
54 | /* initialization related to interrupt handling. */ |
---|
55 | /* */ |
---|
56 | /*---------------------------------------------------------------------*/ |
---|
57 | /* */ |
---|
58 | /* Code */ |
---|
59 | /* References: MBX8xx CPU interrupt initialization */ |
---|
60 | /* Module: irq_init.c */ |
---|
61 | /* Project: RTEMS 4.6.0pre1 / MBX8xx BSP */ |
---|
62 | /* Version 1.1 */ |
---|
63 | /* Date: 04/06/2001 */ |
---|
64 | /* */ |
---|
65 | /* Author(s) / Copyright(s): */ |
---|
66 | /* */ |
---|
67 | /* CopyRight (C) 2001 valette@crf.canon.fr */ |
---|
68 | /* */ |
---|
69 | /* The license and distribution terms for this file may be */ |
---|
70 | /* found in found in the file LICENSE in this distribution or at */ |
---|
71 | /* http://www.OARcorp.com/rtems/license.html. */ |
---|
72 | /* */ |
---|
73 | /*---------------------------------------------------------------------*/ |
---|
74 | /* */ |
---|
75 | /* Partially based on the code references which are named above. */ |
---|
76 | /* Adaptions, modifications, enhancements and any recent parts of */ |
---|
77 | /* the code are under the right of */ |
---|
78 | /* */ |
---|
79 | /* IPR Engineering, Dachauer Straße 38, D-80335 München */ |
---|
80 | /* Copyright(C) 2003 */ |
---|
81 | /* */ |
---|
82 | /*---------------------------------------------------------------------*/ |
---|
83 | /* */ |
---|
84 | /* IPR Engineering makes no representation or warranties with */ |
---|
85 | /* respect to the performance of this computer program, and */ |
---|
86 | /* specifically disclaims any responsibility for any damages, */ |
---|
87 | /* special or consequential, connected with the use of this program. */ |
---|
88 | /* */ |
---|
89 | /*---------------------------------------------------------------------*/ |
---|
90 | /* */ |
---|
91 | /* Version history: 1.0 */ |
---|
92 | /* */ |
---|
93 | /***********************************************************************/ |
---|
94 | |
---|
95 | /*#include "../include/bsp.h"*/ |
---|
96 | #include "../include/bsp.h" |
---|
97 | #include <rtems.h> |
---|
98 | /*#include "../irq/irq.h"*/ |
---|
99 | #include "../irq/irq.h" |
---|
100 | #include <rtems/bspIo.h> |
---|
101 | #include "../include/raw_exception.h" |
---|
102 | #include "../include/mpc5200.h" |
---|
103 | |
---|
104 | extern unsigned int external_exception_vector_prolog_code_size; |
---|
105 | extern void external_exception_vector_prolog_code(); |
---|
106 | extern unsigned int decrementer_exception_vector_prolog_code_size; |
---|
107 | extern void decrementer_exception_vector_prolog_code(); |
---|
108 | extern unsigned int system_management_exception_vector_prolog_code_size; |
---|
109 | extern void system_management_exception_vector_prolog_code(); |
---|
110 | |
---|
111 | extern void BSP_panic(char *s); |
---|
112 | extern void _BSP_Fatal_error(unsigned int v); |
---|
113 | /* |
---|
114 | volatile unsigned int ppc_cached_irq_mask; |
---|
115 | */ |
---|
116 | |
---|
117 | /* |
---|
118 | * default on/off function |
---|
119 | */ |
---|
120 | static void nop_func(){} |
---|
121 | /* |
---|
122 | * default isOn function |
---|
123 | */ |
---|
124 | static int not_connected() {return 0;} |
---|
125 | /* |
---|
126 | * default possible isOn function |
---|
127 | */ |
---|
128 | static int connected() {return 1;} |
---|
129 | |
---|
130 | static rtems_irq_connect_data rtemsIrq[BSP_IRQ_NUMBER]; |
---|
131 | static rtems_irq_global_settings initial_config; |
---|
132 | |
---|
133 | static rtems_irq_connect_data defaultIrq = |
---|
134 | { |
---|
135 | /* vectorIdex, hdl , param, on , off , isOn */ |
---|
136 | 0, nop_func, NULL , nop_func, nop_func, not_connected }; |
---|
137 | |
---|
138 | static rtems_irq_prio irqPrioTable[BSP_SIU_IRQ_NUMBER] = |
---|
139 | { |
---|
140 | /* per. int. priorities (0-7) / 4bit coding / msb is HI/LO selection */ |
---|
141 | /* msb = 0 -> non-critical per. int. is routed to main int. (LO_int) */ |
---|
142 | /* msb = 1 -> critical per. int. is routed to critical int. (HI_int) */ |
---|
143 | 0xF, 0, 0, 0, /* smart_comm (do not change!), psc1, psc2, psc3 */ |
---|
144 | 0, 0, 0, 0, /* irda, eth, usb, ata */ |
---|
145 | 0, 0, 0, 0, /* pci_ctrl, pci_sc_rx, pci_sc_tx, res */ |
---|
146 | 0, 0, 0, 0, /* res, spi_modf, spi_spif, i2c1 */ |
---|
147 | 0, 0, 0, 0, /* i2c, can1, can2, ir_rx */ |
---|
148 | 0, 0, /* ir_rx, xlb_arb */ |
---|
149 | /* main interrupt priorities (0-7) / 4bit coding / msb is INT/SMI selection */ |
---|
150 | /* msb = 0 -> main int. is routed to processor INT (low vector base 0x500 ) */ |
---|
151 | /* msb = 1 -> main int. is routed to processor SMI (low vector base 0x1400 ) */ |
---|
152 | 0, 0, /* slice_tim2, irq1 */ |
---|
153 | 0, 0, 0, 0, /* irq2, irq3, lo_int, rtc_pint */ |
---|
154 | 0, 0, 0, 0, /* rtc_sint, gpio_std, gpio_wkup, tmr0 */ |
---|
155 | 0, 0, 0, 0, /* tmr1, tmr2, tmr3, tmr4 */ |
---|
156 | 0, 0, 0, /* tmr5, tmr6, tmr7 */ |
---|
157 | /* critical interrupt priorities (0-3) / 2bit coding / no special purpose of msb */ |
---|
158 | 0, /* irq0 */ |
---|
159 | 0, 0, 0 /* slice_tim1, hi_int, ccs_wkup */ |
---|
160 | }; |
---|
161 | |
---|
162 | uint32_t irqMaskTable[BSP_PER_IRQ_NUMBER + BSP_MAIN_IRQ_NUMBER]; |
---|
163 | |
---|
164 | |
---|
165 | /* |
---|
166 | * setup irqMaskTable to support a priorized/nested interrupt environment |
---|
167 | */ |
---|
168 | void setup_irqMaskTable(void) |
---|
169 | { |
---|
170 | rtems_irq_prio prio = 0; |
---|
171 | uint32_t i = 0, j = 0, mask = 0; |
---|
172 | |
---|
173 | /* set up the priority dependent masks for peripheral interrupts */ |
---|
174 | for(i = BSP_PER_IRQ_LOWEST_OFFSET; i <= BSP_PER_IRQ_MAX_OFFSET; i++) |
---|
175 | { |
---|
176 | |
---|
177 | prio = irqPrioTable[i]; |
---|
178 | mask = 0; |
---|
179 | |
---|
180 | for(j = BSP_PER_IRQ_LOWEST_OFFSET; j <= BSP_PER_IRQ_MAX_OFFSET; j++) |
---|
181 | { |
---|
182 | |
---|
183 | if(prio > irqPrioTable[j]) |
---|
184 | mask |= (1 << (31 - j + BSP_PER_IRQ_LOWEST_OFFSET)); |
---|
185 | |
---|
186 | if((prio == irqPrioTable[j]) && (j >= i)) |
---|
187 | mask |= (1 << (31 - j + BSP_PER_IRQ_LOWEST_OFFSET)); |
---|
188 | |
---|
189 | } |
---|
190 | |
---|
191 | irqMaskTable[i] = mask; |
---|
192 | |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | /* set up the priority dependent masks for main interrupts */ |
---|
197 | for(i = BSP_MAIN_IRQ_LOWEST_OFFSET; i <= BSP_MAIN_IRQ_MAX_OFFSET; i++) |
---|
198 | { |
---|
199 | |
---|
200 | prio = irqPrioTable[i]; |
---|
201 | mask = 0; |
---|
202 | |
---|
203 | for(j = BSP_MAIN_IRQ_LOWEST_OFFSET; j <= BSP_MAIN_IRQ_MAX_OFFSET; j++) |
---|
204 | { |
---|
205 | |
---|
206 | if(prio > irqPrioTable[j]) |
---|
207 | mask |= (1 << (16 - j + BSP_MAIN_IRQ_LOWEST_OFFSET)); |
---|
208 | |
---|
209 | if((prio == irqPrioTable[j]) && (j >= i)) |
---|
210 | mask |= (1 << (16 - j + BSP_MAIN_IRQ_LOWEST_OFFSET)); |
---|
211 | |
---|
212 | } |
---|
213 | |
---|
214 | irqMaskTable[i] = mask; |
---|
215 | |
---|
216 | } |
---|
217 | |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | /* |
---|
222 | * Initialize MPC5x00 SIU interrupt management |
---|
223 | */ |
---|
224 | void BSP_SIU_irq_init(void) |
---|
225 | { |
---|
226 | |
---|
227 | /* disable all peripheral interrupts */ |
---|
228 | mpc5200.per_mask = 0xFFFFFC00; |
---|
229 | |
---|
230 | /* peripheral interrupt priorities according to reset value */ |
---|
231 | mpc5200.per_pri_1 = 0xF0000000; |
---|
232 | mpc5200.per_pri_2 = 0x00000000; |
---|
233 | mpc5200.per_pri_3 = 0x00000000; |
---|
234 | |
---|
235 | /* disable external interrupts IRQ0-4 / critical interrupts are routed to core_int */ |
---|
236 | mpc5200.ext_en_type = 0x0F000001; |
---|
237 | |
---|
238 | /* disable main interrupts / crit. int. priorities according to reset values */ |
---|
239 | mpc5200.crit_pri_main_mask = 0x0001FFFF; |
---|
240 | |
---|
241 | /* main priorities according to reset value */ |
---|
242 | mpc5200.main_pri_1 = 0; |
---|
243 | mpc5200.main_pri_2 = 0; |
---|
244 | |
---|
245 | /* reset all status indicators */ |
---|
246 | mpc5200.csa = 0x0001FFFF; |
---|
247 | mpc5200.msa = 0x0001FFFF; |
---|
248 | mpc5200.psa = 0x003FFFFF; |
---|
249 | mpc5200.psa_be = 0x03000000; |
---|
250 | |
---|
251 | setup_irqMaskTable(); |
---|
252 | |
---|
253 | } |
---|
254 | |
---|
255 | void BSP_rtems_irq_mng_init(unsigned cpuId) |
---|
256 | { |
---|
257 | rtems_raw_except_connect_data vectorDesc; |
---|
258 | int i; |
---|
259 | |
---|
260 | BSP_SIU_irq_init(); |
---|
261 | /* |
---|
262 | * Initialize Rtems management interrupt table |
---|
263 | */ |
---|
264 | /* |
---|
265 | * re-init the rtemsIrq table |
---|
266 | */ |
---|
267 | for (i = 0; i < BSP_IRQ_NUMBER; i++) |
---|
268 | { |
---|
269 | rtemsIrq[i] = defaultIrq; |
---|
270 | rtemsIrq[i].name = i; |
---|
271 | } |
---|
272 | /* |
---|
273 | * Init initial Interrupt management config |
---|
274 | */ |
---|
275 | initial_config.irqNb = BSP_IRQ_NUMBER; |
---|
276 | initial_config.defaultEntry = defaultIrq; |
---|
277 | initial_config.irqHdlTbl = rtemsIrq; |
---|
278 | initial_config.irqBase = BSP_ASM_IRQ_VECTOR_BASE; |
---|
279 | initial_config.irqPrioTbl = irqPrioTable; |
---|
280 | |
---|
281 | if (!BSP_rtems_irq_mngt_set(&initial_config)) |
---|
282 | { |
---|
283 | /* |
---|
284 | * put something here that will show the failure... |
---|
285 | */ |
---|
286 | BSP_panic("Unable to initialize RTEMS interrupt Management!!! System locked\n"); |
---|
287 | } |
---|
288 | |
---|
289 | /* |
---|
290 | * We must connect the raw irq handler for the two |
---|
291 | * expected interrupt sources : decrementer and external interrupts. |
---|
292 | */ |
---|
293 | vectorDesc.exceptIndex = ASM_DEC_VECTOR; |
---|
294 | vectorDesc.hdl.vector = ASM_DEC_VECTOR; |
---|
295 | vectorDesc.hdl.raw_hdl = decrementer_exception_vector_prolog_code; |
---|
296 | vectorDesc.hdl.raw_hdl_size = (unsigned) &decrementer_exception_vector_prolog_code_size; |
---|
297 | vectorDesc.on = nop_func; |
---|
298 | vectorDesc.off = nop_func; |
---|
299 | vectorDesc.isOn = connected; |
---|
300 | |
---|
301 | if (!mpc60x_set_exception (&vectorDesc)) |
---|
302 | { |
---|
303 | BSP_panic("Unable to initialize RTEMS decrementer raw exception\n"); |
---|
304 | } |
---|
305 | |
---|
306 | vectorDesc.exceptIndex = ASM_EXT_VECTOR; |
---|
307 | vectorDesc.hdl.vector = ASM_EXT_VECTOR; |
---|
308 | vectorDesc.hdl.raw_hdl = external_exception_vector_prolog_code; |
---|
309 | vectorDesc.hdl.raw_hdl_size = (unsigned) &external_exception_vector_prolog_code_size; |
---|
310 | |
---|
311 | if (!mpc60x_set_exception (&vectorDesc)) |
---|
312 | { |
---|
313 | BSP_panic("Unable to initialize RTEMS external raw exception\n"); |
---|
314 | } |
---|
315 | |
---|
316 | vectorDesc.exceptIndex = ASM_SYSMGMT_VECTOR; |
---|
317 | vectorDesc.hdl.vector = ASM_SYSMGMT_VECTOR; |
---|
318 | vectorDesc.hdl.raw_hdl = system_management_exception_vector_prolog_code; |
---|
319 | vectorDesc.hdl.raw_hdl_size = (unsigned) &system_management_exception_vector_prolog_code_size; |
---|
320 | |
---|
321 | if (!mpc60x_set_exception (&vectorDesc)) |
---|
322 | { |
---|
323 | BSP_panic("Unable to initialize RTEMS system management raw exception\n"); |
---|
324 | } |
---|
325 | |
---|
326 | } |
---|
327 | |
---|