-
Notifications
You must be signed in to change notification settings - Fork 2
TimerService
The TimerService is a task scheduler that allows for multiple callbacks to be scheduled on a single timer compare register.
Returns the current tick of the timer. All timers are treated as 32 bit timers. This is a virtual function passed down to the underlying abstraction. See Building a New Abstraction for how to achieve this with lower resolution timers.
Returns the speed of the timer in number of ticks per second. This is a virtual function passed down to the underlying abstraction.
By default, Tasks are not allowed to be scheduled during a callBack. If this is required, add #define ALLOW_TASK_TO_SCHEDULE_IN_CALLBACK
This schedules a callBack to be executed at the input tick. This is for scheduling an infrequent callBack. This will not update a previously scheduled callBack. The callBack is not able to be unscheduled.
This schedules a task to be executed at the input tick. This is for scheduling more frequent tasks. This will also update the task execute tick if the task is already scheduled.
This unschedules a task that was previously scheduled.
ITimerService *_timerService;
IDigitalService *_digitalService;
bool val = false;
void toggleLED()
{
// set LED pin to val
_digitalService->WritePin(45, val); //PC13
// toggle val
val = !val;
}
Task toggleLEDTask = Task(&toggleLED);
// Initialize LED pin
_digitalService->InitPin(45, PinDirection::Out); //PC13 as Output
// Setup first execution of task to be now + 1 second
_timerService->ScheduleTask(&toggleLEDTask, _timerService->GetTick() + _timerService->GetTicksPerSecond());
// if the task has been executed and is no longer scheduled,
// reschedule the task for 1 second after the previous scheduled time.
if(!toggleLEDTask.Scheduled)
_timerService->ScheduleTask(&toggleLEDTask, toggleLEDTask.Tick + _timerService->GetTicksPerSecond());