Blame view

RIOT/cpu/arm7_common/VIC.c 1.75 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  /* Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will
   * 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.
   */
  
  #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)
  {
      unsigned long retval;
      __asm__ volatile(" mrs  %0, cpsr" : "=r"(retval) : /* no inputs */);
      return retval;
  }
  
  int irq_is_in(void)
  {
      int retval;
      __asm__ volatile(" mrs  %0, cpsr" : "=r"(retval) : /* no inputs */);
      return (retval & INTMode) == 18;
  }
  
  static inline void __set_cpsr(unsigned val)
  {
      __asm__ volatile(" msr  cpsr, %0" : /* no outputs */ : "r"(val));
  }
  
  unsigned irq_disable(void)
  {
      unsigned _cpsr;
  
      _cpsr = __get_cpsr();
      __set_cpsr(_cpsr | IRQ_MASK);
      return _cpsr;
  }
  
  unsigned irq_restore(unsigned oldCPSR)
  {
      unsigned _cpsr;
  
      _cpsr = __get_cpsr();
      __set_cpsr((_cpsr & ~IRQ_MASK) | (oldCPSR & IRQ_MASK));
      return _cpsr;
  }
  
  unsigned IRQenabled(void)
  {
      unsigned _cpsr;
  
      _cpsr = __get_cpsr();
      return (_cpsr & IRQ_MASK);
  }
  
  unsigned irq_enable(void)
  {
      unsigned _cpsr;
  
      _cpsr = __get_cpsr();
      __set_cpsr(_cpsr & ~IRQ_MASK);
      return _cpsr;
  }
  
  unsigned disableFIQ(void)
  {
      unsigned _cpsr;
  
      _cpsr = __get_cpsr();
      __set_cpsr(_cpsr | FIQ_MASK);
      return _cpsr;
  }
  
  unsigned restoreFIQ(unsigned oldCPSR)
  {
      unsigned _cpsr;
  
      _cpsr = __get_cpsr();
      __set_cpsr((_cpsr & ~FIQ_MASK) | (oldCPSR & FIQ_MASK));
      return _cpsr;
  }
  
  unsigned enableFIQ(void)
  {
      unsigned _cpsr;
  
      _cpsr = __get_cpsr();
      __set_cpsr(_cpsr & ~FIQ_MASK);
      return _cpsr;
  }