-
Notifications
You must be signed in to change notification settings - Fork 7
/
arm.h
48 lines (36 loc) · 1.05 KB
/
arm.h
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
#ifndef SA_ARM_h
#define SA_ARM_h
#ifdef ARDUINO
#include <Arduino.h>
#else
#include <stdint.h>
#endif
/******************** HELPERS ***********************/
static __inline__ uint8_t SA_iSeiRetVal(void)
{
__asm__ __volatile__ ("cpsie i" ::);
return 1;
}
static __inline__ uint8_t SA_iCliRetVal(void)
{
__asm__ __volatile__ ("cpsid i" ::);
return 1;
}
static __inline__ void SA_iRestore(const uint32_t *__s)
{
uint32_t res = *__s;
__asm__ __volatile__ ("MSR primask, %0" : : "r" (res) );
}
static __inline__ uint32_t SA_iGetIReg( void )
{
uint32_t reg;
__asm__ __volatile__ ("MRS %0, primask" : "=r" (reg) );
return reg;
}
#define SA_ATOMIC_RESTORESTATE uint32_t _sa_saved \
__attribute__((__cleanup__(SA_iRestore))) = SA_iGetIReg()
/******************** MACRO ***********************/
#define ATOMIC() \
for ( SA_ATOMIC_RESTORESTATE, _sa_done = SA_iCliRetVal(); \
_sa_done; _sa_done = 0 )
#endif