From dfeed84ecb06c442969fe388ae05306e4c30aff2 Mon Sep 17 00:00:00 2001 From: Makuna Date: Mon, 3 Aug 2015 19:55:56 -0700 Subject: [PATCH] make compatible with existing interrupt lock class Support both the normal auto lock at all levels, and the lock at a specific level requiring different syntax --- cores/esp8266/Arduino.h | 21 --------------------- cores/esp8266/interrupts.h | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index b293bb633..fa65a2d02 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -160,27 +160,6 @@ void ets_intr_unlock(); #define interrupts() xt_rsil(0) #define noInterrupts() xt_rsil(15) -// this auto class wraps up xt_rsil so your code can be simplier, but can only be -// used in an ino or cpp files. A normal use pattern is like -// -//{ -// { -// InterruptLock(1); // this routine will allow level 2 and above -// // do work within interrupt lock here -// } -// do work outside of interrupt lock here outside its scope -//} -// -#define InterruptLock(intrLevel) \ -class _AutoDisableIntr { \ -public: \ - _AutoDisableIntr() { _savedPS = xt_rsil(intrLevel); } \ - ~_AutoDisableIntr() { xt_wsr_ps(_savedPS); } \ -private: \ - uint32_t _savedPS; \ - }; \ -_AutoDisableIntr _autoDisableIntr - #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) diff --git a/cores/esp8266/interrupts.h b/cores/esp8266/interrupts.h index d86f89b1f..78982fe45 100644 --- a/cores/esp8266/interrupts.h +++ b/cores/esp8266/interrupts.h @@ -8,23 +8,51 @@ extern "C" { #include "ets_sys.h" } +// these auto classes wrap up xt_rsil so your code can be simplier, but can only be +// used in an ino or cpp files. -#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)) -#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory") +// InterruptLock is used when you want to completely disable locks +//{ +// { +// InterruptLock lock; +// // do work within interrupt lock here +// } +// do work outside of interrupt lock here outside its scope +//} +// class InterruptLock { public: InterruptLock() { - xt_disable_interrupts(_state, 15); + _state = = xt_rsil(15); } ~InterruptLock() { - xt_enable_interrupts(_state); + xt_wsr_ps(_state); } protected: uint32_t _state; }; +// AutoInterruptLock is when you need to set a specific level, A normal use pattern is like +// +//{ +// { +// AutoInterruptLock(1); // this routine will allow level 2 and above +// // do work within interrupt lock here +// } +// do work outside of interrupt lock here outside its scope +//} +// +#define AutoInterruptLock(intrLevel) \ +class _AutoDisableIntr { \ +public: \ + _AutoDisableIntr() { _savedPS = xt_rsil(intrLevel); } \ + ~_AutoDisableIntr() { xt_wsr_ps(_savedPS); } \ +private: \ + uint32_t _savedPS; \ + }; \ +_AutoDisableIntr _autoDisableIntr #endif //INTERRUPTS_H