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

4.104.114.95
Last change on this file since 780428f was 780428f, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 07/10/08 at 06:19:03

Extension of the RTEMS Interrupt Manager
(shared handler and handler with a handle).

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