Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
irq.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Intel corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11#ifndef ZEPHYR_INCLUDE_IRQ_H_
12#define ZEPHYR_INCLUDE_IRQ_H_
13
14/* Pull in the arch-specific implementations */
15#include <zephyr/arch/cpu.h>
16
17#ifndef _ASMLANGUAGE
18#include <limits.h>
19#include <stdbool.h>
20#include <zephyr/toolchain.h>
21#include <zephyr/types.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
32
50#define IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
51 ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p)
52
66static inline int
67irq_connect_dynamic(unsigned int irq, unsigned int priority,
68 void (*routine)(const void *parameter),
69 const void *parameter, uint32_t flags)
70{
71 return arch_irq_connect_dynamic(irq, priority, routine, parameter,
72 flags);
73}
74
91static inline int
92irq_disconnect_dynamic(unsigned int irq, unsigned int priority,
93 void (*routine)(const void *parameter),
94 const void *parameter, uint32_t flags)
95{
96 return arch_irq_disconnect_dynamic(irq, priority, routine,
97 parameter, flags);
98}
99
100/*
101 * Direct interrupts are optional; only architectures selecting
102 * CONFIG_ARCH_HAS_DIRECT_INTERRUPTS define the ARCH_*_DIRECT_* hooks used
103 * below. Without these fallbacks the undefined function-like macros survive
104 * preprocessing and misparse as K&R function definitions, which reports a
105 * missing return type rather than the missing feature.
106 *
107 * Only the two API entry points are stubbed: the HEADER/FOOTER/PM hooks are
108 * reachable solely from inside a direct ISR body, so the assertion on
109 * ARCH_ISR_DIRECT_DECLARE() already covers them, and RX defines the
110 * HEADER/FOOTER hooks for its internal ISR accounting without supporting
111 * direct interrupts, so stubbing those would collide.
112 *
113 * The guard cannot test the hooks themselves: the arch-level irq.h headers
114 * include this file before defining them. Doxygen is kept out so that the
115 * documented stubs in arch_interface.h remain the only visible definitions.
116 */
117#if !defined(CONFIG_ARCH_HAS_DIRECT_INTERRUPTS) && !defined(__DOXYGEN__)
118
119#define Z_ISR_DIRECT_UNSUPPORTED \
120 BUILD_ASSERT(0, "direct interrupts are not supported by this architecture")
121
122#define ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) \
123 Z_ISR_DIRECT_UNSUPPORTED
124#define ARCH_ISR_DIRECT_DECLARE(name) \
125 Z_ISR_DIRECT_UNSUPPORTED; \
126 int name(void)
127
128#endif /* !CONFIG_ARCH_HAS_DIRECT_INTERRUPTS && !__DOXYGEN__ */
129
172#define IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) \
173 ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p)
174
182#define ISR_DIRECT_HEADER() ARCH_ISR_DIRECT_HEADER()
183
199#define ISR_DIRECT_FOOTER(check_reschedule) \
200 ARCH_ISR_DIRECT_FOOTER(check_reschedule)
201
214#define ISR_DIRECT_PM() ARCH_ISR_DIRECT_PM()
215
249#define ISR_DIRECT_DECLARE(name) ARCH_ISR_DIRECT_DECLARE(name)
250
288#ifdef CONFIG_SMP
289unsigned int z_smp_global_lock(void);
290#define irq_lock() z_smp_global_lock()
291#else
292#define irq_lock() arch_irq_lock()
293#endif
294
316#ifdef CONFIG_SMP
317void z_smp_global_unlock(unsigned int key);
318#define irq_unlock(key) z_smp_global_unlock(key)
319#else
320#define irq_unlock(key) arch_irq_unlock(key)
321#endif
322
330#define irq_enable(irq) arch_irq_enable(irq)
331
339#define irq_disable(irq) arch_irq_disable(irq)
340
350#define irq_is_enabled(irq) arch_irq_is_enabled(irq)
351
352/*
353 * Namespaced equivalents of the interrupt APIs above. New code should
354 * prefer these. The unprefixed names remain fully supported and must stay
355 * function-like macros: vendor HAL headers declare functions with those
356 * names, and a macro coexists with such a declaration where a function
357 * definition would conflict.
358 */
359
365static ALWAYS_INLINE unsigned int k_irq_lock(void)
366{
367 return irq_lock();
368}
369
375static ALWAYS_INLINE void k_irq_unlock(unsigned int key)
376{
377 irq_unlock(key);
378}
379
385static ALWAYS_INLINE void k_irq_enable(unsigned int irq)
386{
387 irq_enable(irq);
388}
389
395static ALWAYS_INLINE void k_irq_disable(unsigned int irq)
396{
397 irq_disable(irq);
398}
399
407static ALWAYS_INLINE int k_irq_is_enabled(unsigned int irq)
408{
409 return irq_is_enabled(irq);
410}
411
424static ALWAYS_INLINE int k_irq_connect_dynamic(unsigned int irq, unsigned int priority,
425 void (*routine)(const void *parameter),
426 const void *parameter, uint32_t flags)
427{
428 return irq_connect_dynamic(irq, priority, routine, parameter, flags);
429}
430
443static ALWAYS_INLINE int k_irq_disconnect_dynamic(unsigned int irq, unsigned int priority,
444 void (*routine)(const void *parameter),
445 const void *parameter, uint32_t flags)
446{
447 return irq_disconnect_dynamic(irq, priority, routine, parameter, flags);
448}
449
450#if defined(CONFIG_ARCH_HAS_IRQ_PENDING_OPS) || defined(__DOXYGEN__)
462static ALWAYS_INLINE void k_irq_clear_pending(unsigned int irq)
463{
465}
466
478static ALWAYS_INLINE void k_irq_set_pending(unsigned int irq)
479{
481}
482
496static ALWAYS_INLINE bool k_irq_is_pending(unsigned int irq)
497{
498 return arch_irq_is_pending(irq);
499}
500#endif /* CONFIG_ARCH_HAS_IRQ_PENDING_OPS */
501
502#if defined(CONFIG_ARCH_HAS_IRQ_GET_ACTIVE) || defined(__DOXYGEN__)
506#define K_IRQ_ACTIVE_NONE UINT_MAX
507
521static ALWAYS_INLINE unsigned int k_irq_get_active(void)
522{
523 return arch_irq_get_active();
524}
525#endif /* CONFIG_ARCH_HAS_IRQ_GET_ACTIVE */
526
530
531#ifdef __cplusplus
532}
533#endif
534
535#endif /* ASMLANGUAGE */
536#endif /* ZEPHYR_INCLUDE_IRQ_H_ */
int arch_irq_disconnect_dynamic(unsigned int irq, unsigned int priority, void(*routine)(const void *parameter), const void *parameter, uint32_t flags)
Arch-specific hook to dynamically uninstall a shared interrupt.
void arch_irq_clear_pending(unsigned int irq)
Clear the pending state of the specified interrupt line.
bool arch_irq_is_pending(unsigned int irq)
Test if the specified interrupt line is pending.
int arch_irq_connect_dynamic(unsigned int irq, unsigned int priority, void(*routine)(const void *parameter), const void *parameter, uint32_t flags)
Arch-specific hook to install a dynamic interrupt.
void arch_irq_set_pending(unsigned int irq)
Set the pending state of the specified interrupt line.
unsigned int arch_irq_get_active(void)
Report the interrupt line being serviced on the current CPU.
#define irq_lock()
Lock interrupts.
Definition irq.h:290
static ALWAYS_INLINE bool k_irq_is_pending(unsigned int irq)
Get IRQ pending state.
Definition irq.h:496
static ALWAYS_INLINE int k_irq_connect_dynamic(unsigned int irq, unsigned int priority, void(*routine)(const void *parameter), const void *parameter, uint32_t flags)
Configure a dynamic interrupt; namespaced equivalent of irq_connect_dynamic().
Definition irq.h:424
static ALWAYS_INLINE void k_irq_disable(unsigned int irq)
Disable an IRQ; namespaced equivalent of irq_disable().
Definition irq.h:395
static ALWAYS_INLINE void k_irq_unlock(unsigned int key)
Unlock interrupts; namespaced equivalent of irq_unlock().
Definition irq.h:375
static int irq_connect_dynamic(unsigned int irq, unsigned int priority, void(*routine)(const void *parameter), const void *parameter, uint32_t flags)
Configure a dynamic interrupt.
Definition irq.h:67
static ALWAYS_INLINE void k_irq_enable(unsigned int irq)
Enable an IRQ; namespaced equivalent of irq_enable().
Definition irq.h:385
#define irq_unlock(key)
Unlock interrupts.
Definition irq.h:318
#define irq_is_enabled(irq)
Get IRQ enable state.
Definition irq.h:350
#define irq_enable(irq)
Enable an IRQ.
Definition irq.h:330
#define irq_disable(irq)
Disable an IRQ.
Definition irq.h:339
static ALWAYS_INLINE void k_irq_clear_pending(unsigned int irq)
Clear the pending state of an IRQ.
Definition irq.h:462
static ALWAYS_INLINE unsigned int k_irq_get_active(void)
Get the IRQ currently being serviced on this CPU.
Definition irq.h:521
static ALWAYS_INLINE void k_irq_set_pending(unsigned int irq)
Set the pending state of an IRQ.
Definition irq.h:478
static ALWAYS_INLINE int k_irq_is_enabled(unsigned int irq)
Get IRQ enable state; namespaced equivalent of irq_is_enabled().
Definition irq.h:407
static int irq_disconnect_dynamic(unsigned int irq, unsigned int priority, void(*routine)(const void *parameter), const void *parameter, uint32_t flags)
Disconnect a dynamic interrupt.
Definition irq.h:92
static ALWAYS_INLINE unsigned int k_irq_lock(void)
Lock interrupts; namespaced equivalent of irq_lock().
Definition irq.h:365
static ALWAYS_INLINE int k_irq_disconnect_dynamic(unsigned int irq, unsigned int priority, void(*routine)(const void *parameter), const void *parameter, uint32_t flags)
Disconnect a dynamic interrupt; namespaced equivalent of irq_disconnect_dynamic().
Definition irq.h:443
#define ALWAYS_INLINE
Definition common.h:180
flags
Definition parser.h:97
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Macros to abstract toolchain specific capabilities.