Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
irq.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Carlo Caione <ccaione@baylibre.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
14#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_IRQ_H_
15#define ZEPHYR_INCLUDE_ARCH_RISCV_IRQ_H_
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
22
23#ifndef _ASMLANGUAGE
24#include <zephyr/irq.h>
25#include <zephyr/sw_isr_table.h>
26#include <stdbool.h>
27#endif /* !_ASMLANGUAGE */
28
29/* Exceptions 0-15 (MCAUSE interrupt=0) */
30
31/* Environment Call from U-mode */
32#define RISCV_EXC_ECALLU 8
34#define RISCV_EXC_ECALLM 11
35
36/* IRQs 0-15 (MCAUSE interrupt=1) */
37
39#define RISCV_IRQ_MSOFT 3
41#define RISCV_IRQ_MEXT 11
42
43#ifdef CONFIG_64BIT
44#define RISCV_MCAUSE_IRQ_POS 63U
45#define RISCV_MCAUSE_IRQ_BIT BIT64(RISCV_MCAUSE_IRQ_POS)
46#else
47#define RISCV_MCAUSE_IRQ_POS 31U
48#define RISCV_MCAUSE_IRQ_BIT BIT(RISCV_MCAUSE_IRQ_POS)
49#endif
50
51#ifndef _ASMLANGUAGE
52
53extern void arch_irq_enable(unsigned int irq);
54extern void arch_irq_disable(unsigned int irq);
55extern int arch_irq_is_enabled(unsigned int irq);
56
57#if defined(CONFIG_RISCV_HAS_PLIC) || defined(CONFIG_RISCV_HAS_CLIC)
58extern void z_riscv_irq_priority_set(unsigned int irq,
59 unsigned int prio,
61#else
62#define z_riscv_irq_priority_set(i, p, f) /* Nothing */
63#endif /* CONFIG_RISCV_HAS_PLIC || CONFIG_RISCV_HAS_CLIC */
64
65#define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
66{ \
67 Z_ISR_DECLARE(irq_p + CONFIG_RISCV_RESERVED_IRQ_ISR_TABLES_OFFSET, \
68 0, isr_p, isr_param_p); \
69 z_riscv_irq_priority_set(irq_p, priority_p, flags_p); \
70}
71
72#define ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) \
73{ \
74 Z_ISR_DECLARE_DIRECT(irq_p + CONFIG_RISCV_RESERVED_IRQ_ISR_TABLES_OFFSET, \
75 ISR_FLAG_DIRECT, isr_p); \
76 z_riscv_irq_priority_set(irq_p, priority_p, flags_p); \
77}
78
79#define ARCH_ISR_DIRECT_HEADER() arch_isr_direct_header()
80#define ARCH_ISR_DIRECT_FOOTER(swap) arch_isr_direct_footer(swap)
81
82#ifdef CONFIG_TRACING_ISR
83extern void sys_trace_isr_enter(void);
84extern void sys_trace_isr_exit(void);
85#endif
86
87static inline void arch_isr_direct_header(void)
88{
89#ifdef CONFIG_TRACING_ISR
91#endif
92 /* We need to increment this so that arch_is_in_isr() keeps working */
93 ++(arch_curr_cpu()->nested);
94}
95
96extern void __soc_handle_irq(unsigned long mcause);
97
98static inline void arch_isr_direct_footer(int swap)
99{
100 ARG_UNUSED(swap);
101 unsigned long mcause;
102
103 /* Get the IRQ number */
104 __asm__ volatile("csrr %0, mcause" : "=r" (mcause));
105 mcause &= CONFIG_RISCV_MCAUSE_EXCEPTION_MASK;
106
107 /* Clear the pending IRQ */
108 __soc_handle_irq(mcause);
109
110 /* We are not in the ISR anymore */
111 --(arch_curr_cpu()->nested);
112
113#ifdef CONFIG_TRACING_ISR
115#endif
116}
117
118/*
119 * TODO: Add support for rescheduling
120 */
121#define ARCH_ISR_DIRECT_DECLARE(name) \
122 static inline int name##_body(void); \
123 __attribute__ ((interrupt)) void name(void) \
124 { \
125 ISR_DIRECT_HEADER(); \
126 name##_body(); \
127 ISR_DIRECT_FOOTER(0); \
128 } \
129 static inline int name##_body(void)
130
131#endif /* _ASMLANGUAGE */
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_IRQ_H_ */
static ALWAYS_INLINE _cpu_t * arch_curr_cpu(void)
Definition arch_inlines.h:17
static void arch_isr_direct_header(void)
Definition irq.h:91
static void arch_isr_direct_footer(int maybe_swap)
Definition irq.h:98
#define arch_irq_disable(irq)
Definition irq.h:107
#define arch_irq_enable(irq)
Definition irq.h:106
#define arch_irq_is_enabled(irq)
Definition irq.h:109
void sys_trace_isr_enter(void)
Called when entering an ISR.
void sys_trace_isr_exit(void)
Called when exiting an ISR.
Public interface for configuring interrupts.
flags
Definition parser.h:96
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Software-managed ISR table.
Macro utilities.