source: rtems/cpukit/include/rtems/irq-extension.h @ f68401e

4.115
Last change on this file since f68401e was 718124e, checked in by Sebastian Huber <sebastian.huber@…>, on 03/03/14 at 09:18:01

rtems: Add RTEMS_INTERRUPT_REPLACE

A new option RTEMS_INTERRUPT_REPLACE is introduced that permits updating
the first interrupt handler for the registered interrupt vector and
matching argument. If no match is found, the install function fails
with RTEMS_UNSATISFIED.

The Interrupt Manager Extension offers interrupt handlers with an
argument pointer. It is impossible to update two words (handler and
argument) atomically on most architectures. In order to avoid an SMP
lock in bsp_interrupt_handler_dispatch() which would degrade the
interrupt response time an alternative must be provided that makes it
possible to tear-down interrupt sources without an SMP lock.

Add RTEMS_INTERRUPT_REPLACE option to Interrupt Manager Extension. This
enables a clean tear-down of interrupt sources on SMP configurations.
Instead of an interrupt handler removal a replacement handler can be
installed to silence an interrupt source. This can be used in contexts
that allow no sophisticated synchronization (e.g. in atexit() or fatal
handlers).

  • Property mode set to 100644
File size: 9.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_interrupt_extension
5 *
6 * @brief Header file for the Interrupt Manager Extension.
7 */
8
9/*
10 * Based on concepts of Pavel Pisa, Till Straumann and Eric Valette.
11 *
12 * Copyright (c) 2008-2014 embedded brains GmbH.
13 *
14 *  embedded brains GmbH
15 *  Dornierstr. 4
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 RTEMS_IRQ_EXTENSION_H
26#define RTEMS_IRQ_EXTENSION_H
27
28#include <rtems.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif /* __cplusplus */
33
34/**
35 * @defgroup rtems_interrupt_extension Interrupt Manager Extension
36 *
37 * @ingroup ClassicINTR
38 *
39 * In addition to the Classic API interrupt handler with a handle are
40 * supported.  You can also install multiple shared handler for one interrupt
41 * vector.
42 */
43/**@{**/
44
45/**
46 * @brief Makes the interrupt handler unique.  Prevents other handler from
47 * using the same interrupt vector.
48 */
49#define RTEMS_INTERRUPT_UNIQUE ((rtems_option) 0x00000001)
50
51/**
52 * @brief Allows that this interrupt handler may share a common interrupt
53 * vector with other handler.
54 */
55#define RTEMS_INTERRUPT_SHARED ((rtems_option) 0x00000000)
56
57/**
58 * @brief Forces that this interrupt handler replaces the first handler with
59 * the same argument.
60 */
61#define RTEMS_INTERRUPT_REPLACE ((rtems_option) 0x00000002)
62
63/**
64 * @brief Returns true if the interrupt handler unique option is set.
65 */
66#define RTEMS_INTERRUPT_IS_UNIQUE( options) \
67  ((options) & RTEMS_INTERRUPT_UNIQUE)
68
69/**
70 * @brief Returns true if the interrupt handler shared option is set.
71 */
72#define RTEMS_INTERRUPT_IS_SHARED( options) \
73  (!RTEMS_INTERRUPT_IS_UNIQUE( options))
74
75/**
76 * @brief Returns true if the interrupt handler replace option is set.
77 */
78#define RTEMS_INTERRUPT_IS_REPLACE( options) \
79  ((options) & RTEMS_INTERRUPT_REPLACE)
80
81/**
82 * @brief Interrupt handler routine type.
83 */
84typedef void (*rtems_interrupt_handler)(void *);
85
86/**
87 * @brief Installs the interrupt handler routine @a handler for the interrupt
88 * vector with number @a vector.
89 *
90 * You can set one of the mutually exclusive options
91 *
92 * - @ref RTEMS_INTERRUPT_UNIQUE
93 * - @ref RTEMS_INTERRUPT_SHARED
94 * - @ref RTEMS_INTERRUPT_REPLACE
95 *
96 * with the @a options parameter for the interrupt handler.
97 *
98 * The handler routine shall be called with argument @a arg when dispatched.
99 * The order in which the shared interrupt handlers are dispatched for one
100 * vector is BSP dependent.
101 *
102 * If the option @ref RTEMS_INTERRUPT_UNIQUE is set then it shall be ensured
103 * that this handler will be the only one for this vector.
104 *
105 * If the option @ref RTEMS_INTERRUPT_REPLACE is set then it shall be ensured
106 * that this handler will replace the first handler with the same argument for
107 * this vector if it exists, otherwise an error status shall be returned.  A
108 * second handler with the same argument for this vector shall remain
109 * unchanged.  The new handler will inherit the unique or shared option from
110 * the replaced handler.
111 *
112 * You can provide an informative description @a info.  This may be used for
113 * system debugging and status tools.  The string has to be persistent during
114 * the handler life time.
115 *
116 * This function may block.
117 *
118 * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
119 * @retval RTEMS_CALLED_FROM_ISR If this function is called from interrupt
120 * context this shall be returned.
121 * @retval RTEMS_INVALID_ADDRESS If the handler address is NULL this shall be
122 * returned.
123 * @retval RTEMS_INVALID_ID If the vector number is out of range this shall be
124 * returned.
125 * @retval RTEMS_INVALID_NUMBER If an option is not applicable this shall be
126 * returned.
127 * @retval RTEMS_RESOURCE_IN_USE If the vector is already occupied with a
128 * unique handler this shall be returned.  If a unique handler should be
129 * installed and there is already a handler installed this shall be returned.
130 * @retval RTEMS_TOO_MANY If a handler with this argument is already installed
131 * for the vector this shall be returned.
132 * @retval RTEMS_UNSATISFIED If no handler exists to replace with the specified
133 * argument and vector this shall be returned.
134 * @retval RTEMS_IO_ERROR Reserved for board support package specific error
135 * conditions.
136 */
137rtems_status_code rtems_interrupt_handler_install(
138  rtems_vector_number vector,
139  const char *info,
140  rtems_option options,
141  rtems_interrupt_handler handler,
142  void *arg
143);
144
145/**
146 * @brief Removes the interrupt handler routine @a handler with argument @a arg
147 * for the interrupt vector with number @a vector.
148 *
149 * This function may block.
150 *
151 * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
152 * @retval RTEMS_CALLED_FROM_ISR If this function is called from interrupt
153 * context this shall be returned.
154 * @retval RTEMS_INVALID_ADDRESS If the handler address is NULL this shall be
155 * returned.
156 * @retval RTEMS_INVALID_ID If the vector number is out of range this shall be
157 * returned.
158 * @retval RTEMS_UNSATISFIED If the handler with its argument is not installed
159 * for the vector this shall be returned.
160 * @retval RTEMS_IO_ERROR Reserved for board support package specific error
161 * conditions.
162 */
163rtems_status_code rtems_interrupt_handler_remove(
164  rtems_vector_number vector,
165  rtems_interrupt_handler handler,
166  void *arg
167);
168
169/**
170 * @brief Interrupt handler iteration routine type.
171 *
172 * @see rtems_interrupt_handler_iterate()
173 */
174typedef void (*rtems_interrupt_per_handler_routine)(
175  void *, const char *, rtems_option, rtems_interrupt_handler, void *
176);
177
178/**
179 * @brief Iterates over all installed interrupt handler of the interrupt vector
180 * with number @a vector.
181 *
182 * For each installed handler of the vector the function @a routine will be
183 * called with the supplied argument @a arg and the handler information,
184 * options, routine and argument.
185 *
186 * This function is intended for system information and diagnostics.
187 *
188 * This function may block.  Never install or remove an interrupt handler
189 * within the iteration routine.  This may result in a deadlock.
190 *
191 * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
192 * @retval RTEMS_CALLED_FROM_ISR If this function is called from interrupt
193 * context this shall be returned.
194 * @retval RTEMS_INVALID_ID If the vector number is out of range this shall be
195 * returned.
196 * @retval RTEMS_IO_ERROR Reserved for board support package specific error
197 * conditions.
198 */
199rtems_status_code rtems_interrupt_handler_iterate(
200  rtems_vector_number vector,
201  rtems_interrupt_per_handler_routine routine,
202  void *arg
203);
204
205/**
206 * @brief Initializes an interrupt server task.
207 *
208 * The task will have the priority @a priority, the stack size @a stack_size,
209 * the modes @a modes and the attributes @a attributes.  The identifier of the
210 * server task will be returned in @a server.  Interrupt handlers can be
211 * installed on the server with rtems_interrupt_server_handler_install() and
212 * removed with rtems_interrupt_server_handler_remove() using this identifier.
213 * In case of an interrupt the request will be forwarded to the server.  The
214 * handlers are executed within the server context.  If one handler blocks on
215 * something this may delay the processing of other handlers.
216 *
217 * The server identifier pointer @a server may be @a NULL to initialize the
218 * default server.
219 *
220 * This function may block.
221 *
222 * @see rtems_task_create().
223 *
224 * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
225 * @retval RTEMS_INCORRECT_STATE If the default server is already initialized
226 * this shall be returned.
227 * @retval RTEMS_IO_ERROR Reserved for board support package specific error
228 * conditions.
229 */
230rtems_status_code rtems_interrupt_server_initialize(
231  rtems_task_priority priority,
232  size_t stack_size,
233  rtems_mode modes,
234  rtems_attribute attributes,
235  rtems_id *server
236);
237
238/**
239 * @brief Installs the interrupt handler routine @a handler for the interrupt
240 * vector with number @a vector on the server @a server.
241 *
242 * The handler routine will be executed on the corresponding interrupt server
243 * task.  A server identifier @a server of @c RTEMS_ID_NONE may be used to
244 * install the handler on the default server.
245 *
246 * This function may block.
247 *
248 * @see rtems_interrupt_handler_install().
249 *
250 * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
251 * @retval RTEMS_INCORRECT_STATE If the interrupt handler server is not
252 * initialized this shall be returned.
253 * @retval * For other errors see rtems_interrupt_handler_install().
254 */
255rtems_status_code rtems_interrupt_server_handler_install(
256  rtems_id server,
257  rtems_vector_number vector,
258  const char *info,
259  rtems_option options,
260  rtems_interrupt_handler handler,
261  void *arg
262);
263
264/**
265 * @brief Removes the interrupt handler routine @a handler with argument @a arg
266 * for the interrupt vector with number @a vector from the server @a server.
267 *
268 * A server identifier @a server of @c RTEMS_ID_NONE may be used to remove the
269 * handler from the default server.
270 *
271 * This function may block.
272 *
273 * @see rtems_interrupt_handler_remove().
274 *
275 * @retval RTEMS_SUCCESSFUL Shall be returned in case of success.
276 * @retval RTEMS_INCORRECT_STATE If the interrupt handler server is not
277 * initialized this shall be returned.
278 * @retval * For other errors see rtems_interrupt_handler_remove().
279 */
280rtems_status_code rtems_interrupt_server_handler_remove(
281  rtems_id server,
282  rtems_vector_number vector,
283  rtems_interrupt_handler handler,
284  void *arg
285);
286
287/** @} */
288
289#ifdef __cplusplus
290}
291#endif /* __cplusplus */
292
293#endif /* RTEMS_IRQ_EXTENSION_H */
Note: See TracBrowser for help on using the repository browser.