mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
@ -101,13 +101,29 @@ void yield(void);
|
||||
#define timer1_enabled() ((T1C & (1 << TCTE)) != 0)
|
||||
#define timer1_interrupted() ((T1C & (1 << TCIS)) != 0)
|
||||
|
||||
typedef void(*timercallback)(void);
|
||||
|
||||
void timer1_isr_init(void);
|
||||
void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload);
|
||||
void timer1_disable(void);
|
||||
void timer1_attachInterrupt(void (*userFunc)(void));
|
||||
void timer1_attachInterrupt(timercallback userFunc);
|
||||
void timer1_detachInterrupt(void);
|
||||
void timer1_write(uint32_t ticks); //maximum ticks 8388607
|
||||
|
||||
// timer0 is a special CPU timer that has very high resolution but with
|
||||
// limited control.
|
||||
// it uses CCOUNT (ESP.GetCycleCount()) as the non-resetable timer counter
|
||||
// it does not support divide, type, or reload flags
|
||||
// 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")
|
||||
|
||||
void timer0_isr_init(void);
|
||||
void timer0_attachInterrupt(timercallback userFunc);
|
||||
void timer0_detachInterrupt(void);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
|
@ -20,22 +20,33 @@
|
||||
*/
|
||||
#include "wiring_private.h"
|
||||
#include "pins_arduino.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "c_types.h"
|
||||
#include "ets_sys.h"
|
||||
|
||||
void (*timer1_user_cb)(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/ ------------------------------------------------------------------ -
|
||||
// timer 1
|
||||
|
||||
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
|
||||
if ((T1C & ((1 << TCAR) | (1 << TCIT))) == 0) TEIE &= ~TEIE1;//edge int disable
|
||||
T1I = 0;
|
||||
if(timer1_user_cb) timer1_user_cb();
|
||||
if (timer1_user_cb) timer1_user_cb();
|
||||
}
|
||||
|
||||
void timer1_isr_init(){
|
||||
ETS_FRC_TIMER1_INTR_ATTACH(timer1_isr_handler, NULL);
|
||||
}
|
||||
|
||||
void timer1_attachInterrupt(void (*userFunc)(void)) {
|
||||
void timer1_attachInterrupt(timercallback userFunc) {
|
||||
timer1_user_cb = userFunc;
|
||||
ETS_FRC1_INTR_ENABLE();
|
||||
}
|
||||
@ -52,11 +63,39 @@ void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload){
|
||||
}
|
||||
|
||||
void timer1_write(uint32_t ticks){
|
||||
T1L = ((ticks) & 0x7FFFFF);
|
||||
if((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable
|
||||
T1L = ((ticks)& 0x7FFFFF);
|
||||
if ((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable
|
||||
}
|
||||
|
||||
void timer1_disable(){
|
||||
T1C = 0;
|
||||
T1I = 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// timer 0
|
||||
|
||||
static volatile timercallback timer0_user_cb = NULL;
|
||||
|
||||
void timer0_isr_handler(void* para){
|
||||
if (timer0_user_cb) {
|
||||
timer0_user_cb();
|
||||
}
|
||||
}
|
||||
|
||||
void timer0_isr_init(){
|
||||
ETS_CCOMPARE0_INTR_ATTACH(timer0_isr_handler, NULL);
|
||||
}
|
||||
|
||||
void timer0_attachInterrupt(timercallback userFunc) {
|
||||
timer0_user_cb = userFunc;
|
||||
ETS_CCOMPARE0_ENABLE();
|
||||
}
|
||||
|
||||
void timer0_detachInterrupt() {
|
||||
timer0_user_cb = NULL;
|
||||
ETS_CCOMPARE0_DISABLE();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user