finished removing `timer__schedule_milliseconds()`

partial-rewrite
Ben Blazak 2013-06-13 16:38:29 -07:00
parent aec1bac3bb
commit 559fe97d7e
2 changed files with 1 additions and 26 deletions

View File

@ -27,15 +27,11 @@
// ----------------------------------------------------------------------------
static volatile uint16_t _milliseconds__counter;
static list__list_t _milliseconds__scheduled_events;
// since we won't be running scheduled events every "tick"
static uint8_t _milliseconds__last_ticked;
// ----------------------------------------------------------------------------
uint8_t timer__init(void) {
OCR0A = 250; // (ticks per millisecond (hardware timer))
OCR0A = 250; // (ticks (of hardware timer) per millisecond)
TCCR0A = 0b00000010; // (configure Timer/Counter 0)
TCCR0B = 0b00000011; // (configure Timer/Counter 0)
@ -48,26 +44,6 @@ uint16_t timer__get_milliseconds(void) {
return _milliseconds__counter;
}
uint8_t timer__schedule_milliseconds(uint16_t ticks, void(*function)(void)) {
uint8_t elapsed = timer__get_milliseconds() - _milliseconds__last_ticked;
// - use `ticks+elapsed` to compensate for ticks that haven't been counted
// yet, but should have (if we were ticking in real time)
return event_list__append(
&_milliseconds__scheduled_events, ticks+elapsed, function );
}
void timer___tick_milliseconds(void) {
uint8_t elapsed = timer__get_milliseconds() - _milliseconds__last_ticked;
// - update before ticking: if an event reschedules itself to run in 1
// tick, it should execute on the next tick without having to wait
_milliseconds__last_ticked += elapsed;
for (uint8_t i=0; i<elapsed; i++)
event_list__tick(&_milliseconds__scheduled_events);
}
ISR(TIMER0_COMPA_vect) {
_milliseconds__counter++;
}

View File

@ -127,7 +127,6 @@ int main(void) {
}
timer___tick_cycles();
timer___tick_milliseconds();
}
return 0;