irq_arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
21 #include "VIC.h"
22 #include <stdbool.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define IRQ_MASK 0x00000080
29 
30 static inline unsigned __get_cpsr(void)
31 {
32  unsigned long retval;
33  __asm__ volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */ : "memory");
34  return retval;
35 }
36 
37 static inline void __set_cpsr(unsigned val)
38 {
39  __asm__ volatile(" msr cpsr, %0" : /* no outputs */ : "r"(val) : "memory");
40 }
41 
42 static inline bool irq_is_in(void)
43 {
44  int retval;
45  __asm__ volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */ : "memory");
46  return (retval & INTMode) == 18;
47 }
48 
49 static inline __attribute__((always_inline)) unsigned irq_disable(void)
50 {
51  unsigned _cpsr;
52 
53  _cpsr = __get_cpsr();
54  __set_cpsr(_cpsr | IRQ_MASK);
55  return _cpsr;
56 }
57 
58 static inline __attribute__((always_inline)) void irq_restore(unsigned oldCPSR)
59 {
60  __set_cpsr(oldCPSR);
61 }
62 
63 static inline __attribute__((always_inline)) unsigned irq_enable(void)
64 {
65  unsigned _cpsr;
66 
67  _cpsr = __get_cpsr();
68  __set_cpsr(_cpsr & ~IRQ_MASK);
69  return _cpsr;
70 }
71 
72 static inline __attribute__((always_inline)) bool irq_is_enabled(void)
73 {
74  return !(__get_cpsr() & IRQ_MASK);
75 }
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
MAYBE_INLINE bool irq_is_enabled(void)
Test if IRQs are currently enabled.
MAYBE_INLINE unsigned irq_enable(void)
This function clears the IRQ disable bit in the status register.
MAYBE_INLINE bool irq_is_in(void)
Check whether called from interrupt service routine.