mirror of https://github.com/jscrane/r65emu.git
esp8266 timer_create
This commit is contained in:
parent
7d69cbd34e
commit
9a643171a6
18
timed.cpp
18
timed.cpp
|
@ -5,19 +5,24 @@
|
||||||
#include <driverlib/interrupt.h>
|
#include <driverlib/interrupt.h>
|
||||||
#include <driverlib/sysctl.h>
|
#include <driverlib/sysctl.h>
|
||||||
#include <driverlib/timer.h>
|
#include <driverlib/timer.h>
|
||||||
|
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
#include <ets_sys.h>
|
||||||
|
#include <osapi.h>
|
||||||
|
#include <os_type.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "timed.h"
|
#include "timed.h"
|
||||||
|
|
||||||
#if defined(__LM4F120H5QR__)
|
#if defined(__LM4F120H5QR__)
|
||||||
static void (*client_handler)(void);
|
static handler_t client_handler;
|
||||||
|
|
||||||
static void timer0isr(void) {
|
static void timer0isr(void) {
|
||||||
ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
|
ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
|
||||||
client_handler();
|
client_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_create(unsigned freq, void (*handler)(void)) {
|
void timer_create(unsigned freq, handler_t handler) {
|
||||||
client_handler = handler;
|
client_handler = handler;
|
||||||
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
|
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
|
||||||
ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
|
ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
|
||||||
|
@ -29,10 +34,17 @@ void timer_create(unsigned freq, void (*handler)(void)) {
|
||||||
}
|
}
|
||||||
#elif defined(ESP_PLATFORM)
|
#elif defined(ESP_PLATFORM)
|
||||||
|
|
||||||
void timer_create(unsigned freq, void (*handler)(void)) {
|
void timer_create(unsigned freq, handler_t handler) {
|
||||||
hw_timer_t *timer = timerBegin(3, 80, true); // prescaler of 80
|
hw_timer_t *timer = timerBegin(3, 80, true); // prescaler of 80
|
||||||
timerAttachInterrupt(timer, handler, true);
|
timerAttachInterrupt(timer, handler, true);
|
||||||
timerAlarmWrite(timer, 1000000 / freq, true);
|
timerAlarmWrite(timer, 1000000 / freq, true);
|
||||||
timerAlarmEnable(timer);
|
timerAlarmEnable(timer);
|
||||||
}
|
}
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
|
||||||
|
void timer_create(unsigned freq, handler_t handler) {
|
||||||
|
static os_timer_t t;
|
||||||
|
os_timer_setfn(&t, (os_timer_func_t *)handler, 0);
|
||||||
|
os_timer_arm(&t, 1000 / freq, true);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue