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

4.104.115
Last change on this file since 4a6d160 was 4a6d160, checked in by Joel Sherrill <joel.sherrill@…>, on 05/15/09 at 12:53:44

2009-05-15 Sebastian Huber <sebastian.huber@…>

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