27
27
#define EXCLUSIVE_ACCESS (!defined (__CORTEX_M0) && !defined (__CORTEX_M0PLUS))
28
28
29
29
static volatile uint32_t interrupt_enable_counter = 0 ;
30
- static volatile uint32_t critical_primask = 0 ;
30
+ static volatile uint32_t critical_interrupts_disabled = 0 ;
31
+
32
+ static inline uint32_t get_interrupts_disabled (void )
33
+ {
34
+ #if defined(__CORTEX_A9 )
35
+ uint32_t interrupts_disabled = (__get_CPSR () & 0x80 ) >> 7 ;
36
+ #else
37
+ uint32_t interrupts_disabled = __get_PRIMASK ();
38
+ #endif
39
+ return interrupts_disabled ;
40
+ }
31
41
32
42
void core_util_critical_section_enter ()
33
43
{
34
- uint32_t primask = __get_PRIMASK (); /* get the current interrupt enabled state */
44
+ uint32_t interrupts_disabled = get_interrupts_disabled ();
35
45
__disable_irq ();
36
46
37
- /* Save the interrupt enabled state as it was prior to any nested critical section lock use */
47
+ /* Save the interrupt disabled state as it was prior to any nested critical section lock use */
38
48
if (!interrupt_enable_counter ) {
39
- critical_primask = primask & 0x1 ;
49
+ critical_interrupts_disabled = interrupts_disabled & 0x1 ;
40
50
}
41
51
42
52
/* If the interrupt_enable_counter overflows or we are in a nested critical section and interrupts
43
53
are enabled, then something has gone badly wrong thus assert an error.
44
54
*/
45
55
MBED_ASSERT (interrupt_enable_counter < UINT32_MAX );
46
56
if (interrupt_enable_counter > 0 ) {
47
- MBED_ASSERT (primask & 0x1 );
57
+ MBED_ASSERT (interrupts_disabled & 0x1 );
48
58
}
49
59
interrupt_enable_counter ++ ;
50
60
}
@@ -54,16 +64,16 @@ void core_util_critical_section_exit()
54
64
/* If critical_section_enter has not previously been called, do nothing */
55
65
if (interrupt_enable_counter ) {
56
66
57
- uint32_t primask = __get_PRIMASK (); /* get the current interrupt enabled state */
67
+ uint32_t interrupts_disabled = get_interrupts_disabled (); /* get the current interrupt disabled state */
58
68
59
- MBED_ASSERT (primask & 0x1 ); /* Interrupts must be disabled on invoking an exit from a critical section */
69
+ MBED_ASSERT (interrupts_disabled & 0x1 ); /* Interrupts must be disabled on invoking an exit from a critical section */
60
70
61
71
interrupt_enable_counter -- ;
62
72
63
73
/* Only re-enable interrupts if we are exiting the last of the nested critical sections and
64
74
interrupts were enabled on entry to the first critical section.
65
75
*/
66
- if (!interrupt_enable_counter && !critical_primask ) {
76
+ if (!interrupt_enable_counter && !critical_interrupts_disabled ) {
67
77
__enable_irq ();
68
78
}
69
79
}
0 commit comments