The current time is held as a 32-bit value in the variable ctl_current_time. This variable is incremented by the number held in ctl_time_increment each time an ISR calls ctl_increment_tick_from_isr.
void timerISR{void) { ctl_increment_tick_from_isr(); // Your timer code goes here. } int main(void) { ctl_time_increment = 10; // User must set up timerISR to be called every 100 ms. ⁞
By convention, the timer implements a millisecond counter, but you can set the timer's interrupt-and-increment rate to a value that is appropriate for your application.
You can atomically read ctl_current_time by using the ctl_get_current_time function on systems whose word size is not 32 bits.
You can use ctl_timeout_wait to suspend execution of a task for a fixed period. Note: ctl_timeout_wait takes as its parameter the time to resume execution, not the duration: always call this function with ctl_get_current_time()+duration.
ctl_timeout_wait(ctl_get_current_time()+100);
This example suspends execution of the calling task for 100 ticks of the ctl_current_time variable.
The counter is implemented as a 32-bit number, so you can delay for a maximum of a 31-bit number.
ctl_timeout_wait(ctl_get_current_time() + 0x7fffffff);
This example suspends execution of the calling task for the maximum possible time.