Skip to content

Commit 7647df1

Browse files
committed
Revert "Fixed timer bug and cleaned up"
This reverts commit cff5749.
1 parent cff5749 commit 7647df1

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

hardware/esp8266com/esp8266/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() ((__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")
117+
#define timer0_read() (ESP.getCycleCompare0())
118+
#define timer0_write(ticks) (ESP.setCycleCompare0(ticks))
119119

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

hardware/esp8266com/esp8266/cores/esp8266/Esp.h

+16
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ 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);
102104
};
103105

104106
uint32_t EspClass::getCycleCount(void)
@@ -108,6 +110,20 @@ uint32_t EspClass::getCycleCount(void)
108110
return ccount;
109111
}
110112

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+
111127
extern EspClass ESP;
112128

113129
#endif //ESP_H

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_timer.c

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

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

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

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

6765
void timer0_isr_handler(void *para){
6866
if (timer0_user_cb) {
@@ -75,11 +73,11 @@ void timer0_isr_init(){
7573
}
7674

7775
void timer0_attachInterrupt(void(*userFunc)(void)) {
78-
timer0_user_cb = userFunc;
76+
timer1_user_cb = userFunc;
7977
ETS_CCOMPARE0_ENABLE();
8078
}
8179

8280
void timer0_detachInterrupt() {
83-
timer0_user_cb = NULL;
81+
timer1_user_cb = NULL;
8482
ETS_CCOMPARE0_DISABLE();
8583
}

0 commit comments

Comments
 (0)