|
|
|
|
|
|
|
|
if (_state != TimerOff) end(); |
|
|
if (_state != TimerOff) end(); |
|
|
if (!milliseconds) return; |
|
|
if (!milliseconds) return; |
|
|
_event = &event; |
|
|
_event = &event; |
|
|
_ms = milliseconds; |
|
|
|
|
|
|
|
|
_ms = (milliseconds > 2)? milliseconds-2 : 0; |
|
|
_reload = 0; |
|
|
_reload = 0; |
|
|
addToWaitingList(); |
|
|
addToWaitingList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (_state != TimerOff) end(); |
|
|
if (_state != TimerOff) end(); |
|
|
if (!milliseconds) return; |
|
|
if (!milliseconds) return; |
|
|
_event = &event; |
|
|
_event = &event; |
|
|
_ms = milliseconds; |
|
|
|
|
|
|
|
|
_ms = (milliseconds > 2)? milliseconds-2 : 0; |
|
|
_reload = milliseconds; |
|
|
_reload = milliseconds; |
|
|
addToWaitingList(); |
|
|
addToWaitingList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool irq = disableTimerInterrupt(); |
|
|
bool irq = disableTimerInterrupt(); |
|
|
_next = listWaiting; |
|
|
_next = listWaiting; |
|
|
listWaiting = this; // TODO: use STREX to avoid interrupt disable |
|
|
listWaiting = this; // TODO: use STREX to avoid interrupt disable |
|
|
|
|
|
_state = TimerWaiting; |
|
|
enableTimerInterrupt(irq); |
|
|
enableTimerInterrupt(irq); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_next = listActive; |
|
|
_next = listActive; |
|
|
_prev = nullptr; |
|
|
_prev = nullptr; |
|
|
listActive->_prev = this; |
|
|
listActive->_prev = this; |
|
|
|
|
|
// Decrement the next items wait time be our wait time as to properly handle waits for all other items... |
|
|
|
|
|
listActive->_ms -= _ms; |
|
|
listActive = this; |
|
|
listActive = this; |
|
|
} else { |
|
|
} else { |
|
|
// add this timer somewhere after the first already on the list |
|
|
// add this timer somewhere after the first already on the list |
|
|
|
|
|
|
|
|
_prev = timer->_prev; |
|
|
_prev = timer->_prev; |
|
|
timer->_prev = this; |
|
|
timer->_prev = this; |
|
|
_prev->_next = this; |
|
|
_prev->_next = this; |
|
|
|
|
|
timer->_ms -= _ms; |
|
|
_state = TimerActive; |
|
|
_state = TimerActive; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (s == TimerActive) { |
|
|
if (s == TimerActive) { |
|
|
if (_next) { |
|
|
if (_next) { |
|
|
_next->_prev = _prev; |
|
|
_next->_prev = _prev; |
|
|
|
|
|
_next->_ms += _ms; // add in the rest of our timing to next entry... |
|
|
} |
|
|
} |
|
|
if (_prev) { |
|
|
if (_prev) { |
|
|
_prev->_next = _next; |
|
|
_prev->_next = _next; |