drivers/include/periph/timer.h¶
Low-level timer peripheral driver interface definitions.
-
TIMER_DEV
( x)¶ Default timer definition macro.
1
(x)
remove dev_enums.h include once all platforms are ported to the updated periph interface
Overwrite this in your CPUs periph_cpu.h file if needed
-
TIMER_UNDEF
¶ Default value for timer not defined.
1
(UINT_MAX)
-
unsigned int
tim_t
¶ Default timer type.
We chose the name of tim_t here to avoid naming clashes with other libraries and vendor device header.
-
void(*
timer_cb_t
()¶ Signature of event callback functions triggered from interrupts.
Parameters
arg: optional context for the callback channel: timer channel that triggered the interrupt
-
int
timer_init
(drivers/include/periph/timer.h::tim_t
dev, unsigned long freq,drivers/include/periph/timer.h::timer_cb_t
cb, void * arg)¶ Initialize the given timer.
Each timer device is running with the given speed. Each can contain one or more channels as defined in periph_conf.h. The timer is configured in up-counting mode and will count until TIMER_x_MAX_VALUE as defined in used board’s periph_conf.h until overflowing.
The timer will be started automatically after initialization with interrupts enabled.
Parameters
dev: the timer to initialize freq: requested number of ticks per second cb: this callback is called in interrupt context, the emitting channel is passed as argument arg: argument to the callback Return values
- 0 on success
- -1 if speed not applicable or unknown device given
-
int
timer_set
(drivers/include/periph/timer.h::tim_t
dev, int channel, unsigned int timeout)¶ Set a given timer channel for the given timer device.
The callback given during initialization is called when timeout ticks have passed after calling this function
Parameters
dev: the timer device to set channel: the channel to set timeout: timeout in ticks after that the registered callback is executed Return values
- 1 on success
- -1 on error
-
int
timer_set_absolute
(drivers/include/periph/timer.h::tim_t
dev, int channel, unsigned int value)¶ Set an absolute timeout value for the given channel of the given timer.
Parameters
dev: the timer device to set channel: the channel to set value: the absolute compare value when the callback will be triggered Return values
- 1 on success
- -1 on error
-
int
timer_clear
(drivers/include/periph/timer.h::tim_t
dev, int channel)¶ Clear the given channel of the given timer device.
Parameters
dev: the timer device to clear channel: the channel on the given device to clear Return values
- 1 on success
- -1 on error
-
unsigned int
timer_read
(drivers/include/periph/timer.h::tim_t
dev)¶ Read the current value of the given timer device.
Parameters
dev: the timer to read the current value from Return values
- the timers current value
-
void
timer_start
(drivers/include/periph/timer.h::tim_t
dev)¶ Start the given timer.
This function is only needed if the timer was stopped manually before.
Parameters
dev: the timer device to start
-
void
timer_stop
(drivers/include/periph/timer.h::tim_t
dev)¶ Stop the given timer.
This will effect all of the timer’s channels.
Parameters
dev: the timer to stop
-
struct
timer_isr_ctx_t
¶ Default interrupt context entry holding callback and argument.
-
drivers/include/periph/timer.h::timer_cb_t
cb
¶ callback executed from timer interrupt
-
void *
arg
¶ optional argument given to that callback
-