From 4ad7f3bf0701fb56a266e9c9a0109faa5c8823bc Mon Sep 17 00:00:00 2001 From: Makuna Date: Fri, 29 May 2015 08:36:11 -0700 Subject: [PATCH] Revert "Fixed timer bug and cleaned up" This reverts commit cff57490feae778b68740e0ef878d4521ae4eb2b. --- cores/esp8266/Arduino.h | 4 ++-- cores/esp8266/Esp.h | 16 ++++++++++++++++ cores/esp8266/core_esp8266_timer.c | 10 ++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index dcaa47b09..7ebc77b79 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -114,8 +114,8 @@ void timer1_write(uint32_t ticks); //maximum ticks 8388607 // it is auto-disabled when the compare value matches CCOUNT // it is auto-enabled when the compare value changes #define timer0_interrupted() (ETS_INTR_PENDING() & (_BV(ETS_COMPARE0_INUM))) -#define timer0_read() ((__extension__({uint32_t count;__asm__ __volatile__("esync; rsr %0,ccompare0":"=a" (count));count;}))) -#define timer0_write(count) __asm__ __volatile__("wsr %0,ccompare0; esync"::"a" (count) : "memory") +#define timer0_read() (ESP.getCycleCompare0()) +#define timer0_write(ticks) (ESP.setCycleCompare0(ticks)) void timer0_isr_init(void); void timer0_attachInterrupt(void(*userFunc)(void)); diff --git a/cores/esp8266/Esp.h b/cores/esp8266/Esp.h index fc5237196..c887c89e9 100644 --- a/cores/esp8266/Esp.h +++ b/cores/esp8266/Esp.h @@ -99,6 +99,8 @@ class EspClass { uint32_t getFlashChipSizeByChipId(void); inline uint32_t getCycleCount(void); + inline uint32_t getCycleCompare0(void); + inline void setCycleCompare0(uint32_t count); }; uint32_t EspClass::getCycleCount(void) @@ -108,6 +110,20 @@ uint32_t EspClass::getCycleCount(void) return ccount; } +// this returns a value in the range of (0 - 2^32) +uint32_t EspClass::getCycleCompare0(void) +{ + uint32_t count; + __asm__ __volatile__("esync; rsr %0,ccompare0":"=a" (count)); + return count; +} + +// this takes a value in the range of (0 - 2^32) +void EspClass::setCycleCompare0(uint32_t count) +{ + __asm__ __volatile__("wsr %0,ccompare0; esync"::"a" (count) : "memory"); +} + extern EspClass ESP; #endif //ESP_H diff --git a/cores/esp8266/core_esp8266_timer.c b/cores/esp8266/core_esp8266_timer.c index b9b2f1256..979ab0bfc 100644 --- a/cores/esp8266/core_esp8266_timer.c +++ b/cores/esp8266/core_esp8266_timer.c @@ -22,9 +22,7 @@ #include "pins_arduino.h" #include "c_types.h" -typedef void(*_timercallback)(void); - -static volatile _timercallback timer1_user_cb = NULL; +void (*timer1_user_cb)(void); void timer1_isr_handler(void *para){ if((T1C & ((1 << TCAR) | (1 << TCIT))) == 0) TEIE &= ~TEIE1;//edge int disable @@ -62,7 +60,7 @@ void timer1_disable(){ T1I = 0; } -static volatile _timercallback timer0_user_cb = NULL; +void(*timer0_user_cb)(void); void timer0_isr_handler(void *para){ if (timer0_user_cb) { @@ -75,11 +73,11 @@ void timer0_isr_init(){ } void timer0_attachInterrupt(void(*userFunc)(void)) { - timer0_user_cb = userFunc; + timer1_user_cb = userFunc; ETS_CCOMPARE0_ENABLE(); } void timer0_detachInterrupt() { - timer0_user_cb = NULL; + timer1_user_cb = NULL; ETS_CCOMPARE0_DISABLE(); } \ No newline at end of file