2020-05-15 11:18:52 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will
|
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2013-08-16 10:20:23 +02:00
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2020-05-15 11:18:52 +02:00
|
|
|
/**
|
|
|
|
* @ingroup cpu_arm7_common
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Implementation of the kernels irq interface
|
|
|
|
*
|
|
|
|
* @author Heiko Will <hwill@inf.fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef IRQ_ARCH_H
|
|
|
|
#define IRQ_ARCH_H
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
#include "VIC.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2020-05-15 11:18:52 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
#define IRQ_MASK 0x00000080
|
|
|
|
|
|
|
|
static inline unsigned __get_cpsr(void)
|
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned long retval;
|
2019-04-24 16:29:30 +02:00
|
|
|
__asm__ volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */ : "memory");
|
2013-06-21 03:52:57 +02:00
|
|
|
return retval;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-05-15 11:18:52 +02:00
|
|
|
static inline void __set_cpsr(unsigned val)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2020-05-15 11:18:52 +02:00
|
|
|
__asm__ volatile(" msr cpsr, %0" : /* no outputs */ : "r"(val) : "memory");
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2021-12-08 15:53:15 +01:00
|
|
|
static inline bool irq_is_in(void)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2020-05-15 11:18:52 +02:00
|
|
|
int retval;
|
|
|
|
__asm__ volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */ : "memory");
|
|
|
|
return (retval & INTMode) == 18;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-05-15 11:18:52 +02:00
|
|
|
static inline __attribute__((always_inline)) unsigned irq_disable(void)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
__set_cpsr(_cpsr | IRQ_MASK);
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-05-15 11:18:52 +02:00
|
|
|
static inline __attribute__((always_inline)) void irq_restore(unsigned oldCPSR)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2020-05-15 11:32:47 +02:00
|
|
|
__set_cpsr(oldCPSR);
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2020-05-15 11:18:52 +02:00
|
|
|
static inline __attribute__((always_inline)) unsigned irq_enable(void)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
__set_cpsr(_cpsr & ~IRQ_MASK);
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
2020-05-15 11:18:52 +02:00
|
|
|
|
2021-12-08 15:53:15 +01:00
|
|
|
static inline __attribute__((always_inline)) bool irq_is_enabled(void)
|
2021-08-23 14:04:41 +02:00
|
|
|
{
|
|
|
|
return !(__get_cpsr() & IRQ_MASK);
|
|
|
|
}
|
|
|
|
|
2020-05-15 11:18:52 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* IRQ_ARCH_H */
|
|
|
|
/** @} */
|