dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_irq.c
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 /* Project Includes */
32 #include "pios.h"
33 
34 /* Private Function Prototypes */
35 
36 /* Local Variables */
37 /* The nesting counter ensures, that interrupts won't be enabled so long nested functions disable them */
38 static uint32_t nested_ctr;
39 
40 /* Stored priority level before IRQ has been disabled (important for co-existence with vPortEnterCritical) */
41 static uint32_t prev_primask;
42 
47 int32_t PIOS_IRQ_Disable(void)
48 {
49  /* XXX TODO: This is racy */
50  /* Get current priority if nested level == 0 */
51  if (!nested_ctr) {
52  __asm volatile (" mrs %0, primask\n":"=r" (prev_primask)
53  );
54  }
55 
56  /* Disable interrupts */
57  __asm volatile (" mov r0, #1 \n" " msr primask, r0\n":::"r0");
58 
59  ++nested_ctr;
60 
61  /* No error */
62  return 0;
63 }
64 
70 int32_t PIOS_IRQ_Enable(void)
71 {
72  /* Check for nesting error */
73  if (nested_ctr == 0) {
74  /* Nesting error */
75  return -1;
76  }
77 
78  /* Decrease nesting level */
79  --nested_ctr;
80 
81  /* Set back previous priority once nested level reached 0 again */
82  if (nested_ctr == 0) {
83  __asm volatile (" msr primask, %0\n"::"r" (prev_primask)
84  );
85  }
86 
87  /* No error */
88  return 0;
89 }
90 
91 bool PIOS_IRQ_InISR(void)
92 {
93  return (__get_IPSR() & 0xff) != 0;
94 }
95 
int32_t PIOS_IRQ_Enable(void)
Definition: pios_irq.c:53
Main PiOS header to include all the compiled in PiOS options.
static uint32_t nested_ctr
Definition: pios_irq.c:38
bool PIOS_IRQ_InISR(void)
Definition: pios_irq.c:61
int32_t PIOS_IRQ_Disable(void)
Definition: pios_irq.c:40
static uint32_t prev_primask
Definition: pios_irq.c:41