Zephyr API Documentation  3.6.99
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 <[email protected]>
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
21#ifndef _ASMLANGUAGE
22#include <zephyr/irq.h>
23#include <zephyr/sw_isr_table.h>
24#include <stdbool.h>
25#endif /* !_ASMLANGUAGE */
26
27/* Exceptions 0-15 (MCAUSE interrupt=0) */
28
29/* Environment Call from U-mode */
30#define RISCV_EXC_ECALLU 8
32#define RISCV_EXC_ECALLM 11
33
34/* IRQs 0-15 (MCAUSE interrupt=1) */
35
37#define RISCV_IRQ_MSOFT 3
39#define RISCV_IRQ_MEXT 11
40
41#ifdef CONFIG_64BIT
42#define RISCV_MCAUSE_IRQ_POS 63U
43#define RISCV_MCAUSE_IRQ_BIT BIT64(RISCV_MCAUSE_IRQ_POS)
44#else
45#define RISCV_MCAUSE_IRQ_POS 31U
46#define RISCV_MCAUSE_IRQ_BIT BIT(RISCV_MCAUSE_IRQ_POS)
47#endif
48
49#ifndef _ASMLANGUAGE
50
51extern void arch_irq_enable(unsigned int irq);
52extern void arch_irq_disable(unsigned int irq);
53extern int arch_irq_is_enabled(unsigned int irq);
54
55#if defined(CONFIG_RISCV_HAS_PLIC) || defined(CONFIG_RISCV_HAS_CLIC)
56extern void z_riscv_irq_priority_set(unsigned int irq,
57 unsigned int prio,
59#else
60#define z_riscv_irq_priority_set(i, p, f) /* Nothing */
61#endif /* CONFIG_RISCV_HAS_PLIC || CONFIG_RISCV_HAS_CLIC */
62
63#define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
64{ \
65 Z_ISR_DECLARE(irq_p + CONFIG_RISCV_RESERVED_IRQ_ISR_TABLES_OFFSET, \
66 0, isr_p, isr_param_p); \
67 z_riscv_irq_priority_set(irq_p, priority_p, flags_p); \
68}
69
70#define ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) \
71{ \
72 Z_ISR_DECLARE_DIRECT(irq_p + CONFIG_RISCV_RESERVED_IRQ_ISR_TABLES_OFFSET, \
73 ISR_FLAG_DIRECT, isr_p); \
74 z_riscv_irq_priority_set(irq_p, priority_p, flags_p); \
75}
76
77#define ARCH_ISR_DIRECT_HEADER() arch_isr_direct_header()
78#define ARCH_ISR_DIRECT_FOOTER(swap) arch_isr_direct_footer(swap)
79
80#ifdef CONFIG_TRACING_ISR
81extern void sys_trace_isr_enter(void);
82extern void sys_trace_isr_exit(void);
83#endif
84
85static inline void arch_isr_direct_header(void)
86{
87#ifdef CONFIG_TRACING_ISR
89#endif
90 /* We need to increment this so that arch_is_in_isr() keeps working */
91 ++(arch_curr_cpu()->nested);
92}
93
94extern void __soc_handle_irq(unsigned long mcause);
95
96static inline void arch_isr_direct_footer(int swap)
97{
98 ARG_UNUSED(swap);
99 unsigned long mcause;
100
101 /* Get the IRQ number */
102 __asm__ volatile("csrr %0, mcause" : "=r" (mcause));
103 mcause &= CONFIG_RISCV_MCAUSE_EXCEPTION_MASK;
104
105 /* Clear the pending IRQ */
106 __soc_handle_irq(mcause);
107
108 /* We are not in the ISR anymore */
109 --(arch_curr_cpu()->nested);
110
111#ifdef CONFIG_TRACING_ISR
113#endif
114}
115
116/*
117 * TODO: Add support for rescheduling
118 */
119#define ARCH_ISR_DIRECT_DECLARE(name) \
120 static inline int name##_body(void); \
121 __attribute__ ((interrupt)) void name(void) \
122 { \
123 ISR_DIRECT_HEADER(); \
124 name##_body(); \
125 ISR_DIRECT_FOOTER(0); \
126 } \
127 static inline int name##_body(void)
128
129#endif /* _ASMLANGUAGE */
130
131#ifdef __cplusplus
132}
133#endif
134
135#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.