irq_arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universität Berlin
3  * 2020 Otto-von-Guericke-Universität Magdeburg
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
23 #ifndef IRQ_ARCH_H
24 #define IRQ_ARCH_H
25 
26 #include "irq.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /*
33  * gcc warns for missing NOPs before/after interrupt enable/disable.
34  * so I added the NOP instructions, even though they might not be necessary
35  * due to following AND. // Kaspar
36  */
37 
38 
39 extern volatile int __irq_is_in;
40 #define _GENERAL_INTERRUPT_ENABLE (0x0008)
41 
42 __attribute__((always_inline)) static inline unsigned int irq_disable(void)
43 {
44  unsigned int state;
45  __asm__ volatile(
46  "mov.w r2, %[state]" "\n\t"
47  "bic %[gie], r2" "\n\t"
48  "nop" "\n\t"
49  "and %[gie], %[state]" "\n\t"
50  : [state] "=r"(state)
51  : [gie] "i"(_GENERAL_INTERRUPT_ENABLE)
52  : "memory"
53  );
54 
55  return state;
56 }
57 
58 __attribute__((always_inline)) static inline unsigned int irq_enable(void)
59 {
60  unsigned int state;
61  __asm__ volatile(
62  "mov.w r2, %[state]" "\n\t"
63  "nop" "\n\t"
64  "bis %[gie], r2" "\n\t"
65  "nop" "\n\t"
66  "and %[gie], %[state]" "\n\t"
67  : [state] "=r"(state)
68  : [gie] "i"(_GENERAL_INTERRUPT_ENABLE)
69  : "memory"
70  );
71 
72  return state;
73 }
74 
75 __attribute__((always_inline)) static inline void irq_restore(unsigned int state)
76 {
77  __asm__ volatile(
78  "bis %[state], r2" "\n\t"
79  "nop" "\n\t"
80  : /* no outputs */
81  : [state] "r"(state)
82  : "memory"
83  );
84 }
85 
86 __attribute__((always_inline)) static inline int irq_is_in(void)
87 {
88  return __irq_is_in;
89 }
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
96 #endif /* IRQ_ARCH_H */
irq_enable
MAYBE_INLINE unsigned irq_enable(void)
This function clears the IRQ disable bit in the status register.
irq_disable
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
irq_is_in
MAYBE_INLINE int irq_is_in(void)
Check whether called from interrupt service routine.
__irq_is_in
volatile int __irq_is_in
The current ISR state (inside or not)
irq_restore
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
irq.h
IRQ driver interface.