1 #ifndef CYGONCE_HAL_HAL_INTR_H
2 #define CYGONCE_HAL_HAL_INTR_H
3 //==========================================================================
7 // HAL Interrupt and clock support
9 //==========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //==========================================================================
43 //#####DESCRIPTIONBEGIN####
45 // Author(s): yoshinori sato
46 // Contributors: yoshinori sato
48 // Purpose: Define Interrupt support
49 // Description: The macros defined here provide the HAL APIs for handling
50 // interrupts and the clock.
52 // #include <cyg/hal/hal_intr.h>
56 //####DESCRIPTIONEND####
58 //==========================================================================
60 #include <pkgconf/hal.h>
62 #include <cyg/infra/cyg_type.h>
63 #include <cyg/hal/hal_io.h>
65 #include <cyg/hal/var_intr.h>
67 //--------------------------------------------------------------------------
68 // Static data used by HAL
71 externC volatile CYG_ADDRESS hal_interrupt_handlers[CYGNUM_HAL_ISR_COUNT];
72 externC volatile CYG_ADDRWORD hal_interrupt_data[CYGNUM_HAL_ISR_COUNT];
73 externC volatile CYG_ADDRESS hal_interrupt_objects[CYGNUM_HAL_ISR_COUNT];
76 externC volatile CYG_ADDRESS hal_vsr_table[CYGNUM_HAL_VSR_COUNT];
78 //--------------------------------------------------------------------------
80 // The #define is used to test whether this routine exists, and to allow
83 externC cyg_uint32 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data);
85 #define HAL_DEFAULT_ISR hal_default_isr
87 //--------------------------------------------------------------------------
88 // Interrupt state storage
90 typedef cyg_uint32 CYG_INTERRUPT_STATE;
92 //--------------------------------------------------------------------------
94 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
96 // Routine to execute DSRs using separate interrupt stack
97 externC void hal_interrupt_stack_call_pending_DSRs(void);
98 #define HAL_INTERRUPT_STACK_CALL_PENDING_DSRS() \
99 hal_interrupt_stack_call_pending_DSRs()
101 // these are offered solely for stack usage testing
102 // if they are not defined, then there is no interrupt stack.
103 #define HAL_INTERRUPT_STACK_BASE cyg_interrupt_stack_base
104 #define HAL_INTERRUPT_STACK_TOP cyg_interrupt_stack
105 // use them to declare these extern however you want:
106 // extern char HAL_INTERRUPT_STACK_BASE[];
107 // extern char HAL_INTERRUPT_STACK_TOP[];
113 #ifndef HAL_TRANSLATE_VECTOR
115 #define HAL_TRANSLATE_VECTOR(_vector_,_index_) _index_ = (_vector_)
119 //--------------------------------------------------------------------------
120 // Interrupt and VSR attachment macros
122 #define HAL_INTERRUPT_IN_USE( _vector_, _state_) \
124 cyg_uint32 _index_; \
125 HAL_TRANSLATE_VECTOR ((_vector_), _index_); \
127 if( hal_interrupt_handlers[_index_] == (CYG_ADDRESS)HAL_DEFAULT_ISR ) \
133 #define HAL_INTERRUPT_ATTACH( _vector_, _isr_, _data_, _object_ ) \
135 cyg_uint32 _index_; \
136 HAL_TRANSLATE_VECTOR(_vector_,_index_); \
138 if( hal_interrupt_handlers[_index_] == (CYG_ADDRESS)HAL_DEFAULT_ISR ) \
140 hal_interrupt_handlers[_index_] = (CYG_ADDRESS)_isr_; \
141 hal_interrupt_data[_index_] = (CYG_ADDRWORD)_data_; \
142 hal_interrupt_objects[_index_] = (CYG_ADDRESS)_object_; \
146 #define HAL_INTERRUPT_DETACH( _vector_, _isr_ ) \
148 cyg_uint32 _index_; \
149 HAL_TRANSLATE_VECTOR(_vector_,_index_); \
151 if( hal_interrupt_handlers[_index_] == (CYG_ADDRESS)_isr_ ) \
153 hal_interrupt_handlers[_index_] = (CYG_ADDRESS)HAL_DEFAULT_ISR; \
154 hal_interrupt_data[_index_] = 0; \
155 hal_interrupt_objects[_index_] = 0; \
159 #define HAL_VSR_GET( _vector_, _pvsr_ ) \
160 *((CYG_ADDRESS *)_pvsr_) = hal_vsr_table[_vector_];
163 #define HAL_VSR_SET( _vector_, _vsr_, _poldvsr_ ) \
164 if( _poldvsr_ != NULL ) \
165 *(CYG_ADDRESS *)_poldvsr_ = hal_vsr_table[_vector_]; \
166 hal_vsr_table[_vector_] = (CYG_ADDRESS)_vsr_;
169 //--------------------------------------------------------------------------
170 // Interrupt controller access
171 // Read interrupt control registers back after writing to them. This
172 // ensures that the written value is not sitting in the store buffers
173 // when interrupts are re-enabled.
175 #define HAL_INTERRUPT_MASK( _vector_ ) \
176 hal_interrupt_mask( _vector_ )
178 #define HAL_INTERRUPT_UNMASK( _vector_ ) \
179 hal_interrupt_unmask( _vector_ )
181 #define HAL_INTERRUPT_ACKNOWLEDGE( _vector_ ) \
182 hal_interrupt_acknowledge( _vector_ )
184 #if !defined(HAL_INTERRUPT_CONFIGURE)
186 #error HAL_INTERRUPT_CONFIGURE not defined by variant
190 #define HAL_INTERRUPT_SET_LEVEL( _vector_, _level_ ) \
191 hal_interrupt_set_level( _vector_, _level_ )
194 externC void hal_interrupt_mask(int vector);
195 externC void hal_interrupt_unmask(int vector);
196 externC void hal_interrupt_acknowledge(int vector);
197 externC void hal_interrupt_set_level(int vector,int level);
198 //--------------------------------------------------------------------------
200 // This is almost all handled in the var_intr.h.
202 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK_LATENCY
203 #define HAL_CLOCK_LATENCY(_pvalue_) HAL_CLOCK_READ(_pvalue_)
206 //--------------------------------------------------------------------------
207 #endif // ifndef CYGONCE_HAL_HAL_INTR_H