From 367962d89e1f5e33c9d93880c613351d6a2d96a5 Mon Sep 17 00:00:00 2001 From: Makuna Date: Thu, 7 May 2015 12:29:37 -0700 Subject: [PATCH] refactored xt_disable_intterupts to accept level due to the rsil requirement that the level be a constant, the method was moved into a macro --- cores/esp8266/Arduino.h | 14 ++++++++++---- cores/esp8266/core_esp8266_wiring_digital.c | 16 ++-------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 430cf6f02..51aa65602 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -124,11 +124,17 @@ void timer1_write(uint32_t ticks); //maximum ticks 8388607 void ets_intr_lock(); void ets_intr_unlock(); -void xt_enable_interrupts(); -void xt_disable_interrupts(); +// level (0-15), +// level 15 will disable ALL interrupts, +// level 0 will disable most software interrupts +// +#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) "; esync; isync; dsync" : "=a" (state)) +#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; esync" :: "a" (state) : "memory") -#define interrupts() xt_enable_interrupts(); -#define noInterrupts() xt_disable_interrupts(); +extern uint32_t interruptsState; + +#define interrupts() xt_enable_interrupts(interruptsState) +#define noInterrupts() xt_disable_interrupts(interruptsState, 15) #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) diff --git a/cores/esp8266/core_esp8266_wiring_digital.c b/cores/esp8266/core_esp8266_wiring_digital.c index 7cdfa3fbc..54c2b557b 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.c +++ b/cores/esp8266/core_esp8266_wiring_digital.c @@ -139,20 +139,8 @@ extern void __detachInterrupt(uint8_t pin) { } } -static uint32_t interruptState = 0; - -void xt_disable_interrupts() -{ - __asm__ __volatile__("rsil %0,15":"=a" (interruptState)); - __asm__("esync"); - __asm__("isync"); - __asm__("dsync"); -} -void xt_enable_interrupts() -{ - __asm__ __volatile__("wsr %0,ps"::"a" (interruptState) : "memory"); - __asm__("esync"); -} +// stored state for the noInterrupts/interrupts methods +uint32_t interruptsState = 0; void initPins() { //Disable UART interrupts