1 | /** |
---|
2 | * @defgroup leon1 Leon-1 Handler |
---|
3 | * @ingroup sparc_leon2 |
---|
4 | * |
---|
5 | * @file |
---|
6 | * @ingroup leon1 |
---|
7 | * @brief Handlers Leon-1 |
---|
8 | * |
---|
9 | * This include file contains information pertaining to the LEON-1. |
---|
10 | * The LEON-1 is a custom SPARC V7 implementation. |
---|
11 | * This CPU has a number of on-board peripherals and |
---|
12 | * was developed by the European Space Agency to target space applications. |
---|
13 | * |
---|
14 | * NOTE: Other than where absolutely required, this version currently |
---|
15 | * supports only the peripherals and bits used by the basic board |
---|
16 | * support package. This includes at least significant pieces of |
---|
17 | * the following items: |
---|
18 | * |
---|
19 | * + UART Channels A and B |
---|
20 | * + Real Time Clock |
---|
21 | * + Memory Control Register |
---|
22 | * + Interrupt Control |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | /* |
---|
27 | * COPYRIGHT (c) 1989-1998. |
---|
28 | * On-Line Applications Research Corporation (OAR). |
---|
29 | * |
---|
30 | * The license and distribution terms for this file may be |
---|
31 | * found in the file LICENSE in this distribution or at |
---|
32 | * http://www.rtems.org/license/LICENSE. |
---|
33 | * |
---|
34 | * Ported to LEON implementation of the SPARC by On-Line Applications |
---|
35 | * Research Corporation (OAR) under contract to the European Space |
---|
36 | * Agency (ESA). |
---|
37 | * |
---|
38 | * LEON modifications of respective RTEMS file: COPYRIGHT (c) 1995. |
---|
39 | * European Space Agency. |
---|
40 | */ |
---|
41 | |
---|
42 | #ifndef _INCLUDE_LEON_h |
---|
43 | #define _INCLUDE_LEON_h |
---|
44 | |
---|
45 | #include <rtems/score/sparc.h> |
---|
46 | |
---|
47 | #ifdef __cplusplus |
---|
48 | extern "C" { |
---|
49 | #endif |
---|
50 | |
---|
51 | /* |
---|
52 | * Interrupt Sources |
---|
53 | * |
---|
54 | * The interrupt source numbers directly map to the trap type and to |
---|
55 | * the bits used in the Interrupt Clear, Interrupt Force, Interrupt Mask, |
---|
56 | * and the Interrupt Pending Registers. |
---|
57 | */ |
---|
58 | |
---|
59 | #define LEON_INTERRUPT_CORRECTABLE_MEMORY_ERROR 1 |
---|
60 | #define LEON_INTERRUPT_UART_2_RX_TX 2 |
---|
61 | #define LEON_INTERRUPT_UART_1_RX_TX 3 |
---|
62 | #define LEON_INTERRUPT_EXTERNAL_0 4 |
---|
63 | #define LEON_INTERRUPT_EXTERNAL_1 5 |
---|
64 | #define LEON_INTERRUPT_EXTERNAL_2 6 |
---|
65 | #define LEON_INTERRUPT_EXTERNAL_3 7 |
---|
66 | #define LEON_INTERRUPT_TIMER1 8 |
---|
67 | #define LEON_INTERRUPT_TIMER2 9 |
---|
68 | #define LEON_INTERRUPT_EMPTY1 10 |
---|
69 | #define LEON_INTERRUPT_EMPTY2 11 |
---|
70 | #define LEON_INTERRUPT_EMPTY3 12 |
---|
71 | #define LEON_INTERRUPT_EMPTY4 13 |
---|
72 | #define LEON_INTERRUPT_EMPTY5 14 |
---|
73 | #define LEON_INTERRUPT_EMPTY6 15 |
---|
74 | |
---|
75 | #ifndef ASM |
---|
76 | |
---|
77 | /* |
---|
78 | * Trap Types for on-chip peripherals |
---|
79 | * |
---|
80 | * Source: Table 8 - Interrupt Trap Type and Default Priority Assignments |
---|
81 | * |
---|
82 | * NOTE: The priority level for each source corresponds to the least |
---|
83 | * significant nibble of the trap type. |
---|
84 | */ |
---|
85 | |
---|
86 | #define LEON_TRAP_TYPE( _source ) SPARC_ASYNCHRONOUS_TRAP((_source) + 0x10) |
---|
87 | |
---|
88 | #define LEON_TRAP_SOURCE( _trap ) ((_trap) - 0x10) |
---|
89 | |
---|
90 | #define LEON_INT_TRAP( _trap ) \ |
---|
91 | ( (_trap) >= LEON_TRAP_TYPE( LEON_INTERRUPT_CORRECTABLE_MEMORY_ERROR ) && \ |
---|
92 | (_trap) <= LEON_TRAP_TYPE( LEON_INTERRUPT_EMPTY6 ) ) |
---|
93 | |
---|
94 | /* |
---|
95 | * Structure for LEON memory mapped registers. |
---|
96 | * |
---|
97 | * Source: Section 6.1 - On-chip registers |
---|
98 | * |
---|
99 | * NOTE: There is only one of these structures per CPU, its base address |
---|
100 | * is 0x80000000, and the variable LEON_REG is placed there by the |
---|
101 | * linkcmds file. |
---|
102 | */ |
---|
103 | |
---|
104 | typedef struct { |
---|
105 | volatile unsigned int Memory_Config_1; |
---|
106 | volatile unsigned int Memory_Config_2; |
---|
107 | volatile unsigned int Edac_Control; |
---|
108 | volatile unsigned int Failed_Address; |
---|
109 | volatile unsigned int Memory_Status; |
---|
110 | volatile unsigned int Cache_Control; |
---|
111 | volatile unsigned int Power_Down; |
---|
112 | volatile unsigned int Write_Protection_1; |
---|
113 | volatile unsigned int Write_Protection_2; |
---|
114 | volatile unsigned int Leon_Configuration; |
---|
115 | volatile unsigned int dummy2; |
---|
116 | volatile unsigned int dummy3; |
---|
117 | volatile unsigned int dummy4; |
---|
118 | volatile unsigned int dummy5; |
---|
119 | volatile unsigned int dummy6; |
---|
120 | volatile unsigned int dummy7; |
---|
121 | volatile unsigned int Timer_Counter_1; |
---|
122 | volatile unsigned int Timer_Reload_1; |
---|
123 | volatile unsigned int Timer_Control_1; |
---|
124 | volatile unsigned int Watchdog; |
---|
125 | volatile unsigned int Timer_Counter_2; |
---|
126 | volatile unsigned int Timer_Reload_2; |
---|
127 | volatile unsigned int Timer_Control_2; |
---|
128 | volatile unsigned int dummy8; |
---|
129 | volatile unsigned int Scaler_Counter; |
---|
130 | volatile unsigned int Scaler_Reload; |
---|
131 | volatile unsigned int dummy9; |
---|
132 | volatile unsigned int dummy10; |
---|
133 | volatile unsigned int UART_Channel_1; |
---|
134 | volatile unsigned int UART_Status_1; |
---|
135 | volatile unsigned int UART_Control_1; |
---|
136 | volatile unsigned int UART_Scaler_1; |
---|
137 | volatile unsigned int UART_Channel_2; |
---|
138 | volatile unsigned int UART_Status_2; |
---|
139 | volatile unsigned int UART_Control_2; |
---|
140 | volatile unsigned int UART_Scaler_2; |
---|
141 | volatile unsigned int Interrupt_Mask; |
---|
142 | volatile unsigned int Interrupt_Pending; |
---|
143 | volatile unsigned int Interrupt_Force; |
---|
144 | volatile unsigned int Interrupt_Clear; |
---|
145 | volatile unsigned int PIO_Data; |
---|
146 | volatile unsigned int PIO_Direction; |
---|
147 | volatile unsigned int PIO_Interrupt; |
---|
148 | } LEON_Register_Map; |
---|
149 | |
---|
150 | #endif |
---|
151 | |
---|
152 | /* |
---|
153 | * The following constants are intended to be used ONLY in assembly |
---|
154 | * language files. |
---|
155 | * |
---|
156 | * NOTE: The intended style of usage is to load the address of LEON REGS |
---|
157 | * into a register and then use these as displacements from |
---|
158 | * that register. |
---|
159 | */ |
---|
160 | |
---|
161 | #ifdef ASM |
---|
162 | |
---|
163 | #define LEON_REG_MEMCFG1_OFFSET 0x00 |
---|
164 | #define LEON_REG_MEMCFG2_OFFSET 0x04 |
---|
165 | #define LEON_REG_EDACCTRL_OFFSET 0x08 |
---|
166 | #define LEON_REG_FAILADDR_OFFSET 0x0C |
---|
167 | #define LEON_REG_MEMSTATUS_OFFSET 0x10 |
---|
168 | #define LEON_REG_CACHECTRL_OFFSET 0x14 |
---|
169 | #define LEON_REG_POWERDOWN_OFFSET 0x18 |
---|
170 | #define LEON_REG_WRITEPROT1_OFFSET 0x1C |
---|
171 | #define LEON_REG_WRITEPROT2_OFFSET 0x20 |
---|
172 | #define LEON_REG_LEONCONF_OFFSET 0x24 |
---|
173 | #define LEON_REG_UNIMPLEMENTED_2_OFFSET 0x28 |
---|
174 | #define LEON_REG_UNIMPLEMENTED_3_OFFSET 0x2C |
---|
175 | #define LEON_REG_UNIMPLEMENTED_4_OFFSET 0x30 |
---|
176 | #define LEON_REG_UNIMPLEMENTED_5_OFFSET 0x34 |
---|
177 | #define LEON_REG_UNIMPLEMENTED_6_OFFSET 0x38 |
---|
178 | #define LEON_REG_UNIMPLEMENTED_7_OFFSET 0x3C |
---|
179 | #define LEON_REG_TIMERCNT1_OFFSET 0x40 |
---|
180 | #define LEON_REG_TIMERLOAD1_OFFSET 0x44 |
---|
181 | #define LEON_REG_TIMERCTRL1_OFFSET 0x48 |
---|
182 | #define LEON_REG_WDOG_OFFSET 0x4C |
---|
183 | #define LEON_REG_TIMERCNT2_OFFSET 0x50 |
---|
184 | #define LEON_REG_TIMERLOAD2_OFFSET 0x54 |
---|
185 | #define LEON_REG_TIMERCTRL2_OFFSET 0x58 |
---|
186 | #define LEON_REG_UNIMPLEMENTED_8_OFFSET 0x5C |
---|
187 | #define LEON_REG_SCALERCNT_OFFSET 0x60 |
---|
188 | #define LEON_REG_SCALER_LOAD_OFFSET 0x64 |
---|
189 | #define LEON_REG_UNIMPLEMENTED_9_OFFSET 0x68 |
---|
190 | #define LEON_REG_UNIMPLEMENTED_10_OFFSET 0x6C |
---|
191 | #define LEON_REG_UARTDATA1_OFFSET 0x70 |
---|
192 | #define LEON_REG_UARTSTATUS1_OFFSET 0x74 |
---|
193 | #define LEON_REG_UARTCTRL1_OFFSET 0x78 |
---|
194 | #define LEON_REG_UARTSCALER1_OFFSET 0x7C |
---|
195 | #define LEON_REG_UARTDATA2_OFFSET 0x80 |
---|
196 | #define LEON_REG_UARTSTATUS2_OFFSET 0x84 |
---|
197 | #define LEON_REG_UARTCTRL2_OFFSET 0x88 |
---|
198 | #define LEON_REG_UARTSCALER2_OFFSET 0x8C |
---|
199 | #define LEON_REG_IRQMASK_OFFSET 0x90 |
---|
200 | #define LEON_REG_IRQPEND_OFFSET 0x94 |
---|
201 | #define LEON_REG_IRQFORCE_OFFSET 0x98 |
---|
202 | #define LEON_REG_IRQCLEAR_OFFSET 0x9C |
---|
203 | #define LEON_REG_PIODATA_OFFSET 0xA0 |
---|
204 | #define LEON_REG_PIODIR_OFFSET 0xA4 |
---|
205 | #define LEON_REG_PIOIRQ_OFFSET 0xA8 |
---|
206 | #define LEON_REG_SIM_RAM_SIZE_OFFSET 0xF4 |
---|
207 | #define LEON_REG_SIM_ROM_SIZE_OFFSET 0xF8 |
---|
208 | |
---|
209 | #endif |
---|
210 | |
---|
211 | /* |
---|
212 | * The following defines the bits in Memory Configuration Register 1. |
---|
213 | */ |
---|
214 | |
---|
215 | #define LEON_MEMORY_CONFIGURATION_PROM_SIZE_MASK 0x0003C000 |
---|
216 | |
---|
217 | /* |
---|
218 | * The following defines the bits in Memory Configuration Register 1. |
---|
219 | */ |
---|
220 | |
---|
221 | #define LEON_MEMORY_CONFIGURATION_RAM_SIZE_MASK 0x00001E00 |
---|
222 | |
---|
223 | |
---|
224 | /* |
---|
225 | * The following defines the bits in the Timer Control Register. |
---|
226 | */ |
---|
227 | |
---|
228 | #define LEON_REG_TIMER_CONTROL_EN 0x00000001 /* 1 = enable counting */ |
---|
229 | /* 0 = hold scalar and counter */ |
---|
230 | #define LEON_REG_TIMER_CONTROL_RL 0x00000002 /* 1 = reload at 0 */ |
---|
231 | /* 0 = stop at 0 */ |
---|
232 | #define LEON_REG_TIMER_CONTROL_LD 0x00000004 /* 1 = load counter */ |
---|
233 | /* 0 = no function */ |
---|
234 | |
---|
235 | /* |
---|
236 | * The following defines the bits in the UART Control Registers. |
---|
237 | * |
---|
238 | */ |
---|
239 | |
---|
240 | #define LEON_REG_UART_CONTROL_RTD 0x000000FF /* RX/TX data */ |
---|
241 | |
---|
242 | /* |
---|
243 | * The following defines the bits in the LEON UART Status Registers. |
---|
244 | */ |
---|
245 | |
---|
246 | #define LEON_REG_UART_STATUS_CLR 0x00000000 /* Clear all status bits */ |
---|
247 | #define LEON_REG_UART_STATUS_DR 0x00000001 /* Data Ready */ |
---|
248 | #define LEON_REG_UART_STATUS_TSE 0x00000002 /* TX Send Register Empty */ |
---|
249 | #define LEON_REG_UART_STATUS_THE 0x00000004 /* TX Hold Register Empty */ |
---|
250 | #define LEON_REG_UART_STATUS_BR 0x00000008 /* Break Error */ |
---|
251 | #define LEON_REG_UART_STATUS_OE 0x00000010 /* RX Overrun Error */ |
---|
252 | #define LEON_REG_UART_STATUS_PE 0x00000020 /* RX Parity Error */ |
---|
253 | #define LEON_REG_UART_STATUS_FE 0x00000040 /* RX Framing Error */ |
---|
254 | #define LEON_REG_UART_STATUS_ERR 0x00000078 /* Error Mask */ |
---|
255 | |
---|
256 | |
---|
257 | /* |
---|
258 | * The following defines the bits in the LEON UART Status Registers. |
---|
259 | */ |
---|
260 | |
---|
261 | #define LEON_REG_UART_CTRL_RE 0x00000001 /* Receiver enable */ |
---|
262 | #define LEON_REG_UART_CTRL_TE 0x00000002 /* Transmitter enable */ |
---|
263 | #define LEON_REG_UART_CTRL_RI 0x00000004 /* Receiver interrupt enable */ |
---|
264 | #define LEON_REG_UART_CTRL_TI 0x00000008 /* Transmitter interrupt enable */ |
---|
265 | #define LEON_REG_UART_CTRL_PS 0x00000010 /* Parity select */ |
---|
266 | #define LEON_REG_UART_CTRL_PE 0x00000020 /* Parity enable */ |
---|
267 | #define LEON_REG_UART_CTRL_FL 0x00000040 /* Flow control enable */ |
---|
268 | #define LEON_REG_UART_CTRL_LB 0x00000080 /* Loop Back enable */ |
---|
269 | |
---|
270 | #ifndef ASM |
---|
271 | |
---|
272 | /* |
---|
273 | * This is used to manipulate the on-chip registers. |
---|
274 | * |
---|
275 | * The following symbol must be defined in the linkcmds file and point |
---|
276 | * to the correct location. |
---|
277 | */ |
---|
278 | |
---|
279 | extern LEON_Register_Map LEON_REG; |
---|
280 | |
---|
281 | static __inline__ int bsp_irq_fixup(int irq) |
---|
282 | { |
---|
283 | return irq; |
---|
284 | } |
---|
285 | |
---|
286 | /* |
---|
287 | * Macros to manipulate the Interrupt Clear, Interrupt Force, Interrupt Mask, |
---|
288 | * and the Interrupt Pending Registers. |
---|
289 | * |
---|
290 | * NOTE: For operations which are not atomic, this code disables interrupts |
---|
291 | * to guarantee there are no intervening accesses to the same register. |
---|
292 | * The operations which read the register, modify the value and then |
---|
293 | * store the result back are vulnerable. |
---|
294 | */ |
---|
295 | |
---|
296 | #define LEON_Clear_interrupt( _source ) \ |
---|
297 | do { \ |
---|
298 | LEON_REG.Interrupt_Clear = (1 << (_source)); \ |
---|
299 | } while (0) |
---|
300 | |
---|
301 | #define LEON_Force_interrupt( _source ) \ |
---|
302 | do { \ |
---|
303 | LEON_REG.Interrupt_Force = (1 << (_source)); \ |
---|
304 | } while (0) |
---|
305 | |
---|
306 | #define LEON_Is_interrupt_pending( _source ) \ |
---|
307 | (LEON_REG.Interrupt_Pending & (1 << (_source))) |
---|
308 | |
---|
309 | #define LEON_Is_interrupt_masked( _source ) \ |
---|
310 | (!(LEON_REG.Interrupt_Mask & (1 << (_source)))) |
---|
311 | |
---|
312 | #define LEON_Mask_interrupt( _source ) \ |
---|
313 | do { \ |
---|
314 | uint32_t _level; \ |
---|
315 | \ |
---|
316 | _level = sparc_disable_interrupts(); \ |
---|
317 | LEON_REG.Interrupt_Mask &= ~(1 << (_source)); \ |
---|
318 | sparc_enable_interrupts( _level ); \ |
---|
319 | } while (0) |
---|
320 | |
---|
321 | #define LEON_Unmask_interrupt( _source ) \ |
---|
322 | do { \ |
---|
323 | uint32_t _level; \ |
---|
324 | \ |
---|
325 | _level = sparc_disable_interrupts(); \ |
---|
326 | LEON_REG.Interrupt_Mask |= (1 << (_source)); \ |
---|
327 | sparc_enable_interrupts( _level ); \ |
---|
328 | } while (0) |
---|
329 | |
---|
330 | #define LEON_Disable_interrupt( _source, _previous ) \ |
---|
331 | do { \ |
---|
332 | uint32_t _level; \ |
---|
333 | uint32_t _mask = 1 << (_source); \ |
---|
334 | \ |
---|
335 | _level = sparc_disable_interrupts(); \ |
---|
336 | (_previous) = LEON_REG.Interrupt_Mask; \ |
---|
337 | LEON_REG.Interrupt_Mask = _previous & ~_mask; \ |
---|
338 | sparc_enable_interrupts( _level ); \ |
---|
339 | (_previous) &= _mask; \ |
---|
340 | } while (0) |
---|
341 | |
---|
342 | #define LEON_Restore_interrupt( _source, _previous ) \ |
---|
343 | do { \ |
---|
344 | uint32_t _level; \ |
---|
345 | uint32_t _mask = 1 << (_source); \ |
---|
346 | \ |
---|
347 | _level = sparc_disable_interrupts(); \ |
---|
348 | LEON_REG.Interrupt_Mask = \ |
---|
349 | (LEON_REG.Interrupt_Mask & ~_mask) | (_previous); \ |
---|
350 | sparc_enable_interrupts( _level ); \ |
---|
351 | } while (0) |
---|
352 | |
---|
353 | /* Make all SPARC BSPs have common macros for interrupt handling */ |
---|
354 | #define BSP_Clear_interrupt(_source) LEON_Clear_interrupt(_source) |
---|
355 | #define BSP_Force_interrupt(_source) LEON_Force_interrupt(_source) |
---|
356 | #define BSP_Is_interrupt_pending(_source) LEON_Is_interrupt_pending(_source) |
---|
357 | #define BSP_Is_interrupt_masked(_source) LEON_Is_interrupt_masked(_source) |
---|
358 | #define BSP_Unmask_interrupt(_source) LEON_Unmask_interrupt(_source) |
---|
359 | #define BSP_Mask_interrupt(_source) LEON_Mask_interrupt(_source) |
---|
360 | #define BSP_Disable_interrupt(_source, _previous) \ |
---|
361 | LEON_Disable_interrupt(_source, _prev) |
---|
362 | #define BSP_Restore_interrupt(_source, _previous) \ |
---|
363 | LEON_Restore_interrupt(_source, _previous) |
---|
364 | |
---|
365 | /* Make all SPARC BSPs have common macros for interrupt handling on any CPU */ |
---|
366 | #define BSP_Cpu_Is_interrupt_masked(_source, _cpu) \ |
---|
367 | BSP_Is_interrupt_masked(_source) |
---|
368 | #define BSP_Cpu_Unmask_interrupt(_source, _cpu) \ |
---|
369 | BSP_Unmask_interrupt(_source) |
---|
370 | #define BSP_Cpu_Mask_interrupt(_source, _cpu) \ |
---|
371 | BSP_Mask_interrupt(_source) |
---|
372 | #define BSP_Cpu_Disable_interrupt(_source, _previous, _cpu) \ |
---|
373 | BSP_Disable_interrupt(_source, _prev) |
---|
374 | #define BSP_Cpu_Restore_interrupt(_source, _previous, _cpu) \ |
---|
375 | BSP_Cpu_Restore_interrupt(_source, _previous) |
---|
376 | |
---|
377 | /* |
---|
378 | * Each timer control register is organized as follows: |
---|
379 | * |
---|
380 | * D0 - Enable |
---|
381 | * 1 = enable counting |
---|
382 | * 0 = hold scaler and counter |
---|
383 | * |
---|
384 | * D1 - Counter Reload |
---|
385 | * 1 = reload counter at zero and restart |
---|
386 | * 0 = stop counter at zero |
---|
387 | * |
---|
388 | * D2 - Counter Load |
---|
389 | * 1 = load counter with preset value |
---|
390 | * 0 = no function |
---|
391 | * |
---|
392 | */ |
---|
393 | |
---|
394 | #define LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO 0x00000002 |
---|
395 | #define LEON_REG_TIMER_COUNTER_STOP_AT_ZERO 0x00000000 |
---|
396 | |
---|
397 | #define LEON_REG_TIMER_COUNTER_LOAD_COUNTER 0x00000004 |
---|
398 | |
---|
399 | #define LEON_REG_TIMER_COUNTER_ENABLE_COUNTING 0x00000001 |
---|
400 | #define LEON_REG_TIMER_COUNTER_DISABLE_COUNTING 0x00000000 |
---|
401 | |
---|
402 | #define LEON_REG_TIMER_COUNTER_RELOAD_MASK 0x00000002 |
---|
403 | #define LEON_REG_TIMER_COUNTER_ENABLE_MASK 0x00000001 |
---|
404 | |
---|
405 | #define LEON_REG_TIMER_COUNTER_DEFINED_MASK 0x00000003 |
---|
406 | #define LEON_REG_TIMER_COUNTER_CURRENT_MODE_MASK 0x00000003 |
---|
407 | |
---|
408 | /* Load 32-bit word by forcing a cache-miss */ |
---|
409 | static inline unsigned int leon_r32_no_cache(uintptr_t addr) |
---|
410 | { |
---|
411 | unsigned int tmp; |
---|
412 | __asm__ volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(addr)); |
---|
413 | return tmp; |
---|
414 | } |
---|
415 | |
---|
416 | #endif /* !ASM */ |
---|
417 | |
---|
418 | #ifdef __cplusplus |
---|
419 | } |
---|
420 | #endif |
---|
421 | |
---|
422 | #endif /* !_INCLUDE_LEON_h */ |
---|
423 | |
---|