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

4.115
Last change on this file since 38c0b112 was 5cc813f, checked in by Sebastian Huber <sebastian.huber@…>, on 03/24/12 at 16:33:22

bsps: Provide optional prototype

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