1 |
786 |
skrzyp |
#ifndef CYGONCE_HAL_XPIC_H
|
2 |
|
|
#define CYGONCE_HAL_XPIC_H
|
3 |
|
|
|
4 |
|
|
//=============================================================================
|
5 |
|
|
//
|
6 |
|
|
// hal_xpic.h
|
7 |
|
|
//
|
8 |
|
|
// HAL eXternal Programmable Interrupt Controller 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, gthomas, hmt
|
46 |
|
|
// Contributors: nickg, gthomas, hmt
|
47 |
|
|
// Date: 1999-01-28
|
48 |
|
|
// Purpose: Define Interrupt support
|
49 |
|
|
// Description: The macros defined here provide the HAL APIs for handling
|
50 |
|
|
// an external interrupt controller, and which interrupt is
|
51 |
|
|
// used for what.
|
52 |
|
|
//
|
53 |
|
|
// Usage:
|
54 |
|
|
// #include <cyg/hal/hal_intr.h> // which includes this file
|
55 |
|
|
// ...
|
56 |
|
|
//
|
57 |
|
|
//
|
58 |
|
|
//####DESCRIPTIONEND####
|
59 |
|
|
//
|
60 |
|
|
//=============================================================================
|
61 |
|
|
|
62 |
|
|
#include <cyg/hal/hal_hwio.h> // HAL_SPARC_86940_READ/WRITE
|
63 |
|
|
|
64 |
|
|
//-----------------------------------------------------------------------------
|
65 |
|
|
// Interrupt controller access
|
66 |
|
|
//
|
67 |
|
|
// In the Fuitsu SPARClite Evaluation Boards, when the external IRC (86940)
|
68 |
|
|
// is used (set Switch 1, position 8 (SW1#8)), interrupts are as follows:
|
69 |
|
|
//
|
70 |
|
|
// 15 : NMI Push Switch (SW7)
|
71 |
|
|
// 14 : N_INT# Ethernet LAN Controller (MB86964)
|
72 |
|
|
// 13 : EX_IRQ13 from expansion board, active HIGH
|
73 |
|
|
// 12 : EX_IRQ12 from expansion board, active LOW
|
74 |
|
|
// 11 : EX_IRQ11 from expansion board, active LOW
|
75 |
|
|
// 10 : RRDY0 Serial CH0 receive ready signal
|
76 |
|
|
// 9 : TRDY0 Serial CH0 transmit ready signal
|
77 |
|
|
// 8 : TIMER1 Timer 1 output counter
|
78 |
|
|
// 7 : RRDY1 Serial CH1 receive ready signal
|
79 |
|
|
// 6 : TRDY1 Serial CH1 transmit ready signal
|
80 |
|
|
// 5 : EX_IRQ5 from expansion board, active LOW
|
81 |
|
|
// 4 : EX_IRQ4 from expansion board, active LOW
|
82 |
|
|
// 3 : EX_IRQ3 from expansion board, active HIGH
|
83 |
|
|
// 2 : EX_IRQ2 from expansion board, active LOW
|
84 |
|
|
// 1 : TIMER2 Timer 2 output counter
|
85 |
|
|
|
86 |
|
|
// The vector used by the Real time clock
|
87 |
|
|
|
88 |
|
|
//#define CYG_VECTOR_RTC CYG_VECTOR_INTERRUPT_8
|
89 |
|
|
#define CYGNUM_HAL_INTERRUPT_RTC CYGNUM_HAL_VECTOR_INTERRUPT_8
|
90 |
|
|
|
91 |
|
|
#define HAL_SPARC_86940_REG_IRC_TRGM0 ( 0 * 4 )
|
92 |
|
|
#define HAL_SPARC_86940_REG_IRC_TRGM1 ( 1 * 4 )
|
93 |
|
|
#define HAL_SPARC_86940_REG_IRC_RQSNS ( 2 * 4 )
|
94 |
|
|
#define HAL_SPARC_86940_REG_IRC_RQCLR ( 3 * 4 )
|
95 |
|
|
#define HAL_SPARC_86940_REG_IRC_IMASK ( 4 * 4 )
|
96 |
|
|
#define HAL_SPARC_86940_REG_IRC_CLIRL ( 5 * 4 )
|
97 |
|
|
|
98 |
|
|
#define HAL_SPARC_86940_FLAG_CLIRL_CL (0x10)
|
99 |
|
|
|
100 |
|
|
#define HAL_SPARC_86940_IRC_IMASK_READ( r ) \
|
101 |
|
|
HAL_SPARC_86940_READ( HAL_SPARC_86940_REG_IRC_IMASK, r )
|
102 |
|
|
|
103 |
|
|
#define HAL_SPARC_86940_IRC_IMASK_WRITE( v ) \
|
104 |
|
|
HAL_SPARC_86940_WRITE( HAL_SPARC_86940_REG_IRC_IMASK, v )
|
105 |
|
|
|
106 |
|
|
#define HAL_SPARC_86940_IRC_RQSNS_READ( r ) \
|
107 |
|
|
HAL_SPARC_86940_READ( HAL_SPARC_86940_REG_IRC_RQSNS, r )
|
108 |
|
|
|
109 |
|
|
#define HAL_SPARC_86940_IRC_RQCLR_WRITE( v ) \
|
110 |
|
|
HAL_SPARC_86940_WRITE( HAL_SPARC_86940_REG_IRC_RQCLR, v )
|
111 |
|
|
|
112 |
|
|
#define HAL_SPARC_86940_IRC_CLIRL_READ( r ) \
|
113 |
|
|
HAL_SPARC_86940_READ( HAL_SPARC_86940_REG_IRC_CLIRL, r )
|
114 |
|
|
|
115 |
|
|
#define HAL_SPARC_86940_IRC_CLIRL_WRITE( v ) \
|
116 |
|
|
HAL_SPARC_86940_WRITE( HAL_SPARC_86940_REG_IRC_CLIRL, v )
|
117 |
|
|
|
118 |
|
|
//-----------------------------------------------------------------------------
|
119 |
|
|
|
120 |
|
|
#define HAL_INTERRUPT_MASK( _vector_ ) CYG_MACRO_START \
|
121 |
|
|
cyg_uint32 _traps_, _mask_; \
|
122 |
|
|
HAL_DISABLE_TRAPS( _traps_ ); \
|
123 |
|
|
HAL_SPARC_86940_IRC_IMASK_READ( _mask_ ); \
|
124 |
|
|
_mask_ |= (1 << (_vector_) ); \
|
125 |
|
|
HAL_SPARC_86940_IRC_IMASK_WRITE( _mask_ ); \
|
126 |
|
|
HAL_SPARC_86940_IRC_RQCLR_WRITE( (1 << (_vector_) ) ); \
|
127 |
|
|
HAL_SPARC_86940_IRC_CLIRL_WRITE( HAL_SPARC_86940_FLAG_CLIRL_CL ); \
|
128 |
|
|
HAL_RESTORE_INTERRUPTS( _traps_ ); \
|
129 |
|
|
CYG_MACRO_END
|
130 |
|
|
|
131 |
|
|
#define HAL_INTERRUPT_UNMASK( _vector_ ) CYG_MACRO_START \
|
132 |
|
|
cyg_uint32 _traps_, _mask_; \
|
133 |
|
|
HAL_DISABLE_TRAPS( _traps_ ); \
|
134 |
|
|
HAL_SPARC_86940_IRC_IMASK_READ( _mask_ ); \
|
135 |
|
|
_mask_ &=~ (1 << (_vector_) ); \
|
136 |
|
|
HAL_SPARC_86940_IRC_IMASK_WRITE( _mask_ ); \
|
137 |
|
|
HAL_RESTORE_INTERRUPTS( _traps_ ); \
|
138 |
|
|
CYG_MACRO_END
|
139 |
|
|
|
140 |
|
|
#define HAL_INTERRUPT_ACKNOWLEDGE( _vector_ ) CYG_MACRO_START \
|
141 |
|
|
cyg_uint32 _traps_; \
|
142 |
|
|
cyg_uint32 _req_, _irl_; \
|
143 |
|
|
HAL_DISABLE_TRAPS( _traps_ ); \
|
144 |
|
|
HAL_SPARC_86940_IRC_RQCLR_WRITE( (1 << (_vector_) ) ); \
|
145 |
|
|
do { \
|
146 |
|
|
HAL_SPARC_86940_IRC_CLIRL_WRITE( HAL_SPARC_86940_FLAG_CLIRL_CL ); \
|
147 |
|
|
HAL_SPARC_86940_IRC_RQSNS_READ( _req_ ); \
|
148 |
|
|
HAL_SPARC_86940_IRC_CLIRL_READ( _irl_ ); \
|
149 |
|
|
_req_ &= (1 << (_vector_)); /* if there really is a new intr */ \
|
150 |
|
|
_irl_ &= 0x0f; /* then get out - else poll until */ \
|
151 |
|
|
} while ( (!_req_) && (_irl_ == (_vector_)) ); /* no intr here */ \
|
152 |
|
|
HAL_RESTORE_INTERRUPTS( _traps_ ); \
|
153 |
|
|
CYG_MACRO_END
|
154 |
|
|
|
155 |
|
|
// Set an interrupt source's sensitivity:
|
156 |
|
|
// _level_ != 0 ? level-sensitive : edge-sensitive
|
157 |
|
|
// _up_ != 0 ? high/up : low/down
|
158 |
|
|
// SPARClite's 86940 has values as follows:
|
159 |
|
|
// 0 : high level
|
160 |
|
|
// 1 : low level
|
161 |
|
|
// 2 : rising edge
|
162 |
|
|
// 3 : falling edge
|
163 |
|
|
// TRGM0 controls sources 15-8, TRGM1 sources 7-1.
|
164 |
|
|
|
165 |
|
|
#define HAL_INTERRUPT_CONFIGURE( _vector_, _level_, _up_ ) CYG_MACRO_START \
|
166 |
|
|
int _reg_ = (8 > (_vector_)) ? HAL_SPARC_86940_REG_IRC_TRGM1 \
|
167 |
|
|
: HAL_SPARC_86940_REG_IRC_TRGM0; \
|
168 |
|
|
int _val_, _myvect_ = (_vector_); \
|
169 |
|
|
cyg_uint32 _traps_; \
|
170 |
|
|
HAL_DISABLE_TRAPS( _traps_ ); \
|
171 |
|
|
(_myvect_) &= 7; \
|
172 |
|
|
(_myvect_) <<= 1; \
|
173 |
|
|
HAL_SPARC_86940_READ( _reg_, _val_ ); \
|
174 |
|
|
_val_ &=~ (3 << (_myvect_)); \
|
175 |
|
|
_val_ |= ( ((_level_) ? 0 : 2) + ((_up_) ? 0 : 1) ) << (_myvect_); \
|
176 |
|
|
HAL_SPARC_86940_WRITE( _reg_, _val_ ); \
|
177 |
|
|
HAL_INTERRUPT_ACKNOWLEDGE( _vector_ ); \
|
178 |
|
|
HAL_RESTORE_INTERRUPTS( _traps_ ); \
|
179 |
|
|
CYG_MACRO_END
|
180 |
|
|
|
181 |
|
|
// This is not a standard macro - platform dependent for debugging only:
|
182 |
|
|
// o level, up tell you how this source was configured as above.
|
183 |
|
|
// o hipri returns the number of the highest prio requesting interrupt
|
184 |
|
|
// o mask tells you whether this source is masked off
|
185 |
|
|
// o req tells you whether this source is requesting right now.
|
186 |
|
|
#define HAL_INTERRUPT_QUERY_INFO( _vector_, _level_, _up_, \
|
187 |
|
|
_hipri_, _mask_, _req_ ) CYG_MACRO_START \
|
188 |
|
|
int _reg_ = (8 > (_vector_)) ? HAL_SPARC_86940_REG_IRC_TRGM1 \
|
189 |
|
|
: HAL_SPARC_86940_REG_IRC_TRGM0; \
|
190 |
|
|
int _val_, _myvect_ = (_vector_); \
|
191 |
|
|
HAL_SPARC_86940_IRC_IMASK_READ( _val_ ); \
|
192 |
|
|
_mask_ = (0 != ((1 << (_vector_)) & _val_ )); \
|
193 |
|
|
HAL_SPARC_86940_IRC_RQSNS_READ( _val_ ); \
|
194 |
|
|
_req_ = (0 != ((1 << (_vector_)) & _val_ )); \
|
195 |
|
|
HAL_SPARC_86940_IRC_CLIRL_READ( _hipri_ ); \
|
196 |
|
|
(_myvect_) &= 7; \
|
197 |
|
|
(_myvect_) <<= 1; \
|
198 |
|
|
HAL_SPARC_86940_READ( _reg_, _val_ ); \
|
199 |
|
|
_val_ >>= (_myvect_); \
|
200 |
|
|
(_level_) = !(_val_ & 2); \
|
201 |
|
|
(_up_) = !(_val_ & 1); \
|
202 |
|
|
CYG_MACRO_END
|
203 |
|
|
|
204 |
|
|
// This may set the priority of a vector to a particular level:
|
205 |
|
|
// SPARClite does not support this.
|
206 |
|
|
#define HAL_INTERRUPT_SET_LEVEL( _vector_, _level_ ) /* nothing */
|
207 |
|
|
|
208 |
|
|
//-----------------------------------------------------------------------------
|
209 |
|
|
#endif // ifndef CYGONCE_HAL_XPIC_H
|
210 |
|
|
// End of hal_xpic.h
|