From c328452651ed9735b56b021b4e26dd82de37cba9 Mon Sep 17 00:00:00 2001 From: Makuna <Makuna@hotmail.com> Date: Wed, 6 May 2015 08:42:38 -0700 Subject: [PATCH] true interrupt enable and disable plus expose cycle count for bit bang timing --- cores/esp8266/Arduino.h | 7 +++++-- cores/esp8266/Esp.h | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 6d039683b..430cf6f02 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -124,8 +124,11 @@ void timer1_write(uint32_t ticks); //maximum ticks 8388607 void ets_intr_lock(); void ets_intr_unlock(); -#define interrupts() ets_intr_unlock(); -#define noInterrupts() ets_intr_lock(); +void xt_enable_interrupts(); +void xt_disable_interrupts(); + +#define interrupts() xt_enable_interrupts(); +#define noInterrupts() xt_disable_interrupts(); #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) diff --git a/cores/esp8266/Esp.h b/cores/esp8266/Esp.h index b3d836c79..9750dd312 100644 --- a/cores/esp8266/Esp.h +++ b/cores/esp8266/Esp.h @@ -95,8 +95,16 @@ class EspClass { FlashMode_t getFlashChipMode(void); uint32_t getFlashChipSizeByChipId(void); + inline uint32_t getCycleCount(void); }; +uint32_t EspClass::getCycleCount(void) +{ + uint32_t ccount; + __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); + return ccount; +} + extern EspClass ESP; #endif //ESP_H