1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup bsp_interrupt |
---|
7 | * |
---|
8 | * @brief This header file provides interfaces of the generic interrupt |
---|
9 | * controller support. |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * Copyright (C) 2016 Chris Johns <chrisj@rtems.org> |
---|
14 | * |
---|
15 | * Copyright (C) 2008, 2021 embedded brains GmbH (http://www.embedded-brains.de) |
---|
16 | * |
---|
17 | * Redistribution and use in source and binary forms, with or without |
---|
18 | * modification, are permitted provided that the following conditions |
---|
19 | * are met: |
---|
20 | * 1. Redistributions of source code must retain the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer. |
---|
22 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
23 | * notice, this list of conditions and the following disclaimer in the |
---|
24 | * documentation and/or other materials provided with the distribution. |
---|
25 | * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
36 | * POSSIBILITY OF SUCH DAMAGE. |
---|
37 | */ |
---|
38 | |
---|
39 | /* |
---|
40 | * The API is based on concepts of Pavel Pisa, Till Straumann and Eric Valette. |
---|
41 | */ |
---|
42 | |
---|
43 | #ifndef LIBBSP_SHARED_IRQ_GENERIC_H |
---|
44 | #define LIBBSP_SHARED_IRQ_GENERIC_H |
---|
45 | |
---|
46 | #include <stdbool.h> |
---|
47 | |
---|
48 | #include <rtems/irq-extension.h> |
---|
49 | #include <rtems/score/assert.h> |
---|
50 | |
---|
51 | #ifdef RTEMS_SMP |
---|
52 | #include <rtems/score/atomic.h> |
---|
53 | #endif |
---|
54 | |
---|
55 | #include <bsp/irq.h> |
---|
56 | |
---|
57 | #ifdef __cplusplus |
---|
58 | extern "C" { |
---|
59 | #endif /* __cplusplus */ |
---|
60 | |
---|
61 | #if !defined(BSP_INTERRUPT_VECTOR_COUNT) |
---|
62 | #error "BSP_INTERRUPT_VECTOR_COUNT shall be defined" |
---|
63 | #endif |
---|
64 | |
---|
65 | #if defined(BSP_INTERRUPT_USE_INDEX_TABLE) && !defined(BSP_INTERRUPT_HANDLER_TABLE_SIZE) |
---|
66 | #error "if you define BSP_INTERRUPT_USE_INDEX_TABLE, you have to define BSP_INTERRUPT_HANDLER_TABLE_SIZE etc. as well" |
---|
67 | #endif |
---|
68 | |
---|
69 | #ifndef BSP_INTERRUPT_HANDLER_TABLE_SIZE |
---|
70 | #define BSP_INTERRUPT_HANDLER_TABLE_SIZE BSP_INTERRUPT_VECTOR_COUNT |
---|
71 | #endif |
---|
72 | |
---|
73 | #define bsp_interrupt_assert(e) _Assert(e) |
---|
74 | |
---|
75 | /** |
---|
76 | * @brief Each member of this table references the first installed entry at the |
---|
77 | * corresponding interrupt vector or is NULL. |
---|
78 | */ |
---|
79 | extern rtems_interrupt_entry *bsp_interrupt_handler_table[]; |
---|
80 | |
---|
81 | #ifdef BSP_INTERRUPT_USE_INDEX_TABLE |
---|
82 | #if BSP_INTERRUPT_HANDLER_TABLE_SIZE < 0x100 |
---|
83 | typedef uint8_t bsp_interrupt_handler_index_type; |
---|
84 | #elif BSP_INTERRUPT_HANDLER_TABLE_SIZE < 0x10000 |
---|
85 | typedef uint16_t bsp_interrupt_handler_index_type; |
---|
86 | #else |
---|
87 | typedef uint32_t bsp_interrupt_handler_index_type; |
---|
88 | #endif |
---|
89 | extern bsp_interrupt_handler_index_type bsp_interrupt_handler_index_table []; |
---|
90 | #endif |
---|
91 | |
---|
92 | static inline rtems_vector_number bsp_interrupt_handler_index( |
---|
93 | rtems_vector_number vector |
---|
94 | ) |
---|
95 | { |
---|
96 | #ifdef BSP_INTERRUPT_USE_INDEX_TABLE |
---|
97 | return bsp_interrupt_handler_index_table [vector]; |
---|
98 | #else |
---|
99 | return vector; |
---|
100 | #endif |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | * @defgroup bsp_interrupt BSP Interrupt Support |
---|
105 | * |
---|
106 | * @ingroup RTEMSBSPsShared |
---|
107 | * |
---|
108 | * @brief Generic BSP Interrupt Support |
---|
109 | * |
---|
110 | * The BSP interrupt support manages a sequence of interrupt vector numbers |
---|
111 | * greater than or equal to zero and less than @ref BSP_INTERRUPT_VECTOR_COUNT |
---|
112 | * It provides methods to |
---|
113 | * @ref bsp_interrupt_handler_install() "install", |
---|
114 | * @ref bsp_interrupt_handler_remove() "remove" and |
---|
115 | * @ref bsp_interrupt_handler_dispatch() "dispatch" interrupt handlers for each |
---|
116 | * vector number. It implements parts of the RTEMS interrupt manager. |
---|
117 | * |
---|
118 | * The entry points to a list of interrupt handlers are stored in a table |
---|
119 | * (= handler table). |
---|
120 | * |
---|
121 | * You have to configure the BSP interrupt support in the <bsp/irq.h> file |
---|
122 | * for each BSP. For a minimum configuration you have to provide |
---|
123 | * @ref BSP_INTERRUPT_VECTOR_COUNT. |
---|
124 | * |
---|
125 | * For boards with small memory requirements you can define |
---|
126 | * @ref BSP_INTERRUPT_USE_INDEX_TABLE. With an enabled index table the handler |
---|
127 | * table will be accessed via a small index table. You can define the size of |
---|
128 | * the handler table with @ref BSP_INTERRUPT_HANDLER_TABLE_SIZE. |
---|
129 | * |
---|
130 | * You have to provide some special routines in your BSP (follow the links for |
---|
131 | * the details): |
---|
132 | * - bsp_interrupt_facility_initialize() |
---|
133 | * - bsp_interrupt_vector_enable() |
---|
134 | * - bsp_interrupt_vector_disable() |
---|
135 | * - bsp_interrupt_handler_default() |
---|
136 | * |
---|
137 | * Optionally, the BSP may define the following macros to customize the vector |
---|
138 | * installation after installing the first entry and the vector removal before |
---|
139 | * removing the last entry: |
---|
140 | * - bsp_interrupt_vector_install() |
---|
141 | * - bsp_interrupt_vector_remove() |
---|
142 | * |
---|
143 | * The following now deprecated functions are provided for backward |
---|
144 | * compatibility: |
---|
145 | * - BSP_get_current_rtems_irq_handler() |
---|
146 | * - BSP_install_rtems_irq_handler() |
---|
147 | * - BSP_install_rtems_shared_irq_handler() |
---|
148 | * - BSP_remove_rtems_irq_handler() |
---|
149 | * - BSP_rtems_irq_mngt_set() |
---|
150 | * - BSP_rtems_irq_mngt_get() |
---|
151 | * |
---|
152 | * @{ |
---|
153 | */ |
---|
154 | |
---|
155 | #ifdef BSP_INTERRUPT_CUSTOM_VALID_VECTOR |
---|
156 | bool bsp_interrupt_is_valid_vector(rtems_vector_number vector); |
---|
157 | #else |
---|
158 | /** |
---|
159 | * @brief Returns true if the interrupt vector with number @a vector is |
---|
160 | * valid. |
---|
161 | */ |
---|
162 | static inline bool bsp_interrupt_is_valid_vector(rtems_vector_number vector) |
---|
163 | { |
---|
164 | return vector < (rtems_vector_number) BSP_INTERRUPT_VECTOR_COUNT; |
---|
165 | } |
---|
166 | #endif |
---|
167 | |
---|
168 | /** |
---|
169 | * @brief Default interrupt handler. |
---|
170 | * |
---|
171 | * This routine will be called from bsp_interrupt_handler_dispatch() with the |
---|
172 | * current vector number @a vector when the handler list for this vector is |
---|
173 | * empty or the vector number is out of range. |
---|
174 | * |
---|
175 | * @note This function must cope with arbitrary vector numbers @a vector. |
---|
176 | */ |
---|
177 | void bsp_interrupt_handler_default(rtems_vector_number vector); |
---|
178 | |
---|
179 | /** |
---|
180 | * @brief Initialize BSP interrupt support. |
---|
181 | * |
---|
182 | * You must call this function before you can install, remove and dispatch |
---|
183 | * interrupt handlers. There is no protection against concurrent |
---|
184 | * initialization. This function must be called at most once. The BSP |
---|
185 | * specific bsp_interrupt_facility_initialize() function will be called after |
---|
186 | * all internals are initialized. If the BSP specific initialization fails, |
---|
187 | * then this is a fatal error. The fatal error source is |
---|
188 | * RTEMS_FATAL_SOURCE_BSP and the fatal error code is |
---|
189 | * BSP_FATAL_INTERRUPT_INITIALIZATION. |
---|
190 | */ |
---|
191 | void bsp_interrupt_initialize(void); |
---|
192 | |
---|
193 | /** |
---|
194 | * @brief BSP specific initialization. |
---|
195 | * |
---|
196 | * This routine will be called form bsp_interrupt_initialize() and shall do the |
---|
197 | * following: |
---|
198 | * - Initialize the facilities that call bsp_interrupt_handler_dispatch(). For |
---|
199 | * example on PowerPC the external exception handler. |
---|
200 | * - Initialize the interrupt controller. You shall set the interrupt |
---|
201 | * controller in a state such that interrupts are disabled for all vectors. |
---|
202 | * The vectors will be enabled with your bsp_interrupt_vector_enable() function |
---|
203 | * and disabled via your bsp_interrupt_vector_disable() function. These |
---|
204 | * functions have to work afterwards. |
---|
205 | * |
---|
206 | * @return On success RTEMS_SUCCESSFUL shall be returned. |
---|
207 | */ |
---|
208 | rtems_status_code bsp_interrupt_facility_initialize(void); |
---|
209 | |
---|
210 | /** |
---|
211 | * @brief Gets the attributes of the interrupt vector. |
---|
212 | * |
---|
213 | * @param vector is the interrupt vector number. It shall be valid. |
---|
214 | * |
---|
215 | * @param[out] attributes is the pointer to an rtems_interrupt_attributes |
---|
216 | * object. When the function call is successful, the attributes of the |
---|
217 | * interrupt vector will be stored in this object. The pointer shall not be |
---|
218 | * NULL. The object shall be cleared to zero by the caller. |
---|
219 | * |
---|
220 | * @retval ::RTEMS_SUCCESSFUL The requested operation was successful. |
---|
221 | */ |
---|
222 | rtems_status_code bsp_interrupt_get_attributes( |
---|
223 | rtems_vector_number vector, |
---|
224 | rtems_interrupt_attributes *attributes |
---|
225 | ); |
---|
226 | |
---|
227 | /** |
---|
228 | * @brief Checks if the interrupt is enabled. |
---|
229 | * |
---|
230 | * The function checks if the interrupt associated with the interrupt vector |
---|
231 | * specified by ``vector`` was enabled for the processor executing the function |
---|
232 | * call at some time point during the call. |
---|
233 | * |
---|
234 | * @param vector is the interrupt vector number. It shall be valid. |
---|
235 | * |
---|
236 | * @param[out] enabled is the pointer to a ``bool`` object. It shall not be |
---|
237 | * ``NULL``. When the function call is successful, the enabled status of |
---|
238 | * the interrupt associated with the interrupt vector specified by ``vector`` |
---|
239 | * will be stored in this object. When the interrupt was enabled for the |
---|
240 | * processor executing the function call at some time point during the call, |
---|
241 | * the object will be set to true, otherwise to false. |
---|
242 | * |
---|
243 | * @retval ::RTEMS_SUCCESSFUL The requested operation was successful. |
---|
244 | */ |
---|
245 | rtems_status_code bsp_interrupt_vector_is_enabled( |
---|
246 | rtems_vector_number vector, |
---|
247 | bool *enabled |
---|
248 | ); |
---|
249 | |
---|
250 | /** |
---|
251 | * @brief Enables the interrupt vector. |
---|
252 | * |
---|
253 | * This function shall enable the vector at the corresponding facility (in most |
---|
254 | * cases the interrupt controller). It will be called then the first handler |
---|
255 | * is installed for the vector in bsp_interrupt_handler_install() for example. |
---|
256 | * |
---|
257 | * @note The implementation should use |
---|
258 | * bsp_interrupt_assert( bsp_interrupt_is_valid_vector( vector ) ) to validate |
---|
259 | * the vector number in ::RTEMS_DEBUG configurations. |
---|
260 | * |
---|
261 | * @param vector is the interrupt vector number. |
---|
262 | * |
---|
263 | * @retval ::RTEMS_SUCCESSFUL The requested operation was successful. |
---|
264 | * |
---|
265 | * @retval ::RTEMS_UNSATISFIED The request to enable the interrupt vector has |
---|
266 | * not been satisfied. |
---|
267 | */ |
---|
268 | rtems_status_code bsp_interrupt_vector_enable( rtems_vector_number vector ); |
---|
269 | |
---|
270 | /** |
---|
271 | * @brief Disables the interrupt vector. |
---|
272 | * |
---|
273 | * This function shall disable the vector at the corresponding facility (in |
---|
274 | * most cases the interrupt controller). It will be called then the last |
---|
275 | * handler is removed for the vector in bsp_interrupt_handler_remove() for |
---|
276 | * example. |
---|
277 | * |
---|
278 | * @note The implementation should use |
---|
279 | * bsp_interrupt_assert( bsp_interrupt_is_valid_vector( vector ) ) to validate |
---|
280 | * the vector number in ::RTEMS_DEBUG configurations. |
---|
281 | * |
---|
282 | * @param vector is the interrupt vector number. |
---|
283 | * |
---|
284 | * @retval ::RTEMS_SUCCESSFUL The requested operation was successful. |
---|
285 | * |
---|
286 | * @retval ::RTEMS_UNSATISFIED The request to disable the interrupt vector has |
---|
287 | * not been satisfied. |
---|
288 | */ |
---|
289 | rtems_status_code bsp_interrupt_vector_disable( rtems_vector_number vector ); |
---|
290 | |
---|
291 | /** |
---|
292 | * @brief Checks if the interrupt is pending. |
---|
293 | * |
---|
294 | * The function checks if the interrupt associated with the interrupt vector |
---|
295 | * specified by ``vector`` was pending for the processor executing the function |
---|
296 | * call at some time point during the call. |
---|
297 | * |
---|
298 | * @param vector is the interrupt vector number. It shall be valid. |
---|
299 | * |
---|
300 | * @param[out] pending is the pointer to a ``bool`` object. It shall not be |
---|
301 | * ``NULL``. When the function call is successful, the pending status of |
---|
302 | * the interrupt associated with the interrupt vector specified by ``vector`` |
---|
303 | * will be stored in this object. When the interrupt was pending for the |
---|
304 | * processor executing the function call at some time point during the call, |
---|
305 | * the object will be set to true, otherwise to false. |
---|
306 | * |
---|
307 | * @retval ::RTEMS_SUCCESSFUL The requested operation was successful. |
---|
308 | * |
---|
309 | * @retval ::RTEMS_UNSATISFIED The request to get the pending status has not |
---|
310 | * been satisfied. |
---|
311 | */ |
---|
312 | rtems_status_code bsp_interrupt_is_pending( |
---|
313 | rtems_vector_number vector, |
---|
314 | bool *pending |
---|
315 | ); |
---|
316 | |
---|
317 | /** |
---|
318 | * @brief Causes the interrupt vector. |
---|
319 | * |
---|
320 | * @param vector is the number of the interrupt vector to cause. It shall be |
---|
321 | * valid. |
---|
322 | * |
---|
323 | * @retval ::RTEMS_SUCCESSFUL The requested operation was successful. |
---|
324 | * |
---|
325 | * @retval ::RTEMS_UNSATISFIED The request to cause the interrupt vector has |
---|
326 | * not been satisfied. |
---|
327 | */ |
---|
328 | rtems_status_code bsp_interrupt_raise( rtems_vector_number vector ); |
---|
329 | |
---|
330 | #if defined(RTEMS_SMP) |
---|
331 | /** |
---|
332 | * @brief Causes the interrupt vector on the processor. |
---|
333 | * |
---|
334 | * @param vector is the number of the interrupt vector to cause. It shall be |
---|
335 | * valid. |
---|
336 | * |
---|
337 | * @param cpu_index is the index of the target processor of the interrupt |
---|
338 | * vector to cause. It shall be valid. |
---|
339 | * |
---|
340 | * @retval ::RTEMS_SUCCESSFUL The requested operation was successful. |
---|
341 | * |
---|
342 | * @retval ::RTEMS_UNSATISFIED The request to cause the interrupt vector has |
---|
343 | * not been satisfied. |
---|
344 | */ |
---|
345 | rtems_status_code bsp_interrupt_raise_on( |
---|
346 | rtems_vector_number vector, |
---|
347 | uint32_t cpu_index |
---|
348 | ); |
---|
349 | #endif |
---|
350 | |
---|
351 | /** |
---|
352 | * @brief Clears the interrupt vector. |
---|
353 | * |
---|
354 | * @param vector is the number of the interrupt vector to clear. It shall be |
---|
355 | * valid. |
---|
356 | * |
---|
357 | * @retval ::RTEMS_SUCCESSFUL The requested operation was successful. |
---|
358 | * |
---|
359 | * @retval ::RTEMS_UNSATISFIED The request to cause the interrupt vector has |
---|
360 | * not been satisfied. |
---|
361 | */ |
---|
362 | rtems_status_code bsp_interrupt_clear( rtems_vector_number vector ); |
---|
363 | |
---|
364 | #if defined(RTEMS_SMP) |
---|
365 | /** |
---|
366 | * @brief Handles a spurious interrupt. |
---|
367 | * |
---|
368 | * @param vector is the vector number. |
---|
369 | */ |
---|
370 | void bsp_interrupt_spurious( rtems_vector_number vector ); |
---|
371 | #endif |
---|
372 | |
---|
373 | /** |
---|
374 | * @brief Loads the interrupt entry with atomic acquire semantic. |
---|
375 | * |
---|
376 | * @param ptr is the pointer to an ::rtems_interrupt_entry pointer. |
---|
377 | * |
---|
378 | * @return Returns the pointer value. |
---|
379 | */ |
---|
380 | static inline rtems_interrupt_entry *bsp_interrupt_entry_load_acquire( |
---|
381 | rtems_interrupt_entry * const *ptr |
---|
382 | ) |
---|
383 | { |
---|
384 | #if defined(RTEMS_SMP) |
---|
385 | return (rtems_interrupt_entry *) _Atomic_Load_uintptr( |
---|
386 | (const Atomic_Uintptr *) ptr, |
---|
387 | ATOMIC_ORDER_ACQUIRE |
---|
388 | ); |
---|
389 | #else |
---|
390 | return *ptr; |
---|
391 | #endif |
---|
392 | } |
---|
393 | |
---|
394 | /** |
---|
395 | * @brief Stores the interrupt entry with atomic release semantic. |
---|
396 | * |
---|
397 | * @param[out] ptr is the pointer to an ::rtems_interrupt_entry pointer. |
---|
398 | * |
---|
399 | * @param value is the pointer value. |
---|
400 | */ |
---|
401 | static inline void bsp_interrupt_entry_store_release( |
---|
402 | rtems_interrupt_entry **ptr, |
---|
403 | rtems_interrupt_entry *value |
---|
404 | ) |
---|
405 | { |
---|
406 | #if defined(RTEMS_SMP) |
---|
407 | _Atomic_Store_uintptr( |
---|
408 | (Atomic_Uintptr *) ptr, |
---|
409 | (Atomic_Uintptr) value, |
---|
410 | ATOMIC_ORDER_RELEASE |
---|
411 | ); |
---|
412 | #else |
---|
413 | rtems_interrupt_level level; |
---|
414 | |
---|
415 | rtems_interrupt_local_disable( level ); |
---|
416 | *ptr = value; |
---|
417 | rtems_interrupt_local_enable( level ); |
---|
418 | #endif |
---|
419 | } |
---|
420 | |
---|
421 | /** |
---|
422 | * @brief Loads the first interrupt entry installed at the interrupt vector. |
---|
423 | * |
---|
424 | * @param vector is the vector number. |
---|
425 | * |
---|
426 | * @return Returns the first entry or NULL. |
---|
427 | */ |
---|
428 | static inline rtems_interrupt_entry *bsp_interrupt_entry_load_first( |
---|
429 | rtems_vector_number vector |
---|
430 | ) |
---|
431 | { |
---|
432 | rtems_vector_number index; |
---|
433 | |
---|
434 | index = bsp_interrupt_handler_index( vector ); |
---|
435 | |
---|
436 | return bsp_interrupt_entry_load_acquire( |
---|
437 | &bsp_interrupt_handler_table[ index ] |
---|
438 | ); |
---|
439 | } |
---|
440 | |
---|
441 | /** |
---|
442 | * @brief Sequentially calls all interrupt handlers of the entry its |
---|
443 | * successors. |
---|
444 | * |
---|
445 | * In uniprocessor configurations, you can call this function within every |
---|
446 | * context which can be disabled via rtems_interrupt_local_disable(). |
---|
447 | * |
---|
448 | * In SMP configurations, you can call this function in every context. |
---|
449 | * |
---|
450 | * @param entry is the first entry. |
---|
451 | */ |
---|
452 | static inline void bsp_interrupt_dispatch_entries( |
---|
453 | const rtems_interrupt_entry *entry |
---|
454 | ) |
---|
455 | { |
---|
456 | do { |
---|
457 | ( *entry->handler )( entry->arg ); |
---|
458 | entry = bsp_interrupt_entry_load_acquire( &entry->next ); |
---|
459 | } while ( RTEMS_PREDICT_FALSE( entry != NULL ) ); |
---|
460 | } |
---|
461 | |
---|
462 | /** |
---|
463 | * @brief Sequentially calls all interrupt handlers installed at the vector. |
---|
464 | * |
---|
465 | * This function does not validate the vector number. If the vector number is |
---|
466 | * out of range, then the behaviour is undefined. |
---|
467 | * |
---|
468 | * In uniprocessor configurations, you can call this function within every |
---|
469 | * context which can be disabled via rtems_interrupt_local_disable(). |
---|
470 | * |
---|
471 | * In SMP configurations, you can call this function in every context. |
---|
472 | * |
---|
473 | * @param vector is the vector number. |
---|
474 | */ |
---|
475 | static inline void bsp_interrupt_handler_dispatch_unchecked( |
---|
476 | rtems_vector_number vector |
---|
477 | ) |
---|
478 | { |
---|
479 | const rtems_interrupt_entry *entry; |
---|
480 | |
---|
481 | entry = bsp_interrupt_entry_load_first( vector ); |
---|
482 | |
---|
483 | if ( RTEMS_PREDICT_TRUE( entry != NULL ) ) { |
---|
484 | bsp_interrupt_dispatch_entries( entry ); |
---|
485 | } else { |
---|
486 | #if defined(RTEMS_SMP) |
---|
487 | bsp_interrupt_spurious( vector ); |
---|
488 | #else |
---|
489 | bsp_interrupt_handler_default( vector ); |
---|
490 | #endif |
---|
491 | } |
---|
492 | } |
---|
493 | |
---|
494 | /** |
---|
495 | * @brief Sequentially calls all interrupt handlers installed at the vector. |
---|
496 | * |
---|
497 | * If the vector number is out of range or the handler list is empty |
---|
498 | * bsp_interrupt_handler_default() will be called with the vector number as |
---|
499 | * argument. |
---|
500 | * |
---|
501 | * In uniprocessor configurations, you can call this function within every |
---|
502 | * context which can be disabled via rtems_interrupt_local_disable(). |
---|
503 | * |
---|
504 | * In SMP configurations, you can call this function in every context. |
---|
505 | * |
---|
506 | * @param vector is the vector number. |
---|
507 | */ |
---|
508 | static inline void bsp_interrupt_handler_dispatch( rtems_vector_number vector ) |
---|
509 | { |
---|
510 | if ( bsp_interrupt_is_valid_vector( vector ) ) { |
---|
511 | bsp_interrupt_handler_dispatch_unchecked( vector ); |
---|
512 | } else { |
---|
513 | bsp_interrupt_handler_default( vector ); |
---|
514 | } |
---|
515 | } |
---|
516 | |
---|
517 | /** @} */ |
---|
518 | |
---|
519 | /** |
---|
520 | * @brief Acquires the interrupt support lock. |
---|
521 | * |
---|
522 | * The interrupt support lock is a mutex. The mutex is only acquired if the |
---|
523 | * system is the ::SYSTEM_STATE_UP state. |
---|
524 | */ |
---|
525 | void bsp_interrupt_lock(void); |
---|
526 | |
---|
527 | /** |
---|
528 | * @brief Releases the interrupt support lock. |
---|
529 | * |
---|
530 | * The mutex is only released if the system is the ::SYSTEM_STATE_UP state. |
---|
531 | */ |
---|
532 | void bsp_interrupt_unlock(void); |
---|
533 | |
---|
534 | /** |
---|
535 | * @brief Checks the vector and routine. When the checks were successful, the |
---|
536 | * interrupt support lock will be obtained. |
---|
537 | * |
---|
538 | * @param vector is the interrupt vector number to check. |
---|
539 | * |
---|
540 | * @param routine is the routine to check. |
---|
541 | * |
---|
542 | * @retval ::RTEMS_SUCCESSFUL The requested operation was successful. |
---|
543 | * |
---|
544 | * @retval ::RTEMS_INCORRECT_STATE The interrupt support was not initialized. |
---|
545 | * |
---|
546 | * @retval ::RTEMS_CALLED_FROM_ISR The function was called from within |
---|
547 | * interrupt context. |
---|
548 | * |
---|
549 | * @retval ::RTEMS_INVALID_ADDRESS The ``routine`` parameter was NULL. |
---|
550 | * |
---|
551 | * @retval ::RTEMS_INVALID_ID There was no interrupt vector associated with the |
---|
552 | * number specified by ``vector``. |
---|
553 | */ |
---|
554 | rtems_status_code bsp_interrupt_check_and_lock( |
---|
555 | rtems_vector_number vector, |
---|
556 | rtems_interrupt_handler handler |
---|
557 | ); |
---|
558 | |
---|
559 | /* For internal use only */ |
---|
560 | rtems_interrupt_entry *bsp_interrupt_entry_find( |
---|
561 | rtems_vector_number vector, |
---|
562 | rtems_interrupt_handler routine, |
---|
563 | void *arg, |
---|
564 | rtems_interrupt_entry ***previous_next |
---|
565 | ); |
---|
566 | |
---|
567 | /* For internal use only */ |
---|
568 | void bsp_interrupt_entry_remove( |
---|
569 | rtems_vector_number vector, |
---|
570 | rtems_interrupt_entry *entry, |
---|
571 | rtems_interrupt_entry **previous_next |
---|
572 | ); |
---|
573 | |
---|
574 | /** |
---|
575 | * @brief This table contains a bit map which indicates if an entry is unique |
---|
576 | * or shared. |
---|
577 | * |
---|
578 | * If the bit associated with a vector is set, then the entry is unique, |
---|
579 | * otherwise it may be shared. If the bit with index |
---|
580 | * #BSP_INTERRUPT_HANDLER_TABLE_SIZE is set, then the interrupt support is |
---|
581 | * initialized, otherwise it is not initialized. |
---|
582 | */ |
---|
583 | extern uint8_t bsp_interrupt_handler_unique_table[]; |
---|
584 | |
---|
585 | /** |
---|
586 | * @brief Checks if the handler entry associated with the hander index is |
---|
587 | * unique. |
---|
588 | * |
---|
589 | * @param index is the handler index to check. |
---|
590 | * |
---|
591 | * @return Returns true, if handler entry associated with the hander index is |
---|
592 | * unique, otherwise false. |
---|
593 | */ |
---|
594 | static inline bool bsp_interrupt_is_handler_unique( rtems_vector_number index ) |
---|
595 | { |
---|
596 | rtems_vector_number table_index; |
---|
597 | uint8_t bit; |
---|
598 | |
---|
599 | table_index = index / 8; |
---|
600 | bit = (uint8_t) ( 1U << ( index % 8 ) ); |
---|
601 | |
---|
602 | return ( bsp_interrupt_handler_unique_table[ table_index ] & bit ) != 0; |
---|
603 | } |
---|
604 | |
---|
605 | /** |
---|
606 | * @brief Sets the unique status of the handler entry. |
---|
607 | * |
---|
608 | * @param index is the handler index. |
---|
609 | * |
---|
610 | * @param unique is the unique status to set. |
---|
611 | */ |
---|
612 | static inline void bsp_interrupt_set_handler_unique( |
---|
613 | rtems_vector_number index, |
---|
614 | bool unique |
---|
615 | ) |
---|
616 | { |
---|
617 | rtems_vector_number table_index; |
---|
618 | uint8_t bit; |
---|
619 | |
---|
620 | table_index = index / 8; |
---|
621 | bit = (uint8_t) ( 1U << ( index % 8 ) ); |
---|
622 | |
---|
623 | if (unique) { |
---|
624 | bsp_interrupt_handler_unique_table[ table_index ] |= bit; |
---|
625 | } else { |
---|
626 | bsp_interrupt_handler_unique_table[ table_index ] &= ~bit; |
---|
627 | } |
---|
628 | } |
---|
629 | |
---|
630 | /** |
---|
631 | * @brief Checks if the interrupt support is initialized. |
---|
632 | * |
---|
633 | * @return Returns true, if the interrupt support is initialized, otherwise |
---|
634 | * false. |
---|
635 | */ |
---|
636 | static inline bool bsp_interrupt_is_initialized( void ) |
---|
637 | { |
---|
638 | return bsp_interrupt_is_handler_unique( BSP_INTERRUPT_HANDLER_TABLE_SIZE ); |
---|
639 | } |
---|
640 | |
---|
641 | #ifdef __cplusplus |
---|
642 | } |
---|
643 | #endif /* __cplusplus */ |
---|
644 | |
---|
645 | #endif /* LIBBSP_SHARED_IRQ_GENERIC_H */ |
---|