Rename opensdk dir to open_esplibs
This commit is contained in:
parent
2ecbf1d584
commit
eee4a3660c
8 changed files with 1 additions and 1 deletions
89
open_esplibs/libmain/timers.c
Normal file
89
open_esplibs/libmain/timers.c
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#include "etstimer.h"
|
||||
|
||||
struct timer_list_st {
|
||||
struct timer_list_st *next;
|
||||
ETSTimer *timer;
|
||||
};
|
||||
|
||||
static struct timer_list_st *timer_list;
|
||||
static uint8_t armed_timer_count;
|
||||
|
||||
void sdk_os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg) {
|
||||
struct timer_list_st *entry = 0;
|
||||
struct timer_list_st *new_entry;
|
||||
struct timer_list_st **tailptr;
|
||||
|
||||
if (timer_list) {
|
||||
for (entry = timer_list; ; entry = entry->next) {
|
||||
if (entry->timer == ptimer) {
|
||||
if (ptimer->timer_arg == parg && ptimer->timer_func == pfunction) {
|
||||
return;
|
||||
}
|
||||
if (ptimer->timer_handle) {
|
||||
if (!xTimerDelete(ptimer->timer_handle, 50)) {
|
||||
printf("Timer Delete Failed\n");
|
||||
}
|
||||
armed_timer_count--;
|
||||
}
|
||||
ptimer->timer_func = pfunction;
|
||||
ptimer->timer_arg = parg;
|
||||
ptimer->timer_handle = 0;
|
||||
ptimer->timer_ms = 0;
|
||||
return;
|
||||
}
|
||||
if (!entry->next) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ptimer->timer_func = pfunction;
|
||||
ptimer->timer_arg = parg;
|
||||
ptimer->timer_handle = 0;
|
||||
ptimer->timer_ms = 0;
|
||||
new_entry = (struct timer_list_st *)pvPortMalloc(8);
|
||||
new_entry->timer = ptimer;
|
||||
new_entry->next = 0;
|
||||
tailptr = &entry->next;
|
||||
if (!timer_list) {
|
||||
tailptr = &timer_list;
|
||||
}
|
||||
*tailptr = new_entry;
|
||||
}
|
||||
|
||||
void sdk_os_timer_arm(ETSTimer *ptimer, uint32_t milliseconds, bool repeat_flag) {
|
||||
if (!ptimer->timer_handle) {
|
||||
ptimer->timer_repeat = repeat_flag;
|
||||
ptimer->timer_ms = milliseconds;
|
||||
ptimer->timer_handle = xTimerCreate(0, milliseconds/10, repeat_flag, ptimer->timer_arg, ptimer->timer_func);
|
||||
armed_timer_count++;
|
||||
if (!ptimer->timer_handle) {
|
||||
//FIXME: should print an error? (original code doesn't)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ptimer->timer_repeat != repeat_flag) {
|
||||
ptimer->timer_repeat = repeat_flag;
|
||||
// FIXME: This is wrong. The original code is directly modifying
|
||||
// internal FreeRTOS structures to try to change the uxAutoReload of an
|
||||
// existing timer. The correct way to do this is probably to use
|
||||
// xTimerDelete and then xTimerCreate to recreate the timer with a
|
||||
// different uxAutoReload setting.
|
||||
((uint32_t *)ptimer->timer_handle)[7] = repeat_flag;
|
||||
}
|
||||
if (ptimer->timer_ms != milliseconds) {
|
||||
ptimer->timer_ms = milliseconds;
|
||||
xTimerChangePeriod(ptimer->timer_handle, milliseconds/10, 10);
|
||||
}
|
||||
if (!xTimerStart(ptimer->timer_handle, 50)) {
|
||||
printf("Timer Start Failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
void sdk_os_timer_disarm(ETSTimer *ptimer) {
|
||||
if (ptimer->timer_handle) {
|
||||
if (!xTimerStop(ptimer->timer_handle, 50)) {
|
||||
printf("Timer Stop Failed\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue