1 |
786 |
skrzyp |
#ifndef CYGONCE_HAL_IMP_INTR_H
|
2 |
|
|
#define CYGONCE_HAL_IMP_INTR_H
|
3 |
|
|
|
4 |
|
|
//==========================================================================
|
5 |
|
|
//
|
6 |
|
|
// imp_intr.h
|
7 |
|
|
//
|
8 |
|
|
// TX39 Interrupt and clock support
|
9 |
|
|
//
|
10 |
|
|
//==========================================================================
|
11 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
12 |
|
|
// -------------------------------------------
|
13 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
14 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
15 |
|
|
//
|
16 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
17 |
|
|
// the terms of the GNU General Public License as published by the Free
|
18 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
19 |
|
|
// version.
|
20 |
|
|
//
|
21 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
22 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
23 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
24 |
|
|
// for more details.
|
25 |
|
|
//
|
26 |
|
|
// You should have received a copy of the GNU General Public License
|
27 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
28 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
29 |
|
|
//
|
30 |
|
|
// As a special exception, if other files instantiate templates or use
|
31 |
|
|
// macros or inline functions from this file, or you compile this file
|
32 |
|
|
// and link it with other works to produce a work based on this file,
|
33 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
34 |
|
|
// the GNU General Public License. However the source code for this file
|
35 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
36 |
|
|
// General Public License v2.
|
37 |
|
|
//
|
38 |
|
|
// This exception does not invalidate any other reasons why a work based
|
39 |
|
|
// on this file might be covered by the GNU General Public License.
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//==========================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): nickg
|
46 |
|
|
// Contributors: nickg, jskov,
|
47 |
|
|
// gthomas, jlarmour
|
48 |
|
|
// Date: 1999-02-16
|
49 |
|
|
// Purpose: TX39 Interrupt support
|
50 |
|
|
// Description: The macros defined here provide the HAL APIs for handling
|
51 |
|
|
// interrupts and the clock for variants of the TX39 MIPS
|
52 |
|
|
// architecture.
|
53 |
|
|
//
|
54 |
|
|
// Usage:
|
55 |
|
|
// #include <cyg/hal/imp_intr.h>
|
56 |
|
|
// ...
|
57 |
|
|
//
|
58 |
|
|
//
|
59 |
|
|
//####DESCRIPTIONEND####
|
60 |
|
|
//
|
61 |
|
|
//==========================================================================
|
62 |
|
|
|
63 |
|
|
#include <pkgconf/hal.h>
|
64 |
|
|
|
65 |
|
|
#include <cyg/infra/cyg_type.h>
|
66 |
|
|
|
67 |
|
|
#include <cyg/hal/plf_intr.h>
|
68 |
|
|
|
69 |
|
|
//--------------------------------------------------------------------------
|
70 |
|
|
// Interrupt vectors.
|
71 |
|
|
|
72 |
|
|
#ifndef CYGHWR_HAL_INTERRUPT_VECTORS_DEFINED
|
73 |
|
|
|
74 |
|
|
// These are decoded via the IP bits of the cause
|
75 |
|
|
// register when an external interrupt is delivered.
|
76 |
|
|
|
77 |
|
|
#define CYGNUM_HAL_INTERRUPT_1 0
|
78 |
|
|
#define CYGNUM_HAL_INTERRUPT_2 1
|
79 |
|
|
#define CYGNUM_HAL_INTERRUPT_3 2
|
80 |
|
|
#define CYGNUM_HAL_INTERRUPT_4 3
|
81 |
|
|
#define CYGNUM_HAL_INTERRUPT_5 4
|
82 |
|
|
#define CYGNUM_HAL_INTERRUPT_6 5
|
83 |
|
|
#define CYGNUM_HAL_INTERRUPT_7 6
|
84 |
|
|
#define CYGNUM_HAL_INTERRUPT_DMAC1_CH3 7
|
85 |
|
|
#define CYGNUM_HAL_INTERRUPT_DMAC1_CH2 8
|
86 |
|
|
#define CYGNUM_HAL_INTERRUPT_DMAC0_CH1 9
|
87 |
|
|
#define CYGNUM_HAL_INTERRUPT_DMAC0_CH0 10
|
88 |
|
|
#define CYGNUM_HAL_INTERRUPT_SIO_0 11
|
89 |
|
|
#define CYGNUM_HAL_INTERRUPT_SIO_1 12
|
90 |
|
|
#define CYGNUM_HAL_INTERRUPT_TMR_0 13
|
91 |
|
|
#define CYGNUM_HAL_INTERRUPT_TMR_1 14
|
92 |
|
|
#define CYGNUM_HAL_INTERRUPT_TMR_2 15
|
93 |
|
|
#define CYGNUM_HAL_INTERRUPT_0 16
|
94 |
|
|
|
95 |
|
|
// Min/Max ISR numbers and how many there are
|
96 |
|
|
#define CYGNUM_HAL_ISR_MIN 0
|
97 |
|
|
#define CYGNUM_HAL_ISR_MAX 16
|
98 |
|
|
#define CYGNUM_HAL_ISR_COUNT 17
|
99 |
|
|
|
100 |
|
|
// The vector used by the Real time clock
|
101 |
|
|
#define CYGNUM_HAL_INTERRUPT_RTC CYGNUM_HAL_INTERRUPT_TMR_0
|
102 |
|
|
|
103 |
|
|
#define CYGHWR_HAL_INTERRUPT_VECTORS_DEFINED
|
104 |
|
|
|
105 |
|
|
#endif
|
106 |
|
|
|
107 |
|
|
//--------------------------------------------------------------------------
|
108 |
|
|
// Interrupt controller access.
|
109 |
|
|
|
110 |
|
|
#ifndef CYGHWR_HAL_INTERRUPT_CONTROLLER_ACCESS_DEFINED
|
111 |
|
|
|
112 |
|
|
#if defined(CYGPKG_HAL_MIPS_TX3904)
|
113 |
|
|
|
114 |
|
|
#define CYG_HAL_MIPS_TX3904_ILR0 0xFFFFC010
|
115 |
|
|
#define CYG_HAL_MIPS_TX3904_CConR 0xFFFFE000
|
116 |
|
|
|
117 |
|
|
// Array which stores the configured priority levels for the configured
|
118 |
|
|
// interrupts.
|
119 |
|
|
externC volatile CYG_BYTE hal_interrupt_level[CYGNUM_HAL_ISR_COUNT];
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
#define HAL_INTERRUPT_MASK( _vector_ ) \
|
123 |
|
|
{ \
|
124 |
|
|
HAL_IO_REGISTER _reg_ = CYG_HAL_MIPS_TX3904_ILR0; \
|
125 |
|
|
CYG_WORD32 _ilr_; \
|
126 |
|
|
_reg_ += (_vector_)&0xC; \
|
127 |
|
|
HAL_READ_UINT32( _reg_, _ilr_ ); \
|
128 |
|
|
_ilr_ &= ~(7 << (((_vector_)&0x3)<<3)); \
|
129 |
|
|
HAL_WRITE_UINT32( _reg_, _ilr_ ); \
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
#define HAL_INTERRUPT_UNMASK( _vector_ ) \
|
133 |
|
|
{ \
|
134 |
|
|
HAL_IO_REGISTER _reg_ = CYG_HAL_MIPS_TX3904_ILR0; \
|
135 |
|
|
CYG_WORD32 _ilr_; \
|
136 |
|
|
_reg_ += (_vector_)&0xC; \
|
137 |
|
|
HAL_READ_UINT32( _reg_, _ilr_ ); \
|
138 |
|
|
_ilr_ |= hal_interrupt_level[_vector_] << (((_vector_)&0x3)<<3); \
|
139 |
|
|
HAL_WRITE_UINT32( _reg_, _ilr_ ); \
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
#define HAL_INTERRUPT_ACKNOWLEDGE( _vector_ ) \
|
143 |
|
|
{ \
|
144 |
|
|
if( _vector_ <= CYGNUM_HAL_INTERRUPT_7 || \
|
145 |
|
|
_vector_ == CYGNUM_HAL_INTERRUPT_0 ) \
|
146 |
|
|
{ \
|
147 |
|
|
cyg_uint32 _v_ = _vector_ + 1; \
|
148 |
|
|
cyg_uint8 _reg_; \
|
149 |
|
|
\
|
150 |
|
|
/* adjust vector to bit offset in CConR */ \
|
151 |
|
|
if( _v_ == CYGNUM_HAL_INTERRUPT_0 + 1 ) _v_ = 0; \
|
152 |
|
|
\
|
153 |
|
|
/* get CConR */ \
|
154 |
|
|
HAL_READ_UINT8( CYG_HAL_MIPS_TX3904_CConR+1, _reg_ ); \
|
155 |
|
|
\
|
156 |
|
|
/* clear old value and set new */ \
|
157 |
|
|
_reg_ &= ~(7 << 5); \
|
158 |
|
|
_reg_ |= _v_ << 5; \
|
159 |
|
|
HAL_WRITE_UINT8( CYG_HAL_MIPS_TX3904_CConR+1, _reg_); \
|
160 |
|
|
} \
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
#define HAL_INTERRUPT_CONFIGURE( _vector_, _level_, _up_ ) \
|
164 |
|
|
{ \
|
165 |
|
|
if( _vector_ <= CYGNUM_HAL_INTERRUPT_7 || \
|
166 |
|
|
_vector_ == CYGNUM_HAL_INTERRUPT_0 ) \
|
167 |
|
|
{ \
|
168 |
|
|
cyg_uint32 _v_ = _vector_ + 1; \
|
169 |
|
|
cyg_uint32 _val_ = 0; \
|
170 |
|
|
cyg_uint16 _reg_; \
|
171 |
|
|
\
|
172 |
|
|
/* adjust vector to bit offset in CConR */ \
|
173 |
|
|
if( _v_ == CYGNUM_HAL_INTERRUPT_0 + 1 ) _v_ = 0; \
|
174 |
|
|
_v_ <<= 1; \
|
175 |
|
|
\
|
176 |
|
|
/* set bits according to requirements */ \
|
177 |
|
|
if( _up_ ) _val_ |= 1; \
|
178 |
|
|
if( !(_level_) ) _val_ |= 2; \
|
179 |
|
|
\
|
180 |
|
|
/* get CConR */ \
|
181 |
|
|
HAL_READ_UINT16( CYG_HAL_MIPS_TX3904_CConR+2, _reg_ ); \
|
182 |
|
|
\
|
183 |
|
|
/* clear old value and set new */ \
|
184 |
|
|
_reg_ &= ~(3 << _v_); \
|
185 |
|
|
_reg_ |= _val_ << _v_; \
|
186 |
|
|
HAL_WRITE_UINT16( CYG_HAL_MIPS_TX3904_CConR+2, _reg_ ); \
|
187 |
|
|
} \
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
#define HAL_INTERRUPT_SET_LEVEL( _vector_, _level_ ) \
|
191 |
|
|
{ \
|
192 |
|
|
HAL_IO_REGISTER _reg_ = CYG_HAL_MIPS_TX3904_ILR0; \
|
193 |
|
|
CYG_WORD32 _ilr_; \
|
194 |
|
|
_reg_ += (_vector_)&0xC; \
|
195 |
|
|
HAL_READ_UINT32( _reg_, _ilr_ ); \
|
196 |
|
|
_ilr_ |= (_level_) << (((_vector_)&0x3)<<3); \
|
197 |
|
|
HAL_WRITE_UINT32( _reg_, _ilr_ ); \
|
198 |
|
|
hal_interrupt_level[_vector_] = _level_; \
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
#define CYGHWR_HAL_INTERRUPT_CONTROLLER_ACCESS_DEFINED
|
202 |
|
|
|
203 |
|
|
#else
|
204 |
|
|
|
205 |
|
|
#error Unspecified TX39 variant
|
206 |
|
|
|
207 |
|
|
#endif
|
208 |
|
|
|
209 |
|
|
#endif
|
210 |
|
|
|
211 |
|
|
//--------------------------------------------------------------------------
|
212 |
|
|
// Clock control
|
213 |
|
|
|
214 |
|
|
#ifndef CYGHWR_HAL_CLOCK_CONTROL_DEFINED
|
215 |
|
|
|
216 |
|
|
#if defined(CYGPKG_HAL_MIPS_TX3904)
|
217 |
|
|
|
218 |
|
|
#define CYG_HAL_MIPS_TX3904_TIMER_BASE 0xFFFFF000
|
219 |
|
|
#define CYG_HAL_MIPS_TX3904_TIMER_CR (CYG_HAL_MIPS_TX3904_TIMER_BASE + 0x00)
|
220 |
|
|
#define CYG_HAL_MIPS_TX3904_TIMER_SR (CYG_HAL_MIPS_TX3904_TIMER_BASE + 0x04)
|
221 |
|
|
#define CYG_HAL_MIPS_TX3904_TIMER_CPR (CYG_HAL_MIPS_TX3904_TIMER_BASE + 0x08)
|
222 |
|
|
#define CYG_HAL_MIPS_TX3904_TIMER_IMR (CYG_HAL_MIPS_TX3904_TIMER_BASE + 0x10)
|
223 |
|
|
#define CYG_HAL_MIPS_TX3904_TIMER_DR (CYG_HAL_MIPS_TX3904_TIMER_BASE + 0x20)
|
224 |
|
|
#define CYG_HAL_MIPS_TX3904_TIMER_RR (CYG_HAL_MIPS_TX3904_TIMER_BASE + 0xF0)
|
225 |
|
|
|
226 |
|
|
#define HAL_CLOCK_INITIALIZE( _period_ ) \
|
227 |
|
|
{ \
|
228 |
|
|
HAL_WRITE_UINT32( CYG_HAL_MIPS_TX3904_TIMER_DR, 0x00000003 ); \
|
229 |
|
|
HAL_WRITE_UINT32( CYG_HAL_MIPS_TX3904_TIMER_CPR, _period_ ); \
|
230 |
|
|
HAL_WRITE_UINT32( CYG_HAL_MIPS_TX3904_TIMER_SR, 0x00000000 ); \
|
231 |
|
|
HAL_WRITE_UINT32( CYG_HAL_MIPS_TX3904_TIMER_IMR, 0x00008001 ); \
|
232 |
|
|
HAL_WRITE_UINT32( CYG_HAL_MIPS_TX3904_TIMER_CR, 0x000000C0 ); \
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
#define HAL_CLOCK_RESET( _vector_, _period_ ) \
|
236 |
|
|
{ \
|
237 |
|
|
HAL_WRITE_UINT32( CYG_HAL_MIPS_TX3904_TIMER_SR, 0x00000000 ); \
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
#if defined(CYGHWR_HAL_MIPS_TX3904_TRR_REQUIRES_SYNC) && \
|
241 |
|
|
!defined(CYGPKG_HAL_MIPS_SIM)
|
242 |
|
|
|
243 |
|
|
// We need to sync and check the coprocessor 0 condition - this
|
244 |
|
|
// indicates whether data is present in the write buffer. We need to
|
245 |
|
|
// wait until the data to be written is flushed out. This works
|
246 |
|
|
// around a tx39 bug. gcc will insert a NOP after the asm insns.
|
247 |
|
|
|
248 |
|
|
# define HAL_CLOCK_READ( _pvalue_ ) \
|
249 |
|
|
CYG_MACRO_START \
|
250 |
|
|
asm volatile ( \
|
251 |
|
|
"sync; nop; 1: ; bc0f 1b" \
|
252 |
|
|
: \
|
253 |
|
|
: \
|
254 |
|
|
: "$0" \
|
255 |
|
|
); \
|
256 |
|
|
HAL_READ_UINT32( CYG_HAL_MIPS_TX3904_TIMER_RR, *(_pvalue_) ); \
|
257 |
|
|
CYG_MACRO_END
|
258 |
|
|
|
259 |
|
|
#else
|
260 |
|
|
|
261 |
|
|
# define HAL_CLOCK_READ( _pvalue_ ) \
|
262 |
|
|
CYG_MACRO_START \
|
263 |
|
|
HAL_READ_UINT32( CYG_HAL_MIPS_TX3904_TIMER_RR, *(_pvalue_) ); \
|
264 |
|
|
CYG_MACRO_END
|
265 |
|
|
|
266 |
|
|
#endif
|
267 |
|
|
|
268 |
|
|
#if defined(CYGVAR_KERNEL_COUNTERS_CLOCK_LATENCY) && \
|
269 |
|
|
!defined(HAL_CLOCK_LATENCY)
|
270 |
|
|
#define HAL_CLOCK_LATENCY( _pvalue_ ) HAL_CLOCK_READ(_pvalue_)
|
271 |
|
|
#endif
|
272 |
|
|
|
273 |
|
|
#define CYGHWR_HAL_CLOCK_CONTROL_DEFINED
|
274 |
|
|
|
275 |
|
|
#else
|
276 |
|
|
|
277 |
|
|
#error Unspecified TX39 variant
|
278 |
|
|
|
279 |
|
|
#endif
|
280 |
|
|
|
281 |
|
|
#endif
|
282 |
|
|
|
283 |
|
|
//--------------------------------------------------------------------------
|
284 |
|
|
// Timeout exception support. This is TX39 specific.
|
285 |
|
|
|
286 |
|
|
#if defined(CYGPKG_HAL_MIPS_TX3904)
|
287 |
|
|
|
288 |
|
|
#define HAL_TX39_DEBUG_TOE_ENABLE() \
|
289 |
|
|
{ \
|
290 |
|
|
HAL_IO_REGISTER _reg_ = CYG_HAL_MIPS_TX3904_CConR; \
|
291 |
|
|
CYG_WORD32 _cconr_; \
|
292 |
|
|
HAL_READ_UINT32( _reg_, _cconr_); \
|
293 |
|
|
_cconr_ |= 0x04000000; \
|
294 |
|
|
HAL_WRITE_UINT32( _reg_, _cconr_); \
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
#define HAL_TX39_DEBUG_TOE_DISABLE() \
|
298 |
|
|
{ \
|
299 |
|
|
HAL_IO_REGISTER _reg_ = CYG_HAL_MIPS_TX3904_CConR; \
|
300 |
|
|
CYG_WORD32 _cconr_; \
|
301 |
|
|
HAL_READ_UINT32( _reg_, _cconr_); \
|
302 |
|
|
_cconr_ &= 0xFBFFFFFF; \
|
303 |
|
|
HAL_WRITE_UINT32( _reg_, _cconr_); \
|
304 |
|
|
}
|
305 |
|
|
|
306 |
|
|
#else
|
307 |
|
|
|
308 |
|
|
#define HAL_TX39_DEBUG_TOE_ENABLE()
|
309 |
|
|
|
310 |
|
|
#define HAL_TX39_DEBUG_TOE_DISABLE()
|
311 |
|
|
|
312 |
|
|
#endif
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
//--------------------------------------------------------------------------
|
316 |
|
|
#endif // ifndef CYGONCE_HAL_IMP_INTR_H
|
317 |
|
|
// End of imp_intr.h
|