RTEMS  5.1
irq-generic.h
Go to the documentation of this file.
1 
9 /*
10  * Based on concepts of Pavel Pisa, Till Straumann and Eric Valette.
11  *
12  * Copyright (c) 2008, 2017 embedded brains GmbH.
13  *
14  * embedded brains GmbH
15  * Dornierstr. 4
16  * 82178 Puchheim
17  * Germany
18  * <rtems@embedded-brains.de>
19  *
20  * Copyright (c) 2016 Chris Johns <chrisj@rtems.org>
21  *
22  * The license and distribution terms for this file may be
23  * found in the file LICENSE in this distribution or at
24  * http://www.rtems.org/license/LICENSE.
25  */
26 
27 #ifndef LIBBSP_SHARED_IRQ_GENERIC_H
28 #define LIBBSP_SHARED_IRQ_GENERIC_H
29 
30 #include <stdbool.h>
31 
32 #include <rtems/irq-extension.h>
33 #include <rtems/score/assert.h>
34 
35 #ifdef RTEMS_SMP
36  #include <rtems/score/atomic.h>
37 #endif
38 
39 #include <bsp/irq.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44 
45 #if !defined(BSP_INTERRUPT_VECTOR_MIN) || !defined(BSP_INTERRUPT_VECTOR_MAX) || (BSP_INTERRUPT_VECTOR_MAX + 1) < BSP_INTERRUPT_VECTOR_MIN
46  #error "invalid BSP_INTERRUPT_VECTOR_MIN or BSP_INTERRUPT_VECTOR_MAX"
47 #endif
48 
49 #if defined(BSP_INTERRUPT_USE_INDEX_TABLE) && !defined(BSP_INTERRUPT_HANDLER_TABLE_SIZE)
50  #error "if you define BSP_INTERRUPT_USE_INDEX_TABLE, you have to define BSP_INTERRUPT_HANDLER_TABLE_SIZE etc. as well"
51 #endif
52 
53 #if defined(BSP_INTERRUPT_NO_HEAP_USAGE) && !defined(BSP_INTERRUPT_USE_INDEX_TABLE)
54  #error "if you define BSP_INTERRUPT_NO_HEAP_USAGE, you have to define BSP_INTERRUPT_USE_INDEX_TABLE etc. as well"
55 #endif
56 
57 #define BSP_INTERRUPT_VECTOR_NUMBER \
58  (BSP_INTERRUPT_VECTOR_MAX - BSP_INTERRUPT_VECTOR_MIN + 1)
59 
60 #ifndef BSP_INTERRUPT_HANDLER_TABLE_SIZE
61  #define BSP_INTERRUPT_HANDLER_TABLE_SIZE BSP_INTERRUPT_VECTOR_NUMBER
62 #endif
63 
64 /* Internal macros for SMP support, do not use externally */
65 #ifdef RTEMS_SMP
66  #define bsp_interrupt_disable(level) do { (void) level; } while (0)
67  #define bsp_interrupt_enable(level) do { } while (0)
68  #define bsp_interrupt_fence(order) _Atomic_Fence(order)
69 #else
70  #define bsp_interrupt_disable(level) rtems_interrupt_disable(level)
71  #define bsp_interrupt_enable(level) rtems_interrupt_enable(level)
72  #define bsp_interrupt_fence(order) do { } while (0)
73 #endif
74 
75 #define bsp_interrupt_assert(e) _Assert(e)
76 
79  void *arg;
80  const char *info;
81  struct bsp_interrupt_handler_entry *next;
82 };
83 
85 
86 extern bsp_interrupt_handler_entry bsp_interrupt_handler_table [];
87 
88 #ifdef BSP_INTERRUPT_USE_INDEX_TABLE
89  #if BSP_INTERRUPT_HANDLER_TABLE_SIZE < 0x100
90  typedef uint8_t bsp_interrupt_handler_index_type;
91  #elif BSP_INTERRUPT_HANDLER_TABLE_SIZE < 0x10000
92  typedef uint16_t bsp_interrupt_handler_index_type;
93  #else
94  typedef uint32_t bsp_interrupt_handler_index_type;
95  #endif
96  extern bsp_interrupt_handler_index_type bsp_interrupt_handler_index_table [];
97 #endif
98 
99 static inline rtems_vector_number bsp_interrupt_handler_index(
100  rtems_vector_number vector
101 )
102 {
103  #ifdef BSP_INTERRUPT_USE_INDEX_TABLE
104  return bsp_interrupt_handler_index_table [vector - BSP_INTERRUPT_VECTOR_MIN];
105  #else
106  return vector - BSP_INTERRUPT_VECTOR_MIN;
107  #endif
108 }
109 
160 #ifdef BSP_INTERRUPT_CUSTOM_VALID_VECTOR
161  bool bsp_interrupt_is_valid_vector(rtems_vector_number vector);
162 #else
163 
167  static inline bool bsp_interrupt_is_valid_vector(rtems_vector_number vector)
168  {
169  return (rtems_vector_number) BSP_INTERRUPT_VECTOR_MIN <= vector
170  && vector <= (rtems_vector_number) BSP_INTERRUPT_VECTOR_MAX;
171  }
172 #endif
173 
184 
197 void bsp_interrupt_initialize(void);
198 
215 
231 
248 
259 static inline void bsp_interrupt_handler_dispatch(rtems_vector_number vector)
260 {
261  if (bsp_interrupt_is_valid_vector(vector)) {
263  &bsp_interrupt_handler_table [bsp_interrupt_handler_index(vector)];
264 
265  do {
266  rtems_interrupt_handler handler;
267  void *arg;
268 
269  arg = e->arg;
270  bsp_interrupt_fence(ATOMIC_ORDER_ACQUIRE);
271  handler = e->handler;
272  (*handler)(arg);
273 
274  e = e->next;
275  } while (e != NULL);
276  } else {
278  }
279 }
280 
291 
294 /* For internal use only */
295 void bsp_interrupt_lock(void);
296 
297 /* For internal use only */
298 void bsp_interrupt_unlock(void);
299 
300 #ifdef __cplusplus
301 }
302 #endif /* __cplusplus */
303 
304 #endif /* LIBBSP_SHARED_IRQ_GENERIC_H */
Definition: irq-generic.h:77
Atomic Operations API.
void bsp_interrupt_vector_disable(rtems_vector_number vector)
Disables the interrupt vector with number vector.
Definition: irq.c:110
bool bsp_interrupt_handler_is_empty(rtems_vector_number vector)
Is interrupt handler empty.
Definition: irq-generic.c:549
ISR_Vector_number rtems_vector_number
Control block type used to manage the vectors.
Definition: intr.h:47
Information for the Assert Handler.
rtems_status_code
Classic API Status.
Definition: status.h:43
Header file for the Interrupt Manager Extension.
void bsp_interrupt_handler_default(rtems_vector_number vector)
Default interrupt handler.
Definition: irq.c:160
unsigned e
Definition: tlb.h:223
void(* rtems_interrupt_handler)(void *)
Interrupt handler routine type.
Definition: irq-extension.h:79
void bsp_interrupt_initialize(void)
Initialize BSP interrupt support.
Definition: irq-generic.c:161
rtems_status_code bsp_interrupt_facility_initialize(void)
BSP specific initialization.
Definition: irq.c:122
void bsp_interrupt_vector_enable(rtems_vector_number vector)
Enables the interrupt vector with number vector.
Definition: irq.c:98
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77