1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup bsp_interrupt |
---|
5 | * |
---|
6 | * @brief Generic BSP interrupt support API. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Based on concepts of Pavel Pisa, Till Straumann and Eric Valette. |
---|
11 | * |
---|
12 | * Copyright (c) 2008, 2009 |
---|
13 | * embedded brains GmbH |
---|
14 | * Obere Lagerstr. 30 |
---|
15 | * D-82178 Puchheim |
---|
16 | * Germany |
---|
17 | * <rtems@embedded-brains.de> |
---|
18 | * |
---|
19 | * The license and distribution terms for this file may be |
---|
20 | * found in the file LICENSE in this distribution or at |
---|
21 | * http://www.rtems.com/license/LICENSE. |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef LIBBSP_SHARED_IRQ_GENERIC_H |
---|
25 | #define LIBBSP_SHARED_IRQ_GENERIC_H |
---|
26 | |
---|
27 | #include <stdbool.h> |
---|
28 | |
---|
29 | #include <rtems/irq-extension.h> |
---|
30 | |
---|
31 | #include <bsp/irq-config.h> |
---|
32 | |
---|
33 | #ifdef __cplusplus |
---|
34 | extern "C" { |
---|
35 | #endif /* __cplusplus */ |
---|
36 | |
---|
37 | #if !defined(BSP_INTERRUPT_VECTOR_MIN) || !defined(BSP_INTERRUPT_VECTOR_MAX) || (BSP_INTERRUPT_VECTOR_MAX + 1) < BSP_INTERRUPT_VECTOR_MIN |
---|
38 | #error "invalid BSP_INTERRUPT_VECTOR_MIN or BSP_INTERRUPT_VECTOR_MAX" |
---|
39 | #endif |
---|
40 | |
---|
41 | #if defined(BSP_INTERRUPT_USE_INDEX_TABLE) && !defined(BSP_INTERRUPT_HANDLER_TABLE_SIZE) |
---|
42 | #error "if you define BSP_INTERRUPT_USE_INDEX_TABLE, you have to define BSP_INTERRUPT_HANDLER_TABLE_SIZE etc. as well" |
---|
43 | #endif |
---|
44 | |
---|
45 | #if defined(BSP_INTERRUPT_NO_HEAP_USAGE) && !defined(BSP_INTERRUPT_USE_INDEX_TABLE) |
---|
46 | #error "if you define BSP_INTERRUPT_NO_HEAP_USAGE, you have to define BSP_INTERRUPT_USE_INDEX_TABLE etc. as well" |
---|
47 | #endif |
---|
48 | |
---|
49 | #define BSP_INTERRUPT_VECTOR_NUMBER \ |
---|
50 | (BSP_INTERRUPT_VECTOR_MAX - BSP_INTERRUPT_VECTOR_MIN + 1) |
---|
51 | |
---|
52 | #ifndef BSP_INTERRUPT_HANDLER_TABLE_SIZE |
---|
53 | #define BSP_INTERRUPT_HANDLER_TABLE_SIZE BSP_INTERRUPT_VECTOR_NUMBER |
---|
54 | #endif |
---|
55 | |
---|
56 | struct bsp_interrupt_handler_entry { |
---|
57 | rtems_interrupt_handler handler; |
---|
58 | void *arg; |
---|
59 | const char *info; |
---|
60 | struct bsp_interrupt_handler_entry *next; |
---|
61 | }; |
---|
62 | |
---|
63 | typedef struct bsp_interrupt_handler_entry bsp_interrupt_handler_entry; |
---|
64 | |
---|
65 | extern bsp_interrupt_handler_entry bsp_interrupt_handler_table []; |
---|
66 | |
---|
67 | #ifdef BSP_INTERRUPT_USE_INDEX_TABLE |
---|
68 | extern bsp_interrupt_handler_index_type bsp_interrupt_handler_index_table []; |
---|
69 | #endif |
---|
70 | |
---|
71 | static inline rtems_vector_number bsp_interrupt_handler_index( |
---|
72 | rtems_vector_number vector |
---|
73 | ) |
---|
74 | { |
---|
75 | #ifdef BSP_INTERRUPT_USE_INDEX_TABLE |
---|
76 | return bsp_interrupt_handler_index_table [vector - BSP_INTERRUPT_VECTOR_MIN]; |
---|
77 | #else |
---|
78 | return vector - BSP_INTERRUPT_VECTOR_MIN; |
---|
79 | #endif |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * @defgroup bsp_interrupt BSP Interrupt Support |
---|
84 | * |
---|
85 | * @ingroup rtems_interrupt_extension |
---|
86 | * |
---|
87 | * The BSP interrupt support manages a sequence of interrupt vector numbers |
---|
88 | * ranging from @ref BSP_INTERRUPT_VECTOR_MIN to @ref BSP_INTERRUPT_VECTOR_MAX |
---|
89 | * including the end points. It provides methods to @ref |
---|
90 | * bsp_interrupt_handler_install() "install", @ref |
---|
91 | * bsp_interrupt_handler_remove() "remove" and @ref |
---|
92 | * bsp_interrupt_handler_dispatch() "dispatch" interrupt handlers for each |
---|
93 | * vector number. It implements parts of the RTEMS interrupt manager. |
---|
94 | * |
---|
95 | * The entry points to a list of interrupt handlers are stored in a table |
---|
96 | * (= handler table). |
---|
97 | * |
---|
98 | * You have to configure the BSP interrupt support in the bsp/irq-config.h file |
---|
99 | * for each BSP. For a minimum configuration you have to provide @ref |
---|
100 | * BSP_INTERRUPT_VECTOR_MIN and @ref BSP_INTERRUPT_VECTOR_MAX. |
---|
101 | * |
---|
102 | * For boards with small memory requirements you can define @ref |
---|
103 | * BSP_INTERRUPT_USE_INDEX_TABLE. With an enabled index table the handler |
---|
104 | * table will be accessed via a small index table. You can define the size of |
---|
105 | * the handler table with @ref BSP_INTERRUPT_HANDLER_TABLE_SIZE. You must |
---|
106 | * provide a data type for the index table (@ref |
---|
107 | * bsp_interrupt_handler_index_type). It must be an integer type big enough to |
---|
108 | * index the complete handler table. |
---|
109 | * |
---|
110 | * Normally new list entries are allocated from the heap. You may define @ref |
---|
111 | * BSP_INTERRUPT_NO_HEAP_USAGE, if you do not want to use the heap. For this |
---|
112 | * option you have to define @ref BSP_INTERRUPT_USE_INDEX_TABLE as well. |
---|
113 | * |
---|
114 | * You have to provide some special routines in your BSP (follow the links for |
---|
115 | * the details): |
---|
116 | * - bsp_interrupt_facility_initialize() |
---|
117 | * - bsp_interrupt_vector_enable() |
---|
118 | * - bsp_interrupt_vector_disable() |
---|
119 | * - bsp_interrupt_handler_default() |
---|
120 | * |
---|
121 | * The following now deprecated functions are provided for backward |
---|
122 | * compatibility: |
---|
123 | * - BSP_get_current_rtems_irq_handler() |
---|
124 | * - BSP_install_rtems_irq_handler() |
---|
125 | * - BSP_install_rtems_shared_irq_handler() |
---|
126 | * - BSP_remove_rtems_irq_handler() |
---|
127 | * - BSP_rtems_irq_mngt_set() |
---|
128 | * - BSP_rtems_irq_mngt_get() |
---|
129 | * |
---|
130 | * @{ |
---|
131 | */ |
---|
132 | |
---|
133 | /** |
---|
134 | * @brief Returns true if the interrupt vector with number @a vector is valid. |
---|
135 | */ |
---|
136 | static inline bool bsp_interrupt_is_valid_vector(rtems_vector_number vector) |
---|
137 | { |
---|
138 | return (rtems_vector_number) BSP_INTERRUPT_VECTOR_MIN <= vector |
---|
139 | && vector <= (rtems_vector_number) BSP_INTERRUPT_VECTOR_MAX; |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * @brief Default interrupt handler. |
---|
144 | * |
---|
145 | * This routine will be called from bsp_interrupt_handler_dispatch() with the |
---|
146 | * current vector number @a vector when the handler list for this vector is |
---|
147 | * empty or the vector number is out of range. |
---|
148 | * |
---|
149 | * @note This function must cope with arbitrary vector numbers @a vector. |
---|
150 | */ |
---|
151 | void bsp_interrupt_handler_default(rtems_vector_number vector); |
---|
152 | |
---|
153 | /** |
---|
154 | * @brief Initialize BSP interrupt support. |
---|
155 | * |
---|
156 | * You must call this function before you can install, remove and dispatch |
---|
157 | * interrupt handlers. The BSP specific bsp_interrupt_facility_initialize() |
---|
158 | * function will be called after all internals are initialized. Initialization |
---|
159 | * is complete if everything was successful. |
---|
160 | */ |
---|
161 | rtems_status_code bsp_interrupt_initialize(void); |
---|
162 | |
---|
163 | /** |
---|
164 | * @brief BSP specific initialization. |
---|
165 | * |
---|
166 | * This routine will be called form bsp_interrupt_initialize() and shall do the |
---|
167 | * following: |
---|
168 | * - Initialize the facilities that call bsp_interrupt_handler_dispatch(). For |
---|
169 | * example on PowerPC the external exception handler. |
---|
170 | * - Initialize the interrupt controller. You shall set the interrupt |
---|
171 | * controller in a state such that interrupts are disabled for all vectors. |
---|
172 | * The vectors will be enabled with your bsp_interrupt_vector_enable() function |
---|
173 | * and disabled via your bsp_interrupt_vector_disable() function. These |
---|
174 | * functions have to work afterwards. |
---|
175 | * |
---|
176 | * @return On success RTEMS_SUCCESSFUL shall be returned. |
---|
177 | */ |
---|
178 | rtems_status_code bsp_interrupt_facility_initialize(void); |
---|
179 | |
---|
180 | /** |
---|
181 | * @brief Enables the interrupt vector with number @a vector. |
---|
182 | * |
---|
183 | * This function shall enable the vector at the corresponding facility (in most |
---|
184 | * cases the interrupt controller). It will be called then the first handler |
---|
185 | * is installed for the vector in bsp_interrupt_handler_install(). For a |
---|
186 | * vector out of range this function shall do nothing except returning |
---|
187 | * RTEMS_SUCCESSFUL. |
---|
188 | * |
---|
189 | * @note You must not install or remove an interrupt handler in this function. |
---|
190 | * This may result in a deadlock. |
---|
191 | * |
---|
192 | * @return On success RTEMS_SUCCESSFUL shall be returned. |
---|
193 | */ |
---|
194 | rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector); |
---|
195 | |
---|
196 | /** |
---|
197 | * @brief Disables the interrupt vector with number @a vector. |
---|
198 | * |
---|
199 | * This function shall disable the vector at the corresponding facility (in |
---|
200 | * most cases the interrupt controller). It will be called then the last |
---|
201 | * handler is removed for the vector in bsp_interrupt_handler_remove(). For a |
---|
202 | * vector out of range this function shall do nothing except returning |
---|
203 | * RTEMS_SUCCESSFUL. |
---|
204 | * |
---|
205 | * @note You must not install or remove an interrupt handler in this function. |
---|
206 | * This may result in a deadlock. |
---|
207 | * |
---|
208 | * @return On success RTEMS_SUCCESSFUL shall be returned. |
---|
209 | */ |
---|
210 | rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector); |
---|
211 | |
---|
212 | /** |
---|
213 | * @brief Sequencially calls all interrupt handlers for the vector number @a |
---|
214 | * vector. |
---|
215 | * |
---|
216 | * If the vector number is out of range or the handler list is empty |
---|
217 | * bsp_interrupt_handler_default() will be called with argument @a vector. |
---|
218 | * |
---|
219 | * You can call this function within every context which can be disabled via |
---|
220 | * rtems_interrupt_disable(). |
---|
221 | */ |
---|
222 | static inline void bsp_interrupt_handler_dispatch(rtems_vector_number vector) |
---|
223 | { |
---|
224 | if (bsp_interrupt_is_valid_vector(vector)) { |
---|
225 | bsp_interrupt_handler_entry *e = |
---|
226 | &bsp_interrupt_handler_table [bsp_interrupt_handler_index(vector)]; |
---|
227 | |
---|
228 | do { |
---|
229 | (*e->handler)(e->arg); |
---|
230 | e = e->next; |
---|
231 | } while (e != NULL); |
---|
232 | } else { |
---|
233 | bsp_interrupt_handler_default(vector); |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | /** @} */ |
---|
238 | |
---|
239 | #ifdef __cplusplus |
---|
240 | } |
---|
241 | #endif /* __cplusplus */ |
---|
242 | |
---|
243 | #endif /* LIBBSP_SHARED_IRQ_GENERIC_H */ |
---|