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

4.11
Last change on this file since dd8df59 was dd8df59, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 14, 2012 at 12:59:27 PM

bsps: Interrupt initialization error is fatal

  • 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 rtems_interrupt_extension
94 *
95 * The BSP interrupt support manages a sequence of interrupt vector numbers
96 * ranging from @ref BSP_INTERRUPT_VECTOR_MIN to @ref BSP_INTERRUPT_VECTOR_MAX
97 * including the end points.  It provides methods to
98 * @ref bsp_interrupt_handler_install() "install",
99 * @ref bsp_interrupt_handler_remove() "remove" and
100 * @ref bsp_interrupt_handler_dispatch() "dispatch" interrupt handlers for each
101 * vector number.  It implements parts of the RTEMS interrupt manager.
102 *
103 * The entry points to a list of interrupt handlers are stored in a table
104 * (= handler table).
105 *
106 * You have to configure the BSP interrupt support in the <bsp/irq.h> file
107 * for each BSP.  For a minimum configuration you have to provide
108 * @ref BSP_INTERRUPT_VECTOR_MIN and @ref BSP_INTERRUPT_VECTOR_MAX.
109 *
110 * For boards with small memory requirements you can define
111 * @ref BSP_INTERRUPT_USE_INDEX_TABLE.  With an enabled index table the handler
112 * table will be accessed via a small index table.  You can define the size of
113 * the handler table with @ref BSP_INTERRUPT_HANDLER_TABLE_SIZE.
114 *
115 * Normally new list entries are allocated from the heap.  You may define
116 * @ref BSP_INTERRUPT_NO_HEAP_USAGE, if you do not want to use the heap.  For
117 * this option you have to define @ref BSP_INTERRUPT_USE_INDEX_TABLE as well.
118 *
119 * You have to provide some special routines in your BSP (follow the links for
120 * the details):
121 * - bsp_interrupt_facility_initialize()
122 * - bsp_interrupt_vector_enable()
123 * - bsp_interrupt_vector_disable()
124 * - bsp_interrupt_handler_default()
125 *
126 * The following now deprecated functions are provided for backward
127 * compatibility:
128 * - BSP_get_current_rtems_irq_handler()
129 * - BSP_install_rtems_irq_handler()
130 * - BSP_install_rtems_shared_irq_handler()
131 * - BSP_remove_rtems_irq_handler()
132 * - BSP_rtems_irq_mngt_set()
133 * - BSP_rtems_irq_mngt_get()
134 *
135 * @{
136 */
137
138#ifdef BSP_INTERRUPT_CUSTOM_VALID_VECTOR
139  bool bsp_interrupt_is_valid_vector(rtems_vector_number vector);
140#else
141  /**
142   * @brief Returns true if the interrupt vector with number @a vector is
143   * valid.
144   */
145  static inline bool bsp_interrupt_is_valid_vector(rtems_vector_number vector)
146  {
147    return (rtems_vector_number) BSP_INTERRUPT_VECTOR_MIN <= vector
148      && vector <= (rtems_vector_number) BSP_INTERRUPT_VECTOR_MAX;
149  }
150#endif
151
152/**
153 * @brief Default interrupt handler.
154 *
155 * This routine will be called from bsp_interrupt_handler_dispatch() with the
156 * current vector number @a vector when the handler list for this vector is
157 * empty or the vector number is out of range.
158 *
159 * @note This function must cope with arbitrary vector numbers @a vector.
160 */
161void bsp_interrupt_handler_default(rtems_vector_number vector);
162
163/**
164 * @brief Initialize BSP interrupt support.
165 *
166 * You must call this function before you can install, remove and dispatch
167 * interrupt handlers.  There is no protection against concurrent
168 * initialization.  This function must be called at most once.  The BSP
169 * specific bsp_interrupt_facility_initialize() function will be called after
170 * all internals are initialized.  If the BSP specific initialization fails,
171 * then this is a fatal error.  The fatal error source is
172 * RTEMS_FATAL_SOURCE_BSP_GENERIC and the fatal error code is
173 * BSP_GENERIC_FATAL_INTERRUPT_INITIALIZATION.
174 */
175void bsp_interrupt_initialize(void);
176
177/**
178 * @brief BSP specific initialization.
179 *
180 * This routine will be called form bsp_interrupt_initialize() and shall do the
181 * following:
182 * - Initialize the facilities that call bsp_interrupt_handler_dispatch().  For
183 * example on PowerPC the external exception handler.
184 * - Initialize the interrupt controller.  You shall set the interrupt
185 * controller in a state such that interrupts are disabled for all vectors.
186 * The vectors will be enabled with your bsp_interrupt_vector_enable() function
187 * and disabled via your bsp_interrupt_vector_disable() function.  These
188 * functions have to work afterwards.
189 *
190 * @return On success RTEMS_SUCCESSFUL shall be returned.
191 */
192rtems_status_code bsp_interrupt_facility_initialize(void);
193
194/**
195 * @brief Enables the interrupt vector with number @a vector.
196 *
197 * This function shall enable the vector at the corresponding facility (in most
198 * cases the interrupt controller).  It will be called then the first handler
199 * is installed for the vector in bsp_interrupt_handler_install().  It is
200 * guaranteed that the vector number is within the BSP_INTERRUPT_VECTOR_MIN and
201 * BSP_INTERRUPT_VECTOR_MAX range.
202 *
203 * @note You must not install or remove an interrupt handler in this function.
204 * This may result in a deadlock.
205 *
206 * @return On success RTEMS_SUCCESSFUL shall be returned.
207 */
208rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector);
209
210/**
211 * @brief Disables the interrupt vector with number @a vector.
212 *
213 * This function shall disable the vector at the corresponding facility (in
214 * most cases the interrupt controller).  It will be called then the last
215 * handler is removed for the vector in bsp_interrupt_handler_remove().  It is
216 * guaranteed that the vector number is within the BSP_INTERRUPT_VECTOR_MIN and
217 * BSP_INTERRUPT_VECTOR_MAX range.
218 *
219 * @note You must not install or remove an interrupt handler in this function.
220 * This may result in a deadlock.
221 *
222 * @return On success RTEMS_SUCCESSFUL shall be returned.
223 */
224rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector);
225
226/**
227 * @brief Sequencially calls all interrupt handlers for the vector number @a
228 * vector.
229 *
230 * If the vector number is out of range or the handler list is empty
231 * bsp_interrupt_handler_default() will be called with argument @a vector.
232 *
233 * You can call this function within every context which can be disabled via
234 * rtems_interrupt_disable().
235 */
236static inline void bsp_interrupt_handler_dispatch(rtems_vector_number vector)
237{
238  if (bsp_interrupt_is_valid_vector(vector)) {
239    bsp_interrupt_handler_entry *e =
240      &bsp_interrupt_handler_table [bsp_interrupt_handler_index(vector)];
241
242    do {
243      (*e->handler)(e->arg);
244      e = e->next;
245    } while (e != NULL);
246  } else {
247    bsp_interrupt_handler_default(vector);
248  }
249}
250
251/** @} */
252
253#ifdef __cplusplus
254}
255#endif /* __cplusplus */
256
257#endif /* LIBBSP_SHARED_IRQ_GENERIC_H */
Note: See TracBrowser for help on using the repository browser.