Timer / counter driver support for hardware abstraction layer.
In timer mode, with callback handler :
void timer100ms_fn(void)
{
puts("time out");
}
// init timer
rt_dev_t timer = timer_getFreeDevice();
timer_setPeriodMs(timer, 100);
timer_setHandler(timer, timer100ms_fn);
timer_enable(timer); // timer100ms_fn function will be called every 100ms
In counter mode :
// init timer
rt_dev_t timer = timer_getFreeDevice();
timer_setCounter(timer, 1); // no divider
timer_enable(timer); // start to count
uint16_t value;
value = timer_value(timer); // get count
timer_clearValue(timer); // clear count
rt_dev_t timer_getFreeDevice();
Gives a free timer device number
int timer_open(rt_dev_t device);
Opens a timer
int timer_close(rt_dev_t device);
Closes a timer
bool timer_isOpened(rt_dev_t device)
Timer sdk state
int timer_enable(rt_dev_t device);
Enables the specified timer device
int timer_disable(rt_dev_t device);
Disables the specified timer device
bool timer_isEnabled(rt_dev_t device);
Timer sdk enabled state
int timer_setPeriodMs(rt_dev_t device, uint32_t periodMs);
Sets the period in ms of the timer module to work in timer mode
uint32_t timer_periodMs(rt_dev_t device);
Returns the current period in ms
int timer_setPeriodUs(rt_dev_t device, uint32_t periodUs);
Sets the period in us of the timer module to work in timer mode
uint32_t timer_periodUs(rt_dev_t device);
Returns the current period in us
int timer_setPeriodUs(rt_dev_t device, uint32_t period);
Sets the period in low level units. If the period is greatter than the PR register size, the pre divider is adapted
uint32_t timer_period(rt_dev_t device);
Returns the current period in low level units
int timer_setCounter(rt_dev_t device, uint16_t diviser);
Returns the current value of timer
int timer_clearValue(rt_dev_t device);
Reset the value of counter
int timer_setValue(rt_dev_t device, uint16_t value);
Sets the current value of timer
uint16_t timer_value(rt_dev_t device);
Returns the current value of timer
Header file : timer.h