RTEMS: bsps/include/bsp/irq-generic.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
irq-generic.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2016 Chris Johns <chrisj@rtems.org>
14 *
15 * Copyright (C) 2008, 2017 embedded brains GmbH (http://www.embedded-brains.de)
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39/*
40 * The API is based on concepts of Pavel Pisa, Till Straumann and Eric Valette.
41 */
42
43#ifndef LIBBSP_SHARED_IRQ_GENERIC_H
44#define LIBBSP_SHARED_IRQ_GENERIC_H
45
46#include <stdbool.h>
47
48#include <rtems/irq-extension.h>
49#include <rtems/score/assert.h>
50
51#ifdef RTEMS_SMP
52 #include <rtems/score/atomic.h>
53#endif
54
55#include <bsp/irq.h>
56
57#ifdef __cplusplus
58extern "C" {
59#endif /* __cplusplus */
60
61#if !defined(BSP_INTERRUPT_VECTOR_MIN) || !defined(BSP_INTERRUPT_VECTOR_MAX) || (BSP_INTERRUPT_VECTOR_MAX + 1) < BSP_INTERRUPT_VECTOR_MIN
62 #error "invalid BSP_INTERRUPT_VECTOR_MIN or BSP_INTERRUPT_VECTOR_MAX"
63#endif
64
65#if defined(BSP_INTERRUPT_USE_INDEX_TABLE) && !defined(BSP_INTERRUPT_HANDLER_TABLE_SIZE)
66 #error "if you define BSP_INTERRUPT_USE_INDEX_TABLE, you have to define BSP_INTERRUPT_HANDLER_TABLE_SIZE etc. as well"
67#endif
68
69#if defined(BSP_INTERRUPT_NO_HEAP_USAGE) && !defined(BSP_INTERRUPT_USE_INDEX_TABLE)
70 #error "if you define BSP_INTERRUPT_NO_HEAP_USAGE, you have to define BSP_INTERRUPT_USE_INDEX_TABLE etc. as well"
71#endif
72
73#define BSP_INTERRUPT_VECTOR_NUMBER \
74 (BSP_INTERRUPT_VECTOR_MAX - BSP_INTERRUPT_VECTOR_MIN + 1)
75
76#ifndef BSP_INTERRUPT_HANDLER_TABLE_SIZE
77 #define BSP_INTERRUPT_HANDLER_TABLE_SIZE BSP_INTERRUPT_VECTOR_NUMBER
78#endif
79
80/* Internal macros for SMP support, do not use externally */
81#ifdef RTEMS_SMP
82 #define bsp_interrupt_disable(level) do { (void) level; } while (0)
83 #define bsp_interrupt_enable(level) do { } while (0)
84 #define bsp_interrupt_fence(order) _Atomic_Fence(order)
85#else
86 #define bsp_interrupt_disable(level) rtems_interrupt_disable(level)
87 #define bsp_interrupt_enable(level) rtems_interrupt_enable(level)
88 #define bsp_interrupt_fence(order) do { } while (0)
89#endif
90
91#define bsp_interrupt_assert(e) _Assert(e)
92
93 struct bsp_interrupt_handler_entry {
94 rtems_interrupt_handler handler;
95 void *arg;
96 const char *info;
97 struct bsp_interrupt_handler_entry *next;
98};
99
100typedef struct bsp_interrupt_handler_entry bsp_interrupt_handler_entry;
101
102extern bsp_interrupt_handler_entry bsp_interrupt_handler_table [];
103
104#ifdef BSP_INTERRUPT_USE_INDEX_TABLE
105 #if BSP_INTERRUPT_HANDLER_TABLE_SIZE < 0x100
106 typedef uint8_t bsp_interrupt_handler_index_type;
107 #elif BSP_INTERRUPT_HANDLER_TABLE_SIZE < 0x10000
108 typedef uint16_t bsp_interrupt_handler_index_type;
109 #else
110 typedef uint32_t bsp_interrupt_handler_index_type;
111 #endif
112 extern bsp_interrupt_handler_index_type bsp_interrupt_handler_index_table [];
113#endif
114
115static inline rtems_vector_number bsp_interrupt_handler_index(
116 rtems_vector_number vector
117)
118{
119 #ifdef BSP_INTERRUPT_USE_INDEX_TABLE
120 return bsp_interrupt_handler_index_table [vector - BSP_INTERRUPT_VECTOR_MIN];
121 #else
122 return vector - BSP_INTERRUPT_VECTOR_MIN;
123 #endif
124}
125
176#ifdef BSP_INTERRUPT_CUSTOM_VALID_VECTOR
177 bool bsp_interrupt_is_valid_vector(rtems_vector_number vector);
178#else
183 static inline bool bsp_interrupt_is_valid_vector(rtems_vector_number vector)
184 {
185 return (rtems_vector_number) BSP_INTERRUPT_VECTOR_MIN <= vector
186 && vector <= (rtems_vector_number) BSP_INTERRUPT_VECTOR_MAX;
187 }
188#endif
189
199void bsp_interrupt_handler_default(rtems_vector_number vector);
200
213void bsp_interrupt_initialize(void);
214
230 rtems_status_code bsp_interrupt_facility_initialize(void);
231
246void bsp_interrupt_vector_enable(rtems_vector_number vector);
247
263void bsp_interrupt_vector_disable(rtems_vector_number vector);
264
275static inline void bsp_interrupt_handler_dispatch(rtems_vector_number vector)
276{
277 if (bsp_interrupt_is_valid_vector(vector)) {
278 const bsp_interrupt_handler_entry *e =
279 &bsp_interrupt_handler_table [bsp_interrupt_handler_index(vector)];
280
281 do {
282 rtems_interrupt_handler handler;
283 void *arg;
284
285 arg = e->arg;
286 bsp_interrupt_fence(ATOMIC_ORDER_ACQUIRE);
287 handler = e->handler;
288 (*handler)(arg);
289
290 e = e->next;
291 } while (e != NULL);
292 } else {
293 bsp_interrupt_handler_default(vector);
294 }
295}
296
306bool bsp_interrupt_handler_is_empty(rtems_vector_number vector);
307
310/* For internal use only */
311void bsp_interrupt_lock(void);
312
313/* For internal use only */
314void bsp_interrupt_unlock(void);
315
316#ifdef __cplusplus
317}
318#endif /* __cplusplus */
319
320#endif /* LIBBSP_SHARED_IRQ_GENERIC_H */
assert.h
Information for the Assert Handler.
NULL
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
rtems_vector_number
ISR_Vector_number rtems_vector_number
Control block type used to manage the vectors.
Definition: intr.h:47
rtems_status_code
rtems_status_code
Classic API Status.
Definition: status.h:43
bsp_interrupt_handler_is_empty
bool bsp_interrupt_handler_is_empty(rtems_vector_number vector)
Is interrupt handler empty.
Definition: irq-generic.c:561
bsp_interrupt_handler_default
void bsp_interrupt_handler_default(rtems_vector_number vector)
Default interrupt handler.
Definition: irq.c:160
bsp_interrupt_vector_disable
void bsp_interrupt_vector_disable(rtems_vector_number vector)
Disables the interrupt vector with number vector.
Definition: irq.c:110
bsp_interrupt_vector_enable
void bsp_interrupt_vector_enable(rtems_vector_number vector)
Enables the interrupt vector with number vector.
Definition: irq.c:98
bsp_interrupt_facility_initialize
rtems_status_code bsp_interrupt_facility_initialize(void)
BSP specific initialization.
Definition: irq.c:122
bsp_interrupt_initialize
void bsp_interrupt_initialize(void)
Initialize BSP interrupt support.
Definition: irq-generic.c:173
rtems_interrupt_handler
void(* rtems_interrupt_handler)(void *)
Interrupt handler routine type.
Definition: irq-extension.h:79
atomic.h
Atomic Operations API.
irq-extension.h
Header file for the Interrupt Manager Extension.
bsp_interrupt_handler_entry
Definition: irq-generic.h:93
e
unsigned e
Definition: tlb.h:13