2010-09-22 15:10:42 +02:00
|
|
|
/* Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will
|
2013-08-16 10:20:23 +02:00
|
|
|
* This file is part of RIOT.
|
|
|
|
*
|
2013-11-22 20:47:05 +01:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
2013-08-16 10:20:23 +02:00
|
|
|
* Public License. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
#include "VIC.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#define IRQ_MASK 0x00000080
|
|
|
|
#define FIQ_MASK 0x00000040
|
|
|
|
#define INT_MASK (IRQ_MASK | FIQ_MASK)
|
|
|
|
|
|
|
|
static inline unsigned __get_cpsr(void)
|
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned long retval;
|
|
|
|
asm volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */);
|
|
|
|
return retval;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int inISR(void)
|
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
int retval;
|
|
|
|
asm volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */);
|
|
|
|
return (retval & INTMode) == 18;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __set_cpsr(unsigned val)
|
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
asm volatile(" msr cpsr, %0" : /* no outputs */ : "r"(val));
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned disableIRQ(void)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
unsigned restoreIRQ(unsigned oldCPSR)
|
|
|
|
{
|
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) | (oldCPSR & IRQ_MASK));
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned IRQenabled(void)
|
|
|
|
{
|
2013-06-07 17:21:11 +02:00
|
|
|
unsigned _cpsr;
|
|
|
|
|
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
return (_cpsr & IRQ_MASK);
|
|
|
|
}
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
unsigned enableIRQ(void)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
unsigned disableFIQ(void)
|
|
|
|
{
|
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 | FIQ_MASK);
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned restoreFIQ(unsigned oldCPSR)
|
|
|
|
{
|
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 & ~FIQ_MASK) | (oldCPSR & FIQ_MASK));
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned enableFIQ(void)
|
|
|
|
{
|
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 & ~FIQ_MASK);
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|