Skip to content

Commit

Permalink
Fixed timer bug and cleaned up
Browse files Browse the repository at this point in the history
Decided to not expose compare timer in ESP object to minimize the
exposure surface
Fixed incorrect timer callback being used and initialized timer
callbacks
  • Loading branch information
Makuna committed May 25, 2015
1 parent 95da465 commit 63f9129
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() (ESP.getCycleCompare0())
#define timer0_write(ticks) (ESP.setCycleCompare0(ticks))
#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")

void timer0_isr_init(void);
void timer0_attachInterrupt(void(*userFunc)(void));
Expand Down
16 changes: 0 additions & 16 deletions cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ 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)
Expand All @@ -110,20 +108,6 @@ 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
10 changes: 6 additions & 4 deletions cores/esp8266/core_esp8266_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include "pins_arduino.h"
#include "c_types.h"

void (*timer1_user_cb)(void);
typedef void(*_timercallback)(void);

static volatile _timercallback timer1_user_cb = NULL;

void timer1_isr_handler(void *para){
if((T1C & ((1 << TCAR) | (1 << TCIT))) == 0) TEIE &= ~TEIE1;//edge int disable
Expand Down Expand Up @@ -60,7 +62,7 @@ void timer1_disable(){
T1I = 0;
}

void(*timer0_user_cb)(void);
static volatile _timercallback timer0_user_cb = NULL;

void timer0_isr_handler(void *para){
if (timer0_user_cb) {
Expand All @@ -73,11 +75,11 @@ void timer0_isr_init(){
}

void timer0_attachInterrupt(void(*userFunc)(void)) {
timer1_user_cb = userFunc;
timer0_user_cb = userFunc;
ETS_CCOMPARE0_ENABLE();
}

void timer0_detachInterrupt() {
timer1_user_cb = NULL;
timer0_user_cb = NULL;
ETS_CCOMPARE0_DISABLE();
}

0 comments on commit 63f9129

Please sign in to comment.