Skip to content

Commit 63f9129

Browse files
committed
Fixed timer bug and cleaned up
Decided to not expose compare timer in ESP object to minimize the exposure surface Fixed incorrect timer callback being used and initialized timer callbacks
1 parent 95da465 commit 63f9129

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

cores/esp8266/Arduino.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ void timer1_write(uint32_t ticks); //maximum ticks 8388607
114114
// it is auto-disabled when the compare value matches CCOUNT
115115
// it is auto-enabled when the compare value changes
116116
#define timer0_interrupted() (ETS_INTR_PENDING() & (_BV(ETS_COMPARE0_INUM)))
117-
#define timer0_read() (ESP.getCycleCompare0())
118-
#define timer0_write(ticks) (ESP.setCycleCompare0(ticks))
117+
#define timer0_read() ((__extension__({uint32_t count;__asm__ __volatile__("esync; rsr %0,ccompare0":"=a" (count));count;})))
118+
#define timer0_write(count) __asm__ __volatile__("wsr %0,ccompare0; esync"::"a" (count) : "memory")
119119

120120
void timer0_isr_init(void);
121121
void timer0_attachInterrupt(void(*userFunc)(void));

cores/esp8266/Esp.h

-16
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ class EspClass {
9999
uint32_t getFlashChipSizeByChipId(void);
100100

101101
inline uint32_t getCycleCount(void);
102-
inline uint32_t getCycleCompare0(void);
103-
inline void setCycleCompare0(uint32_t count);
104102
};
105103

106104
uint32_t EspClass::getCycleCount(void)
@@ -110,20 +108,6 @@ uint32_t EspClass::getCycleCount(void)
110108
return ccount;
111109
}
112110

113-
// this returns a value in the range of (0 - 2^32)
114-
uint32_t EspClass::getCycleCompare0(void)
115-
{
116-
uint32_t count;
117-
__asm__ __volatile__("esync; rsr %0,ccompare0":"=a" (count));
118-
return count;
119-
}
120-
121-
// this takes a value in the range of (0 - 2^32)
122-
void EspClass::setCycleCompare0(uint32_t count)
123-
{
124-
__asm__ __volatile__("wsr %0,ccompare0; esync"::"a" (count) : "memory");
125-
}
126-
127111
extern EspClass ESP;
128112

129113
#endif //ESP_H

cores/esp8266/core_esp8266_timer.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#include "pins_arduino.h"
2323
#include "c_types.h"
2424

25-
void (*timer1_user_cb)(void);
25+
typedef void(*_timercallback)(void);
26+
27+
static volatile _timercallback timer1_user_cb = NULL;
2628

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

63-
void(*timer0_user_cb)(void);
65+
static volatile _timercallback timer0_user_cb = NULL;
6466

6567
void timer0_isr_handler(void *para){
6668
if (timer0_user_cb) {
@@ -73,11 +75,11 @@ void timer0_isr_init(){
7375
}
7476

7577
void timer0_attachInterrupt(void(*userFunc)(void)) {
76-
timer1_user_cb = userFunc;
78+
timer0_user_cb = userFunc;
7779
ETS_CCOMPARE0_ENABLE();
7880
}
7981

8082
void timer0_detachInterrupt() {
81-
timer1_user_cb = NULL;
83+
timer0_user_cb = NULL;
8284
ETS_CCOMPARE0_DISABLE();
8385
}

0 commit comments

Comments
 (0)