source: rtems/c/src/lib/libbsp/sparc/leon3/include/leon.h @ ddf0d60

4.115
Last change on this file since ddf0d60 was ddf0d60, checked in by Daniel Hellstrom <daniel@…>, on 04/17/12 at 14:25:40

LEON3: updated console driver for new AMBAPP layer

Signed-off-by: Daniel Hellstrom <daniel@…>

  • Property mode set to 100644
File size: 9.1 KB
Line 
1/*  leon.h
2 *
3 *  LEON3 BSP data types and macros.
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  Modified for LEON3 BSP.
9 *  COPYRIGHT (c) 2004.
10 *  Gaisler Research.
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#ifndef _INCLUDE_LEON_h
20#define _INCLUDE_LEON_h
21
22#include <rtems/score/sparc.h>
23#include <amba.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#define LEON_INTERRUPT_EXTERNAL_1 5
30
31#ifndef ASM
32/*
33 *  Trap Types for on-chip peripherals
34 *
35 *  Source: Table 8 - Interrupt Trap Type and Default Priority Assignments
36 *
37 *  NOTE: The priority level for each source corresponds to the least
38 *        significant nibble of the trap type.
39 */
40
41#define LEON_TRAP_TYPE( _source ) SPARC_ASYNCHRONOUS_TRAP((_source) + 0x10)
42
43#define LEON_TRAP_SOURCE( _trap ) ((_trap) - 0x10)
44
45#define LEON_INT_TRAP( _trap ) \
46  ( (_trap) >= 0x11 && \
47    (_trap) <= 0x1F )
48
49typedef struct {
50  volatile unsigned int value;
51  volatile unsigned int reload;
52  volatile unsigned int conf;
53  volatile unsigned int notused;
54} LEON3_Timer_SubType;
55
56typedef struct {
57  volatile unsigned int scaler_value;   /* common timer registers */
58  volatile unsigned int scaler_reload;
59  volatile unsigned int status;
60  volatile unsigned int notused;
61  LEON3_Timer_SubType timer[8];
62} LEON3_Timer_Regs_Map;
63
64typedef struct {
65  volatile unsigned int iodata;
66  volatile unsigned int ioout;
67  volatile unsigned int iodir;
68  volatile unsigned int irqmask;
69  volatile unsigned int irqpol;
70  volatile unsigned int irqedge;
71} LEON3_IOPORT_Regs_Map;
72
73/* /\* */
74/*  *  This is used to manipulate the on-chip registers. */
75/*  * */
76/*  *  The following symbol must be defined in the linkcmds file and point */
77/*  *  to the correct location. */
78/*  *\/ */
79/* Leon uses dynamic register mapping using amba configuration records */
80/* LEON_Register_Map is obsolete */
81/* extern LEON_Register_Map LEON_REG; */
82
83#endif
84
85/*
86 *  The following defines the bits in Memory Configuration Register 1.
87 */
88
89#define LEON_MEMORY_CONFIGURATION_PROM_SIZE_MASK  0x0003C000
90
91/*
92 *  The following defines the bits in Memory Configuration Register 1.
93 */
94
95#define LEON_MEMORY_CONFIGURATION_RAM_SIZE_MASK  0x00001E00
96
97
98/*
99 *  The following defines the bits in the Timer Control Register.
100 */
101
102#define LEON_REG_TIMER_CONTROL_EN    0x00000001  /* 1 = enable counting */
103                                                 /* 0 = hold scalar and counter */
104#define LEON_REG_TIMER_CONTROL_RL    0x00000002  /* 1 = reload at 0 */
105                                                 /* 0 = stop at 0 */
106#define LEON_REG_TIMER_CONTROL_LD    0x00000004  /* 1 = load counter */
107                                                 /* 0 = no function */
108
109/*
110 *  The following defines the bits in the UART Control Registers.
111 *
112 */
113
114#define LEON_REG_UART_CONTROL_RTD  0x000000FF /* RX/TX data */
115
116/*
117 *  The following defines the bits in the LEON UART Status Registers.
118 */
119
120#define LEON_REG_UART_STATUS_DR   0x00000001 /* Data Ready */
121#define LEON_REG_UART_STATUS_TSE  0x00000002 /* TX Send Register Empty */
122#define LEON_REG_UART_STATUS_THE  0x00000004 /* TX Hold Register Empty */
123#define LEON_REG_UART_STATUS_BR   0x00000008 /* Break Error */
124#define LEON_REG_UART_STATUS_OE   0x00000010 /* RX Overrun Error */
125#define LEON_REG_UART_STATUS_PE   0x00000020 /* RX Parity Error */
126#define LEON_REG_UART_STATUS_FE   0x00000040 /* RX Framing Error */
127#define LEON_REG_UART_STATUS_ERR  0x00000078 /* Error Mask */
128
129/*
130 *  The following defines the bits in the LEON UART Status Registers.
131 */
132
133#define LEON_REG_UART_CTRL_RE     0x00000001 /* Receiver enable */
134#define LEON_REG_UART_CTRL_TE     0x00000002 /* Transmitter enable */
135#define LEON_REG_UART_CTRL_RI     0x00000004 /* Receiver interrupt enable */
136#define LEON_REG_UART_CTRL_TI     0x00000008 /* Transmitter interrupt enable */
137#define LEON_REG_UART_CTRL_PS     0x00000010 /* Parity select */
138#define LEON_REG_UART_CTRL_PE     0x00000020 /* Parity enable */
139#define LEON_REG_UART_CTRL_FL     0x00000040 /* Flow control enable */
140#define LEON_REG_UART_CTRL_LB     0x00000080 /* Loop Back enable */
141
142extern volatile LEON3_IrqCtrl_Regs_Map *LEON3_IrqCtrl_Regs;  /* LEON3 Interrupt Controller */
143extern volatile LEON3_Timer_Regs_Map *LEON3_Timer_Regs; /* LEON3 GP Timer */
144
145/* LEON3 CPU Index of boot CPU */
146extern int LEON3_Cpu_Index;
147
148/* The external IRQ number, -1 if not external interrupts */
149extern int LEON3_IrqCtrl_EIrq;
150
151static __inline__ int bsp_irq_fixup(int irq)
152{
153       int eirq;
154
155       if (LEON3_IrqCtrl_EIrq != 0 && irq == LEON3_IrqCtrl_EIrq) {
156               /* Get interrupt number from IRQ controller */
157               eirq = LEON3_IrqCtrl_Regs->intid[LEON3_Cpu_Index] & 0x1f;
158               if (eirq & 0x10)
159                       irq = eirq;
160       }
161
162       return irq;
163}
164
165/* Macros used for manipulating bits in LEON3 GP Timer Control Register */
166
167#define LEON3_GPTIMER_EN 1
168#define LEON3_GPTIMER_RL 2
169#define LEON3_GPTIMER_LD 4
170#define LEON3_GPTIMER_IRQEN 8
171
172#define LEON3_MP_IRQ    14        /* Irq used by shared memory driver */
173
174#define LEON3_IRQMPSTATUS_CPUNR     28
175#define LEON3_IRQMPSTATUS_BROADCAST 27
176
177
178#ifndef ASM
179
180/*
181 *  Macros to manipulate the Interrupt Clear, Interrupt Force, Interrupt Mask,
182 *  and the Interrupt Pending Registers.
183 *
184 *  NOTE: For operations which are not atomic, this code disables interrupts
185 *        to guarantee there are no intervening accesses to the same register.
186 *        The operations which read the register, modify the value and then
187 *        store the result back are vulnerable.
188 */
189
190#define LEON_Clear_interrupt( _source ) \
191  do { \
192    LEON3_IrqCtrl_Regs->iclear = (1 << (_source)); \
193  } while (0)
194
195#define LEON_Force_interrupt( _source ) \
196  do { \
197    LEON3_IrqCtrl_Regs->iforce = (1 << (_source)); \
198  } while (0)
199
200#define LEON_Is_interrupt_pending( _source ) \
201  (LEON3_IrqCtrl_Regs->ipend & (1 << (_source)))
202
203#define LEON_Is_interrupt_masked( _source ) \
204  do {\
205     (LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] & (1 << (_source))); \
206   } while (0)
207
208#define LEON_Mask_interrupt( _source ) \
209  do { \
210    uint32_t _level; \
211    _level = sparc_disable_interrupts(); \
212     LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index]  &= ~(1 << (_source)); \
213    sparc_enable_interrupts( _level ); \
214  } while (0)
215
216#define LEON_Unmask_interrupt( _source ) \
217  do { \
218    uint32_t _level; \
219    _level = sparc_disable_interrupts(); \
220    LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index]  |= (1 << (_source)); \
221    sparc_enable_interrupts( _level ); \
222  } while (0)
223
224#define LEON_Disable_interrupt( _source, _previous ) \
225  do { \
226    uint32_t _level; \
227    uint32_t _mask = 1 << (_source); \
228    _level = sparc_disable_interrupts(); \
229     (_previous) = LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index]; \
230     LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] = _previous & ~_mask; \
231    sparc_enable_interrupts( _level ); \
232    (_previous) &= _mask; \
233  } while (0)
234
235#define LEON_Restore_interrupt( _source, _previous ) \
236  do { \
237    uint32_t _level; \
238    uint32_t _mask = 1 << (_source); \
239    _level = sparc_disable_interrupts(); \
240      LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] = \
241        (LEON3_IrqCtrl_Regs->mask[LEON3_Cpu_Index] & ~_mask) | (_previous); \
242    sparc_enable_interrupts( _level ); \
243  } while (0)
244
245/* Make all SPARC BSPs have common macros for interrupt handling */
246#define BSP_Clear_interrupt(_source) LEON_Clear_interrupt(_source)
247#define BSP_Force_interrupt(_source) LEON_Force_interrupt(_source)
248#define BSP_Is_interrupt_pending(_source) LEON_Is_interrupt_pending(_source)
249#define BSP_Is_interrupt_masked(_source) LEON_Is_interrupt_masked(_source)
250#define BSP_Unmask_interrupt(_source) LEON_Unmask_interrupt(_source)
251#define BSP_Mask_interrupt(_source) LEON_Mask_interrupt(_source)
252#define BSP_Disable_interrupt(_source, _previous) \
253        LEON_Disable_interrupt(_source, _prev)
254#define BSP_Restore_interrupt(_source, _previous) \
255        LEON_Restore_interrupt(_source, _previous)
256
257/*
258 *  Each timer control register is organized as follows:
259 *
260 *    D0 - Enable
261 *          1 = enable counting
262 *          0 = hold scaler and counter
263 *
264 *    D1 - Counter Reload
265 *          1 = reload counter at zero and restart
266 *          0 = stop counter at zero
267 *
268 *    D2 - Counter Load
269 *          1 = load counter with preset value
270 *          0 = no function
271 *
272 */
273
274#define LEON_REG_TIMER_COUNTER_RELOAD_AT_ZERO     0x00000002
275#define LEON_REG_TIMER_COUNTER_STOP_AT_ZERO       0x00000000
276
277#define LEON_REG_TIMER_COUNTER_LOAD_COUNTER       0x00000004
278
279#define LEON_REG_TIMER_COUNTER_ENABLE_COUNTING    0x00000001
280#define LEON_REG_TIMER_COUNTER_DISABLE_COUNTING   0x00000000
281
282#define LEON_REG_TIMER_COUNTER_RELOAD_MASK        0x00000002
283#define LEON_REG_TIMER_COUNTER_ENABLE_MASK        0x00000001
284
285#define LEON_REG_TIMER_COUNTER_DEFINED_MASK       0x00000003
286#define LEON_REG_TIMER_COUNTER_CURRENT_MODE_MASK  0x00000003
287
288/* Load 32-bit word by forcing a cache-miss */
289static inline unsigned int leon_r32_no_cache(uintptr_t addr)
290{
291        unsigned int tmp;
292        asm volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(addr));
293        return tmp;
294}
295
296#endif /* !ASM */
297
298#ifdef __cplusplus
299}
300#endif
301
302#endif /* !_INCLUDE_LEON_h */
303/* end of include file */
304
Note: See TracBrowser for help on using the repository browser.