Loading...
Searching...
No Matches
irq_arch.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2005-2008 by Thomas Hillebrandt and Heiko Will
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
17
18#include "VIC.h"
19#include <stdbool.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define IRQ_MASK 0x00000080
26
27static inline unsigned __get_cpsr(void)
28{
29 unsigned long retval;
30 __asm__ volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */ : "memory");
31 return retval;
32}
33
34static inline void __set_cpsr(unsigned val)
35{
36 __asm__ volatile(" msr cpsr, %0" : /* no outputs */ : "r"(val) : "memory");
37}
38
39static inline bool irq_is_in(void)
40{
41 int retval;
42 __asm__ volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */ : "memory");
43 return (retval & INTMode) == 18;
44}
45
46static inline __attribute__((always_inline)) unsigned irq_disable(void)
47{
48 unsigned _cpsr;
49
50 _cpsr = __get_cpsr();
51 __set_cpsr(_cpsr | IRQ_MASK);
52 return _cpsr;
53}
54
55static inline __attribute__((always_inline)) void irq_restore(unsigned oldCPSR)
56{
57 __set_cpsr(oldCPSR);
58}
59
60static inline __attribute__((always_inline)) unsigned irq_enable(void)
61{
62 unsigned _cpsr;
63
64 _cpsr = __get_cpsr();
65 __set_cpsr(_cpsr & ~IRQ_MASK);
66 return _cpsr;
67}
68
69static inline __attribute__((always_inline)) bool irq_is_enabled(void)
70{
71 return !(__get_cpsr() & IRQ_MASK);
72}
73
74#ifdef __cplusplus
75}
76#endif
77
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.