File tree 3 files changed +22
-8
lines changed
hardware/esp8266com/esp8266/cores/esp8266
3 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -114,8 +114,8 @@ void timer1_write(uint32_t ticks); //maximum ticks 8388607
114
114
// it is auto-disabled when the compare value matches CCOUNT
115
115
// it is auto-enabled when the compare value changes
116
116
#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) )
119
119
120
120
void timer0_isr_init (void );
121
121
void timer0_attachInterrupt (void (* userFunc )(void ));
Original file line number Diff line number Diff line change @@ -99,6 +99,8 @@ class EspClass {
99
99
uint32_t getFlashChipSizeByChipId (void );
100
100
101
101
inline uint32_t getCycleCount (void );
102
+ inline uint32_t getCycleCompare0 (void );
103
+ inline void setCycleCompare0 (uint32_t count);
102
104
};
103
105
104
106
uint32_t EspClass::getCycleCount (void )
@@ -108,6 +110,20 @@ uint32_t EspClass::getCycleCount(void)
108
110
return ccount;
109
111
}
110
112
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
+
111
127
extern EspClass ESP;
112
128
113
129
#endif // ESP_H
Original file line number Diff line number Diff line change 22
22
#include "pins_arduino.h"
23
23
#include "c_types.h"
24
24
25
- typedef void (* _timercallback )(void );
26
-
27
- static volatile _timercallback timer1_user_cb = NULL ;
25
+ void (* timer1_user_cb )(void );
28
26
29
27
void timer1_isr_handler (void * para ){
30
28
if ((T1C & ((1 << TCAR ) | (1 << TCIT ))) == 0 ) TEIE &= ~TEIE1 ;//edge int disable
@@ -62,7 +60,7 @@ void timer1_disable(){
62
60
T1I = 0 ;
63
61
}
64
62
65
- static volatile _timercallback timer0_user_cb = NULL ;
63
+ void ( * timer0_user_cb )( void ) ;
66
64
67
65
void timer0_isr_handler (void * para ){
68
66
if (timer0_user_cb ) {
@@ -75,11 +73,11 @@ void timer0_isr_init(){
75
73
}
76
74
77
75
void timer0_attachInterrupt (void (* userFunc )(void )) {
78
- timer0_user_cb = userFunc ;
76
+ timer1_user_cb = userFunc ;
79
77
ETS_CCOMPARE0_ENABLE ();
80
78
}
81
79
82
80
void timer0_detachInterrupt () {
83
- timer0_user_cb = NULL ;
81
+ timer1_user_cb = NULL ;
84
82
ETS_CCOMPARE0_DISABLE ();
85
83
}
You can’t perform that action at this time.
0 commit comments