- Timer update next alarm bug fixed
This commit is contained in:
parent
c165389369
commit
c01907fdde
12
timer.c
12
timer.c
@ -69,8 +69,11 @@ static void timer_update_nearest_alarm(Timer *tmr) {
|
|||||||
AlarmAssignment *nearest = NULL; // nearest alarm
|
AlarmAssignment *nearest = NULL; // nearest alarm
|
||||||
for (uint32_t i = 0; i < tmr->maxSched; i++) {
|
for (uint32_t i = 0; i < tmr->maxSched; i++) {
|
||||||
AlarmAssignment * iter = tmr->alarms + i;
|
AlarmAssignment * iter = tmr->alarms + i;
|
||||||
|
if (iter->id == 0) { // do not consider empty slots
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int64_t t_i_us = time_to_us(&(iter->time));
|
int64_t t_i_us = time_to_us(&(iter->time));
|
||||||
if ((nearest == NULL) && (iter->id != 0)) { // if it's the first one
|
if (nearest == NULL) { // if it's the first one
|
||||||
nearest = iter;
|
nearest = iter;
|
||||||
min_delta_t_us = t_i_us - t_c_us;
|
min_delta_t_us = t_i_us - t_c_us;
|
||||||
} else { // if it's not the first one
|
} else { // if it's not the first one
|
||||||
@ -103,6 +106,7 @@ uint32_t timer_sched(Timer *tmr, const TimePoint *t, TimerAlarmCb cb, AlarmUserD
|
|||||||
|
|
||||||
// increase allocation count
|
// increase allocation count
|
||||||
tmr->nSched++;
|
tmr->nSched++;
|
||||||
|
MSG("%d %s\n", tmr->nSched, __FUNCTION__);
|
||||||
|
|
||||||
// replace nearest if needed
|
// replace nearest if needed
|
||||||
if (tmr->nSched > 1) {
|
if (tmr->nSched > 1) {
|
||||||
@ -132,6 +136,7 @@ void timer_unsched(Timer *tmr, uint32_t id) {
|
|||||||
if (alarm != NULL) {
|
if (alarm != NULL) {
|
||||||
memset(alarm, 0, sizeof(AlarmAssignment));
|
memset(alarm, 0, sizeof(AlarmAssignment));
|
||||||
tmr->nSched--;
|
tmr->nSched--;
|
||||||
|
MSG("%d %s\n", tmr->nSched, __FUNCTION__);
|
||||||
timer_update_nearest_alarm(tmr);
|
timer_update_nearest_alarm(tmr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,12 +181,11 @@ void timer_tick(Timer *tmr, int64_t us) {
|
|||||||
|
|
||||||
// decrease scheduled alarm count
|
// decrease scheduled alarm count
|
||||||
tmr->nSched--;
|
tmr->nSched--;
|
||||||
|
MSG("%d %s\n", tmr->nSched, __FUNCTION__);
|
||||||
|
|
||||||
// update nearest alarm
|
// update nearest alarm
|
||||||
timer_update_nearest_alarm(tmr);
|
timer_update_nearest_alarm(tmr);
|
||||||
|
|
||||||
ETHLIB_OS_MTX_UNLOCK(&(tmr->tabMtx));
|
|
||||||
|
|
||||||
// invoke callback
|
// invoke callback
|
||||||
if (alarm.cb != NULL) {
|
if (alarm.cb != NULL) {
|
||||||
alarm.cb(tmr, alarm.params);
|
alarm.cb(tmr, alarm.params);
|
||||||
@ -190,6 +194,8 @@ void timer_tick(Timer *tmr, int64_t us) {
|
|||||||
if (tmr->nextAlarm != NULL) {
|
if (tmr->nextAlarm != NULL) {
|
||||||
t_alarm = time_to_us(&(tmr->nextAlarm->time));
|
t_alarm = time_to_us(&(tmr->nextAlarm->time));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ETHLIB_OS_MTX_UNLOCK(&(tmr->tabMtx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user