source: rtems/c/src/lib/libbsp/shared/include/irq-generic.h @ 296c74e6

4.115
Last change on this file since 296c74e6 was 296c74e6, checked in by Daniel Ramirez <javamonn@…>, on 12/09/13 at 19:37:48

doxygen: refactored doxygen in libbsp to illustrate new rule set

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