import cbaos v0.1
[cbaos.git] / arch / arm-cortex-m0 / include / lock.h
blob262d606651fc042dc2cc1feec097c94438aeced9
1 #ifndef _ARCH_LOCK_H_
2 #define _ARCH_LOCK_H_
4 #include <types.h>
6 struct lock {
7 u32 primask;
8 };
10 #define LOCK_INIT (struct lock) {}
12 static inline void lock_init(struct lock *lock)
13 {
14 }
16 // source:
17 // http://embeddedfreak.wordpress.com/2009/08/14/cortex-m3-global-interruptexception-control/
18 //
19 // confirm this is correct by printing primask before after
21 // note arm architecture v7m rm... setting PRIMASK raises priority to 0
23 static inline void lock(struct lock *lock)
24 {
25 u32 tmp;
26 asm volatile (
27 "mrs %0, PRIMASK\n\t"
28 "cpsid i\n\t"
29 : "=r" (tmp) );
30 lock->primask = tmp;
31 }
33 static inline void unlock(struct lock *lock)
34 {
35 asm volatile (
36 "msr PRIMASK, %0\n\t"
37 : : "r" (lock->primask) );
38 }
40 #endif