irq_arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Ken Rabold
3  * 2020 Inria
4  * 2020 Otto-von-Guericke-Universität Magdeburg
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser General
7  * Public License v2.1. See the file LICENSE in the top level directory for more
8  * details.
9  */
10 
23 #ifndef IRQ_ARCH_H
24 #define IRQ_ARCH_H
25 
26 #include <stdint.h>
27 #include "irq.h"
28 #include "cpu_conf.h"
29 #include "cpu.h"
30 
31 #include "vendor/encoding.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 extern volatile int fe310_in_isr;
38 
42 static inline __attribute__((always_inline)) unsigned int irq_enable(void)
43 {
44  /* Enable all interrupts */
45  unsigned state;
46  __asm__ volatile (
47  "csrrs %[dest], mstatus, %[mask]"
48  : [dest] "=r"(state)
49  : [mask] "i"(MSTATUS_MIE)
50  : "memory"
51  );
52  return state;
53 }
54 
58 static inline __attribute__((always_inline)) unsigned int irq_disable(void)
59 {
60 
61  unsigned int state;
62  __asm__ volatile (
63  "csrrc %[dest], mstatus, %[mask]"
64  : [dest] "=r"(state)
65  : [mask] "i"(MSTATUS_MIE)
66  : "memory"
67  );
68 
69  return state;
70 }
71 
75 static inline __attribute__((always_inline)) void irq_restore(unsigned int state)
76 {
77  /* Restore all interrupts to given state */
78  __asm__ volatile (
79  "csrw mstatus, %[state]"
80  : /* no outputs */
81  : [state] "r"(state)
82  : "memory"
83  );
84 }
85 
89 static inline __attribute__((always_inline)) int irq_is_in(void)
90 {
91  return fe310_in_isr;
92 }
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif /* IRQ_ARCH_H */
99 
irq_restore
static void irq_restore(unsigned int state)
Restore the state of the IRQ flags.
Definition: irq_arch.h:75
irq_disable
static unsigned int irq_disable(void)
Disable all maskable interrupts.
Definition: irq_arch.h:58
irq_enable
static unsigned int irq_enable(void)
Enable all maskable interrupts.
Definition: irq_arch.h:42
irq.h
IRQ driver interface.
irq_is_in
static int irq_is_in(void)
See if the current context is inside an ISR.
Definition: irq_arch.h:89
cpu_conf.h
CPU specific configuration options.