1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// var_misc.c
|
4 |
|
|
//
|
5 |
|
|
// HAL CPU variant miscellaneous functions
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): nickg
|
44 |
|
|
// Contributors: nickg, jlarmour
|
45 |
|
|
// Date: 1999-01-21
|
46 |
|
|
// Purpose: HAL miscellaneous functions
|
47 |
|
|
// Description: This file contains miscellaneous functions provided by the
|
48 |
|
|
// HAL.
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//========================================================================*/
|
53 |
|
|
|
54 |
|
|
#include <pkgconf/hal.h>
|
55 |
|
|
|
56 |
|
|
#include <cyg/infra/cyg_type.h> // Base types
|
57 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
58 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
59 |
|
|
#include <cyg/hal/var_arch.h>
|
60 |
|
|
#include <cyg/hal/var_intr.h>
|
61 |
|
|
#include <cyg/hal/hal_io.h>
|
62 |
|
|
|
63 |
|
|
/*------------------------------------------------------------------------*/
|
64 |
|
|
/* Variant specific initialization routine. */
|
65 |
|
|
|
66 |
|
|
void hal_variant_init(void)
|
67 |
|
|
{
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
struct int_regs {
|
71 |
|
|
CYG_BYTE *ier;
|
72 |
|
|
CYG_BYTE *isr;
|
73 |
|
|
CYG_BYTE mask;
|
74 |
|
|
CYG_BYTE status;
|
75 |
|
|
};
|
76 |
|
|
|
77 |
|
|
#define REGS_DEF(ier,isr,mask,status) \
|
78 |
|
|
{(CYG_BYTE *)ier,(CYG_BYTE *)isr,mask,status}
|
79 |
|
|
|
80 |
|
|
struct int_regs interrupt_registers[]= {
|
81 |
|
|
REGS_DEF(CYGARC_IER,CYGARC_ISR,0x01,0x01),
|
82 |
|
|
REGS_DEF(CYGARC_IER,CYGARC_ISR,0x02,0x02),
|
83 |
|
|
REGS_DEF(CYGARC_IER,CYGARC_ISR,0x04,0x04),
|
84 |
|
|
REGS_DEF(CYGARC_IER,CYGARC_ISR,0x08,0x08),
|
85 |
|
|
REGS_DEF(CYGARC_IER,CYGARC_ISR,0x10,0x10),
|
86 |
|
|
REGS_DEF(CYGARC_IER,CYGARC_ISR,0x20,0x20),
|
87 |
|
|
REGS_DEF(CYGARC_IER,CYGARC_ISR,0x40,0x40),
|
88 |
|
|
REGS_DEF(CYGARC_IER,CYGARC_ISR,0x80,0x80),
|
89 |
|
|
REGS_DEF(CYGARC_TCSR,CYGARC_TCSR,0x20,0x80),
|
90 |
|
|
REGS_DEF(CYGARC_RTMCSR,CYGARC_RTMCSR,0x40,0x80),
|
91 |
|
|
REGS_DEF(NULL,NULL,0,0),
|
92 |
|
|
REGS_DEF(CYGARC_ADCSR,CYGARC_ADCSR,0x40,0x80),
|
93 |
|
|
REGS_DEF(CYGARC_TISRA,CYGARC_TISRA,0x10,0x01),
|
94 |
|
|
REGS_DEF(CYGARC_TISRB,CYGARC_TISRB,0x10,0x01),
|
95 |
|
|
REGS_DEF(CYGARC_TISRC,CYGARC_TISRC,0x10,0x01),
|
96 |
|
|
REGS_DEF(NULL,NULL,0,0),
|
97 |
|
|
REGS_DEF(CYGARC_TISRA,CYGARC_TISRA,0x20,0x02),
|
98 |
|
|
REGS_DEF(CYGARC_TISRB,CYGARC_TISRB,0x20,0x02),
|
99 |
|
|
REGS_DEF(CYGARC_TISRC,CYGARC_TISRC,0x20,0x02),
|
100 |
|
|
REGS_DEF(NULL,NULL,0,0),
|
101 |
|
|
REGS_DEF(CYGARC_TISRA,CYGARC_TISRA,0x40,0x04),
|
102 |
|
|
REGS_DEF(CYGARC_TISRB,CYGARC_TISRB,0x40,0x04),
|
103 |
|
|
REGS_DEF(CYGARC_TISRC,CYGARC_TISRC,0x40,0x04),
|
104 |
|
|
REGS_DEF(NULL,NULL,0,0),
|
105 |
|
|
REGS_DEF(CYGARC_8TCR0,CYGARC_8TCSR0,0x40,0x40),
|
106 |
|
|
REGS_DEF(CYGARC_8TCR0,CYGARC_8TCSR0,0x80,0x80),
|
107 |
|
|
REGS_DEF(CYGARC_8TCR1,CYGARC_8TCSR1,0xC0,0xC0),
|
108 |
|
|
REGS_DEF(CYGARC_8TCR0,CYGARC_8TCSR0,0x20,0x20),
|
109 |
|
|
REGS_DEF(CYGARC_8TCR2,CYGARC_8TCSR2,0x40,0x40),
|
110 |
|
|
REGS_DEF(CYGARC_8TCR2,CYGARC_8TCSR2,0x80,0x80),
|
111 |
|
|
REGS_DEF(CYGARC_8TCR3,CYGARC_8TCSR3,0xC0,0xC0),
|
112 |
|
|
REGS_DEF(CYGARC_8TCR2,CYGARC_8TCSR2,0x20,0x20),
|
113 |
|
|
REGS_DEF(CYGARC_DTCR0A,CYGARC_DTCR0A,0x08,0x80),
|
114 |
|
|
REGS_DEF(CYGARC_DTCR0B,CYGARC_DTCR0B,0x08,0x80),
|
115 |
|
|
REGS_DEF(CYGARC_DTCR1A,CYGARC_DTCR1A,0x08,0x80),
|
116 |
|
|
REGS_DEF(CYGARC_DTCR1B,CYGARC_DTCR1B,0x08,0x80),
|
117 |
|
|
REGS_DEF(NULL,NULL,0,0),
|
118 |
|
|
REGS_DEF(NULL,NULL,0,0),
|
119 |
|
|
REGS_DEF(NULL,NULL,0,0),
|
120 |
|
|
REGS_DEF(NULL,NULL,0,0),
|
121 |
|
|
REGS_DEF(CYGARC_SCR0,CYGARC_SSR0,0x40,0x30),
|
122 |
|
|
REGS_DEF(CYGARC_SCR0,CYGARC_SSR0,0x40,0x40),
|
123 |
|
|
REGS_DEF(CYGARC_SCR0,CYGARC_SSR0,0x80,0x80),
|
124 |
|
|
REGS_DEF(CYGARC_SCR0,CYGARC_SSR0,0x04,0x04),
|
125 |
|
|
REGS_DEF(CYGARC_SCR1,CYGARC_SSR1,0x40,0x30),
|
126 |
|
|
REGS_DEF(CYGARC_SCR1,CYGARC_SSR1,0x40,0x40),
|
127 |
|
|
REGS_DEF(CYGARC_SCR1,CYGARC_SSR1,0x80,0x80),
|
128 |
|
|
REGS_DEF(CYGARC_SCR1,CYGARC_SSR1,0x04,0x04),
|
129 |
|
|
REGS_DEF(CYGARC_SCR2,CYGARC_SSR2,0x40,0x30),
|
130 |
|
|
REGS_DEF(CYGARC_SCR2,CYGARC_SSR2,0x40,0x40),
|
131 |
|
|
REGS_DEF(CYGARC_SCR2,CYGARC_SSR2,0x80,0x80),
|
132 |
|
|
REGS_DEF(CYGARC_SCR2,CYGARC_SSR2,0x04,0x04)
|
133 |
|
|
};
|
134 |
|
|
|
135 |
|
|
void
|
136 |
|
|
hal_interrupt_mask(int vector)
|
137 |
|
|
{
|
138 |
|
|
CYG_BYTE ier;
|
139 |
|
|
struct int_regs *regs=&interrupt_registers[vector-12];
|
140 |
|
|
if (vector == CYGNUM_HAL_INTERRUPT_WDT) {
|
141 |
|
|
HAL_READ_UINT8(CYGARC_TCSR,ier);
|
142 |
|
|
ier &= ~0x20;
|
143 |
|
|
HAL_WRITE_UINT16(CYGARC_TCSR,0xa500 | ier);
|
144 |
|
|
} else {
|
145 |
|
|
if ((vector > 12) && regs->ier) {
|
146 |
|
|
HAL_READ_UINT8(regs->ier,ier);
|
147 |
|
|
ier &= ~(regs->mask);
|
148 |
|
|
HAL_WRITE_UINT8(regs->ier,ier);
|
149 |
|
|
} else {
|
150 |
|
|
CYG_FAIL("Unknown interrupt vector");
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
void
|
156 |
|
|
hal_interrupt_unmask(int vector)
|
157 |
|
|
{
|
158 |
|
|
CYG_BYTE ier;
|
159 |
|
|
struct int_regs *regs=&interrupt_registers[vector-12];
|
160 |
|
|
if (vector == CYGNUM_HAL_INTERRUPT_WDT) {
|
161 |
|
|
HAL_READ_UINT8(CYGARC_TCSR,ier);
|
162 |
|
|
ier |= 0x20;
|
163 |
|
|
HAL_WRITE_UINT16(CYGARC_TCSR,0xa500 | ier);
|
164 |
|
|
} else {
|
165 |
|
|
if ((vector > 12) && regs->ier) {
|
166 |
|
|
HAL_READ_UINT8(regs->ier,ier);
|
167 |
|
|
ier |= regs->mask;
|
168 |
|
|
HAL_WRITE_UINT8(regs->ier,ier);
|
169 |
|
|
} else {
|
170 |
|
|
CYG_FAIL("Unknown interrupt vector");
|
171 |
|
|
}
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
void
|
176 |
|
|
hal_interrupt_acknowledge(int vector)
|
177 |
|
|
{
|
178 |
|
|
CYG_BYTE isr;
|
179 |
|
|
struct int_regs *regs=&interrupt_registers[vector-12];
|
180 |
|
|
if (vector >= CYGNUM_HAL_INTERRUPT_DEND0A &&
|
181 |
|
|
vector <= CYGNUM_HAL_INTERRUPT_DEND1B)
|
182 |
|
|
return;
|
183 |
|
|
if (vector == CYGNUM_HAL_INTERRUPT_WDT) {
|
184 |
|
|
HAL_READ_UINT8(CYGARC_TCSR,isr);
|
185 |
|
|
isr &= ~0x80;
|
186 |
|
|
HAL_WRITE_UINT16(CYGARC_TCSR,0xa500 | isr);
|
187 |
|
|
} else {
|
188 |
|
|
if ((vector > 12) && regs->isr) {
|
189 |
|
|
HAL_READ_UINT8(regs->isr,isr);
|
190 |
|
|
isr &= ~(regs->status);
|
191 |
|
|
HAL_WRITE_UINT8(regs->isr,isr);
|
192 |
|
|
} else {
|
193 |
|
|
CYG_FAIL("Unknown interrupt vector");
|
194 |
|
|
}
|
195 |
|
|
}
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
const short priority_table[]={
|
199 |
|
|
7, 6, 5, 5, 4, 4,-1,-1,
|
200 |
|
|
3, 3,-1, 3, 2, 2, 2, 2,
|
201 |
|
|
1, 1, 1, 1, 0, 0, 0, 0,
|
202 |
|
|
15,15,15,15,14,14,14,14,
|
203 |
|
|
13,13,13,13,-1,-1,-1,-1,
|
204 |
|
|
11,11,11,11,10,10,10,10,
|
205 |
|
|
9,9,9,9
|
206 |
|
|
};
|
207 |
|
|
|
208 |
|
|
void
|
209 |
|
|
hal_interrupt_set_level(int vector,int level)
|
210 |
|
|
{
|
211 |
|
|
CYG_BYTE *ipr;
|
212 |
|
|
CYG_BYTE ipr_mask;
|
213 |
|
|
int priority = priority_table[vector-12];
|
214 |
|
|
ipr = (CYG_BYTE *)CYGARC_IPRA + ((priority & 0xf8) >> 3);
|
215 |
|
|
if (priority>=0) {
|
216 |
|
|
ipr_mask = 1 << (priority & 0x07);
|
217 |
|
|
if (level == 0) {
|
218 |
|
|
*ipr &= ~ipr_mask;
|
219 |
|
|
} else {
|
220 |
|
|
*ipr |= ipr_mask;
|
221 |
|
|
}
|
222 |
|
|
} else {
|
223 |
|
|
CYG_FAIL("Unknown interrupt vector");
|
224 |
|
|
}
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
void
|
228 |
|
|
hal_interrupt_configure(int vector,int level,int up)
|
229 |
|
|
{
|
230 |
|
|
cyg_uint8 iscr,mask;
|
231 |
|
|
if (vector >= CYGNUM_HAL_INTERRUPT_EXTERNAL_0 &&
|
232 |
|
|
vector <= CYGNUM_HAL_INTERRUPT_EXTERNAL_7) {
|
233 |
|
|
mask = 1 << (vector - CYGNUM_HAL_INTERRUPT_EXTERNAL_0);
|
234 |
|
|
HAL_READ_UINT8(CYGARC_ISCR,iscr);
|
235 |
|
|
if (level) {
|
236 |
|
|
iscr &= ~mask;
|
237 |
|
|
}
|
238 |
|
|
if (up) {
|
239 |
|
|
iscr |= mask;
|
240 |
|
|
}
|
241 |
|
|
CYG_ASSERT(!(up && level), "Cannot trigger on high level!");
|
242 |
|
|
HAL_WRITE_UINT8(CYGARC_ISCR,iscr);
|
243 |
|
|
} else {
|
244 |
|
|
CYG_FAIL("Unhandled interrupt vector");
|
245 |
|
|
}
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
/*------------------------------------------------------------------------*/
|
249 |
|
|
/* End of var_misc.c */
|