Contiki 2.5
interrupt-utils.c
1 /******************************************************************************
2  *
3  * $RCSfile: interrupt-utils.c,v $
4  * $Revision: 1.2 $
5  *
6  * This module provides the interface routines for setting up and
7  * controlling the various interrupt modes present on the ARM processor.
8  * Copyright 2004, R O SoftWare
9  * No guarantees, warrantees, or promises, implied or otherwise.
10  * May be used for hobby or commercial purposes provided copyright
11  * notice remains intact.
12  *
13  *****************************************************************************/
14 #include "interrupt-utils.h"
15 
16 #define IRQ_MASK 0x00000080
17 #define FIQ_MASK 0x00000040
18 #define INT_MASK (IRQ_MASK | FIQ_MASK)
19 
20 static inline unsigned __get_cpsr(void)
21 {
22  unsigned long retval;
23  asm volatile (" mrs %0, cpsr" : "=r" (retval) : /* no inputs */ );
24  return retval;
25 }
26 
27 static inline void __set_cpsr(unsigned val)
28 {
29  asm volatile (" msr cpsr_c, %0" : /* no outputs */ : "r" (val) );
30 }
31 
32 unsigned disableIRQ(void)
33 {
34  unsigned _cpsr;
35 
36  _cpsr = __get_cpsr();
37  __set_cpsr(_cpsr | IRQ_MASK);
38  return _cpsr;
39 }
40 
41 unsigned restoreIRQ(unsigned oldCPSR)
42 {
43  unsigned _cpsr;
44 
45  _cpsr = __get_cpsr();
46  __set_cpsr((_cpsr & ~IRQ_MASK) | (oldCPSR & IRQ_MASK));
47  return _cpsr;
48 }
49 
50 unsigned enableIRQ(void)
51 {
52  unsigned _cpsr;
53 
54  _cpsr = __get_cpsr();
55  __set_cpsr(_cpsr & ~IRQ_MASK);
56  return _cpsr;
57 }
58 
59 unsigned disableFIQ(void)
60 {
61  unsigned _cpsr;
62 
63  _cpsr = __get_cpsr();
64  __set_cpsr(_cpsr | FIQ_MASK);
65  return _cpsr;
66 }
67 
68 unsigned restoreFIQ(unsigned oldCPSR)
69 {
70  unsigned _cpsr;
71 
72  _cpsr = __get_cpsr();
73  __set_cpsr((_cpsr & ~FIQ_MASK) | (oldCPSR & FIQ_MASK));
74  return _cpsr;
75 }
76 
77 unsigned enableFIQ(void)
78 {
79  unsigned _cpsr;
80 
81  _cpsr = __get_cpsr();
82  __set_cpsr(_cpsr & ~FIQ_MASK);
83  return _cpsr;
84 }