diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-01-27 20:09:57 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-01-27 20:09:57 +0100 |
commit | ed1ab10711cf4eb9eb7a6ca0c17ff7239322f3fd (patch) | |
tree | e57f258fb6d02c8180e142722c5b6398588a8085 /src | |
parent | d326c7e54390eeeed86922849066f5f575ff2a7c (diff) |
msp430fr5969: sleep: restore interrupt state
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/msp430fr5969lp/arch.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/arch/msp430fr5969lp/arch.cc b/src/arch/msp430fr5969lp/arch.cc index 622206b..4c8fd40 100644 --- a/src/arch/msp430fr5969lp/arch.cc +++ b/src/arch/msp430fr5969lp/arch.cc @@ -86,6 +86,13 @@ extern void loop(); volatile char run_loop = 0; #endif +inline static unsigned int irq_enabled() +{ + unsigned int sr; + __asm__ __volatile__("mov SR, %0" : "=r" (sr) : ); + return sr & GIE; +} + volatile bool sleep_done = false; // max delay: 262 ms @ 16 MHz @@ -95,6 +102,7 @@ void Arch::sleep_ms(unsigned int const ms) if (ms == 0) { return; } + int int_enabled = irq_enabled(); sleep_done = false; #if F_CPU == 16000000UL TA3CTL = TASSEL__SMCLK | ID__8; // /8 @@ -121,7 +129,9 @@ void Arch::sleep_ms(unsigned int const ms) asm volatile("nop"); __bis_SR_register(GIE | LPM2_bits); asm volatile("nop"); - __dint(); + if (!int_enabled) { + __dint(); + } } TA3CTL = TASSEL__SMCLK; } |