Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
sw_isr_table.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, Wind River Systems, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
14#ifndef ZEPHYR_INCLUDE_SW_ISR_TABLE_H_
15#define ZEPHYR_INCLUDE_SW_ISR_TABLE_H_
16
17#if !defined(_ASMLANGUAGE)
18#include <zephyr/device.h>
20#include <zephyr/types.h>
21#include <zephyr/toolchain.h>
22#include <zephyr/sys/util.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/* Default vector for the IRQ vector table */
29void _isr_wrapper(void);
30
31/* Spurious interrupt handler. Throws an error if called */
32void z_irq_spurious(const void *unused);
33
34/*
35 * Note the order: arg first, then ISR. This allows a table entry to be
36 * loaded arg -> r0, isr -> r3 in _isr_wrapper with one ldmia instruction,
37 * on ARM Cortex-M (Thumb2).
38 */
39struct _isr_table_entry {
40 const void *arg;
41 void (*isr)(const void *);
42};
43
44/* The software ISR table itself, an array of these structures indexed by the
45 * irq line
46 */
47extern struct _isr_table_entry _sw_isr_table[];
48
49struct _irq_parent_entry {
50 const struct device *dev;
51 unsigned int level;
52 unsigned int irq;
53 unsigned int offset;
54};
55
60/* Mapping between aggregator level to order */
61#define Z_STR_L2 2ND
62#define Z_STR_L3 3RD
71#define Z_SW_ISR_TBL_KCONFIG_BY_ALVL(l) CONCAT(CONFIG_, CONCAT(Z_STR_L, l), _LVL_ISR_TBL_OFFSET)
72
85#define INTC_BASE_ISR_TBL_OFFSET(node_id) \
86 Z_SW_ISR_TBL_KCONFIG_BY_ALVL(DT_INTC_GET_AGGREGATOR_LEVEL(node_id))
87
95#define INTC_INST_ISR_TBL_OFFSET(inst) \
96 (INTC_BASE_ISR_TBL_OFFSET(DT_DRV_INST(inst)) + (inst * CONFIG_MAX_IRQ_PER_AGGREGATOR))
97
108#define INTC_CHILD_ISR_TBL_OFFSET(node_id) \
109 (INTC_BASE_ISR_TBL_OFFSET(node_id) + \
110 (DT_NODE_CHILD_IDX(node_id) * CONFIG_MAX_IRQ_PER_AGGREGATOR))
111
121#define IRQ_PARENT_ENTRY_DEFINE(_name, _dev, _irq, _offset, _level) \
122 static const STRUCT_SECTION_ITERABLE_ALTERNATE(intc_table, _irq_parent_entry, _name) = { \
123 .dev = _dev, \
124 .level = _level, \
125 .irq = _irq, \
126 .offset = _offset, \
127 }
128
129/*
130 * Data structure created in a special binary .intlist section for each
131 * configured interrupt. gen_irq_tables.py pulls this out of the binary and
132 * uses it to create the IRQ vector table and the _sw_isr_table.
133 *
134 * More discussion in include/linker/intlist.ld
135 *
136 * This is a version used when CONFIG_ISR_TABLES_LOCAL_DECLARATION is disabled.
137 * See _isr_list_sname used otherwise.
138 */
139struct _isr_list {
141 int32_t irq;
145 void *func;
147 const void *param;
148};
149
150/*
151 * Data structure created in a special binary .intlist section for each
152 * configured interrupt. gen_isr_tables.py pulls this out of the binary and
153 * uses it to create linker script chunks that would place interrupt table entries
154 * in the right place in the memory.
155 *
156 * This is a version used when CONFIG_ISR_TABLES_LOCAL_DECLARATION is enabled.
157 * See _isr_list used otherwise.
158 */
159struct _isr_list_sname {
161 int32_t irq;
165 const char sname[];
166};
167
168#ifdef CONFIG_SHARED_INTERRUPTS
169struct z_shared_isr_table_entry {
170 struct _isr_table_entry clients[CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS];
171 size_t client_num;
172};
173
174void z_shared_isr(const void *data);
175
176extern struct z_shared_isr_table_entry z_shared_sw_isr_table[];
177#endif /* CONFIG_SHARED_INTERRUPTS */
178
180#define ISR_FLAG_DIRECT BIT(0)
181
182#define _MK_ISR_NAME(x, y) __MK_ISR_NAME(x, y)
183#define __MK_ISR_NAME(x, y) __isr_ ## x ## _irq_ ## y
184
185
186#if defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION)
187
188#define _MK_ISR_ELEMENT_NAME(func, id) __MK_ISR_ELEMENT_NAME(func, id)
189#define __MK_ISR_ELEMENT_NAME(func, id) __isr_table_entry_ ## func ## _irq_ ## id
190
191#define _MK_IRQ_ELEMENT_NAME(func, id) __MK_ISR_ELEMENT_NAME(func, id)
192#define __MK_IRQ_ELEMENT_NAME(func, id) __irq_table_entry_ ## func ## _irq_ ## id
193
194#define _MK_ISR_SECTION_NAME(prefix, file, counter) \
195 "." Z_STRINGIFY(prefix)"."file"." Z_STRINGIFY(counter)
196
197#define _MK_ISR_ELEMENT_SECTION(counter) _MK_ISR_SECTION_NAME(irq, __FILE__, counter)
198#define _MK_IRQ_ELEMENT_SECTION(counter) _MK_ISR_SECTION_NAME(isr, __FILE__, counter)
199
200/* Separated macro to create ISR table entry only.
201 * Used by Z_ISR_DECLARE and ISR tables generation script.
202 */
203#define _Z_ISR_TABLE_ENTRY(irq, func, param, sect) \
204 static Z_DECL_ALIGN(struct _isr_table_entry) \
205 __attribute__((section(sect))) \
206 __used _MK_ISR_ELEMENT_NAME(func, __COUNTER__) = { \
207 .arg = (const void *)(param), \
208 .isr = (void (*)(const void *))(void *)(func) \
209 }
210
211#define Z_ISR_DECLARE_C(irq, flags, func, param, counter) \
212 _Z_ISR_DECLARE_C(irq, flags, func, param, counter)
213
214#define _Z_ISR_DECLARE_C(irq, flags, func, param, counter) \
215 _Z_ISR_TABLE_ENTRY(irq, func, param, _MK_ISR_ELEMENT_SECTION(counter)); \
216 static struct _isr_list_sname Z_GENERIC_SECTION(.intList) \
217 __used _MK_ISR_NAME(func, counter) = \
218 {irq, flags, _MK_ISR_ELEMENT_SECTION(counter)}
219
220/* Create an entry for _isr_table to be then placed by the linker.
221 * An instance of struct _isr_list which gets put in the .intList
222 * section is created with the name of the section where _isr_table entry is placed to be then
223 * used by isr generation script to create linker script chunk.
224 */
225#define Z_ISR_DECLARE(irq, flags, func, param) \
226 BUILD_ASSERT(((flags) & ISR_FLAG_DIRECT) == 0, "Use Z_ISR_DECLARE_DIRECT macro"); \
227 Z_ISR_DECLARE_C(irq, flags, func, param, __COUNTER__)
228
229
230/* Separated macro to create ISR Direct table entry only.
231 * Used by Z_ISR_DECLARE_DIRECT and ISR tables generation script.
232 */
233#define _Z_ISR_DIRECT_TABLE_ENTRY(irq, func, sect) \
234 COND_CODE_1(CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS, ( \
235 static Z_DECL_ALIGN(uintptr_t) \
236 __attribute__((section(sect))) \
237 __used _MK_IRQ_ELEMENT_NAME(func, __COUNTER__) = ((uintptr_t)(func)); \
238 ), ( \
239 static void __attribute__((section(sect))) __attribute__((naked)) \
240 __used _MK_IRQ_ELEMENT_NAME(func, __COUNTER__)(void) { \
241 __asm(ARCH_IRQ_VECTOR_JUMP_CODE(func)); \
242 } \
243 ))
244
245#define Z_ISR_DECLARE_DIRECT_C(irq, flags, func, counter) \
246 _Z_ISR_DECLARE_DIRECT_C(irq, flags, func, counter)
247
248#define _Z_ISR_DECLARE_DIRECT_C(irq, flags, func, counter) \
249 _Z_ISR_DIRECT_TABLE_ENTRY(irq, func, _MK_IRQ_ELEMENT_SECTION(counter)); \
250 static struct _isr_list_sname Z_GENERIC_SECTION(.intList) \
251 __used _MK_ISR_NAME(func, counter) = { \
252 irq, \
253 ISR_FLAG_DIRECT | (flags), \
254 _MK_IRQ_ELEMENT_SECTION(counter)}
255
256/* Create an entry to irq table and place it in specific section which name is then placed
257 * in an instance of struct _isr_list to be then used by the isr generation script to create
258 * the linker script chunks.
259 */
260#define Z_ISR_DECLARE_DIRECT(irq, flags, func) \
261 BUILD_ASSERT(IS_ENABLED(CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS) || \
262 IS_ENABLED(CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_CODE), \
263 "CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_{ADDRESS,CODE} not set"); \
264 Z_ISR_DECLARE_DIRECT_C(irq, flags, func, __COUNTER__)
265
266
267#else /* defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION) */
268
269/* Create an instance of struct _isr_list which gets put in the .intList
270 * section. This gets consumed by gen_isr_tables.py which creates the vector
271 * and/or SW ISR tables.
272 */
273#define Z_ISR_DECLARE(irq, flags, func, param) \
274 static Z_DECL_ALIGN(struct _isr_list) Z_GENERIC_SECTION(.intList) \
275 __used _MK_ISR_NAME(func, __COUNTER__) = \
276 {irq, flags, (void *)&func, (const void *)param}
277
278/* The version of the Z_ISR_DECLARE that should be used for direct ISR declaration.
279 * It is here for the API match the version with CONFIG_ISR_TABLES_LOCAL_DECLARATION enabled.
280 */
281#define Z_ISR_DECLARE_DIRECT(irq, flags, func) \
282 Z_ISR_DECLARE(irq, ISR_FLAG_DIRECT | (flags), func, NULL)
283
284#endif
285
286#define IRQ_TABLE_SIZE (CONFIG_NUM_IRQS - CONFIG_GEN_IRQ_START_VECTOR)
287
288#ifdef CONFIG_DYNAMIC_INTERRUPTS
289void z_isr_install(unsigned int irq, void (*routine)(const void *),
290 const void *param);
291
292#ifdef CONFIG_SHARED_INTERRUPTS
293int z_isr_uninstall(unsigned int irq, void (*routine)(const void *),
294 const void *param);
295#endif /* CONFIG_SHARED_INTERRUPTS */
296#endif
297
298#ifdef __cplusplus
299}
300#endif
301
302#endif /* _ASMLANGUAGE */
303
304#endif /* ZEPHYR_INCLUDE_SW_ISR_TABLE_H_ */
flags
Definition parser.h:96
__INT32_TYPE__ int32_t
Definition stdint.h:74
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
Misc utilities.
Macros to abstract toolchain specific capabilities.