1 #ifndef CYGONCE_HAL_HAL_INTR_H
2 #define CYGONCE_HAL_HAL_INTR_H
4 //==========================================================================
8 // HAL Interrupt and clock support
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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 version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //==========================================================================
44 //#####DESCRIPTIONBEGIN####
47 // Contributors: proven, jskov, pjo, nickg, bartv
49 // Purpose: Define Interrupt support
50 // Description: The macros defined here provide the HAL APIs for handling
51 // interrupts and the clock.
54 // #include <cyg/hal/hal_intr.h>
57 //####DESCRIPTIONEND####
59 //==========================================================================
61 // Interrupt and exception handling in the synthetic target is very much
62 // tied up with POSIX signal handling.
64 // There are two interrupt sources to consider. The system clock is
65 // provided most conveniently by a timer signal SIGALRM. All other
66 // interrupts are handled by communication with the auxiliary program
67 // and involve SIGIO. The model that is actually presented to
68 // higher-level code is a single VSR, and 32 ISRs. ISR 0 is
69 // arbitrarily assigned to the clock. The remaining 31 ISRs correspond
70 // to devices managed through the auxiliary, effectively providing an
71 // interrupt controller. A single VSR suffices because it is passed
72 // the signal number as argument.
74 // Exceptions also correspond to signals, but are not handled through
75 // the same VSR: slightly different processing is needed for
76 // interrupts vs. exceptions, for example the latter does not involve
77 // calling interrupt_end(). The exceptions of interest are SIGILL,
78 // SIGBUS, SIGFPE, and SIGSEGV. SIGBUS and SIGSEGV are treated as a
79 // single exception. Obviously there are other signals but they do not
80 // have obvious meanings in the context of the synthetic target. NOTE:
81 // SIGSTKFLT may be needed as well at some point.
83 #define CYGNUM_HAL_INTERRUPT_RTC 0
84 #define CYGNUM_HAL_ISR_MIN 0
85 #define CYGNUM_HAL_ISR_MAX 31
86 #define CYGNUM_HAL_ISR_COUNT (CYGNUM_HAL_ISR_MAX + 1)
88 #define CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION 0
89 #define CYGNUM_HAL_EXCEPTION_DATA_ACCESS 1
90 #define CYGNUM_HAL_EXCEPTION_FPU 2
92 #define CYGNUM_HAL_EXCEPTION_MIN 0
93 #define CYGNUM_HAL_EXCEPTION_MAX CYGNUM_HAL_EXCEPTION_FPU
94 #define CYGNUM_HAL_EXCEPTION_COUNT (CYGNUM_HAL_EXCEPTION_MAX + 1)
96 #define CYGNUM_HAL_VECTOR_SIGNAL 0
97 #define CYGNUM_HAL_VSR_MIN 0
98 #define CYGNUM_HAL_VSR_MAX CYGNUM_HAL_VECTOR_SIGNAL
99 #define CYGNUM_HAL_VSR_COUNT (CYGNUM_HAL_VSR_MAX + 1)
101 // These #include's cannot happen until after the above are defined.
102 // There are dependencies on e.g. CYGNUM_HAL_EXCEPTION_COUNT.
104 #include <cyg/infra/cyg_type.h>
106 // cyg_vector_t etc., supplied either by the kernel or the common HAL
107 #include <cyg/hal/drv_api.h>
109 // Nearly all interrupt state control happens via functions. This
110 // facilitates debugging, for example it is easier to set breakpoints
111 // that way, at the cost of performance. However performance is not a
112 // critical issue for the synthetic target, Instead it is intended to
113 // facilitate application development, and hence debugability has a
114 // higher priority. There is one exception: the sequence
115 // disable_interrupts() followed by restore_interrupts() occurs
116 // frequently and is worth some inlining.
118 // Note: some of the details such as the existence of a global
119 // variable hal_interrupts_enabled are known to the context switch
120 // code in the variant HAL.
121 typedef cyg_bool_t CYG_INTERRUPT_STATE;
122 externC volatile cyg_bool_t hal_interrupts_enabled;
123 externC void hal_enable_interrupts(void);
124 externC cyg_bool_t hal_interrupt_in_use(cyg_vector_t);
125 externC void hal_interrupt_attach(cyg_vector_t, cyg_ISR_t*, CYG_ADDRWORD, CYG_ADDRESS);
126 externC void hal_interrupt_detach(cyg_vector_t, cyg_ISR_t*);
127 externC void (*hal_vsr_get(cyg_vector_t))(void);
128 externC void hal_vsr_set(cyg_vector_t, void (*)(void), void (**)(void));
129 externC void hal_interrupt_mask(cyg_vector_t);
130 externC void hal_interrupt_unmask(cyg_vector_t);
131 externC void hal_interrupt_acknowledge(cyg_vector_t);
132 externC void hal_interrupt_configure(cyg_vector_t, cyg_bool_t, cyg_bool_t);
133 externC void hal_interrupt_set_level(cyg_vector_t, cyg_priority_t);
136 #define HAL_ENABLE_INTERRUPTS() \
138 hal_enable_interrupts(); \
141 #define HAL_DISABLE_INTERRUPTS(_old_) \
143 _old_ = hal_interrupts_enabled; \
144 hal_interrupts_enabled = false; \
147 #define HAL_RESTORE_INTERRUPTS(_old_) \
150 hal_interrupts_enabled = false; \
151 } else if (!hal_interrupts_enabled) { \
152 hal_enable_interrupts(); \
156 #define HAL_QUERY_INTERRUPTS(_old_) \
158 _old_ = hal_interrupts_enabled; \
161 #define HAL_TRANSLATE_VECTOR(_vector_, _index_) \
163 (_index_) = (_vector_); \
166 #define HAL_INTERRUPT_IN_USE(_vector_, _state_) \
168 (_state_) = hal_interrupt_in_use(_vector_); \
171 #define HAL_INTERRUPT_ATTACH(_vector_, _isr_, _data_, _object_ ) \
173 hal_interrupt_attach(_vector_, _isr_, (CYG_ADDRWORD) _data_, (CYG_ADDRESS) _object_); \
176 #define HAL_INTERRUPT_DETACH(_vector_, _isr_) \
178 hal_interrupt_detach(_vector_, _isr_); \
181 #define HAL_VSR_GET(_vector_, _vsr_) \
183 (*_vsr_) = hal_vsr_get(_vector_); \
186 #define HAL_VSR_SET(_vector_, _vsr_, _poldvsr_) \
188 hal_vsr_set(_vector_, _vsr_, _poldvsr_); \
191 #define HAL_INTERRUPT_MASK(_vector_) \
193 hal_interrupt_mask(_vector_); \
196 #define HAL_INTERRUPT_UNMASK(_vector_) \
198 hal_interrupt_unmask(_vector_); \
201 #define HAL_INTERRUPT_ACKNOWLEDGE(_vector_) \
203 hal_interrupt_acknowledge(_vector_); \
206 #define HAL_INTERRUPT_CONFIGURE(_vector_, _level_, _up_) \
208 hal_interrupt_configure(_vector_, _level_, _up_); \
211 #define HAL_INTERRUPT_SET_LEVEL(_vector_, _level_) \
213 hal_interrupt_set_level(_vector_, _level_); \
216 // Additional data exported by the synthetic target interrupt handling
217 // subsystem. These two variables correspond to typical interrupt
218 // status and mask registers.
219 extern volatile cyg_uint32 synth_pending_isrs;
220 extern volatile cyg_uint32 synth_masked_isrs;
222 // ----------------------------------------------------------------------------
224 externC void hal_clock_initialize(cyg_uint32);
225 externC cyg_uint32 hal_clock_read(void);
227 #define HAL_CLOCK_INITIALIZE( _period_ ) \
229 hal_clock_initialize(_period_); \
232 // No special action is needed for reset.
233 #define HAL_CLOCK_RESET( _vector_, _period_ ) \
236 #define HAL_CLOCK_READ(_pvalue_) \
238 *(_pvalue_) = hal_clock_read(); \
241 // ----------------------------------------------------------------------------
242 // HAL_DELAY_US() support. The macro is provided by the processor-specific
243 // HAL, but the bogomips rating is provided by the architectural code.
244 extern int hal_bogomips;
245 #include <cyg/hal/var_intr.h>
247 // ----------------------------------------------------------------------------
248 // Resetting the Synth target is not possible, but existing the process is.
249 externC void cyg_hal_sys_exit(int);
250 #define HAL_PLATFORM_RESET() \
252 cyg_hal_sys_exit(0); \
255 // ----------------------------------------------------------------------------
256 // Test case exit support.
257 #define CYGHWR_TEST_PROGRAM_EXIT() \
259 cyg_hal_sys_exit(0); \
261 //---------------------------------------------------------------------------
262 #endif // ifndef CYGONCE_HAL_HAL_INTR_H