timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
33 #ifndef PERIPH_TIMER_H
34 #define PERIPH_TIMER_H
35 
36 #include <limits.h>
37 #include <stdint.h>
38 
39 #include "periph_cpu.h"
40 #include "periph_conf.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
51 #ifndef TIMER_DEV
52 #define TIMER_DEV(x) (x)
53 #endif
54 
58 #ifndef TIMER_UNDEF
59 #define TIMER_UNDEF (UINT_MAX)
60 #endif
61 
68 #ifndef HAVE_TIMER_T
69 typedef unsigned int tim_t;
70 #endif
71 
77 #ifndef TIM_FLAG_RESET_ON_SET
78 #define TIM_FLAG_RESET_ON_SET (0x01)
79 #endif
80 
88 #ifndef TIM_FLAG_RESET_ON_MATCH
89 #define TIM_FLAG_RESET_ON_MATCH (0x02)
90 #endif
91 
98 typedef void (*timer_cb_t)(void *arg, int channel);
99 
103 #ifndef HAVE_TIMER_ISR_CTX_T
104 typedef struct {
106  void *arg;
108 #endif
109 
130 int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg);
131 
146 int timer_set(tim_t dev, int channel, unsigned int timeout);
147 
162 int timer_set_absolute(tim_t dev, int channel, unsigned int value);
163 
182 int timer_set_periodic(tim_t dev, int channel, unsigned int value, uint8_t flags);
183 
193 int timer_clear(tim_t dev, int channel);
194 
202 unsigned int timer_read(tim_t dev);
203 
211 void timer_start(tim_t dev);
212 
223 void timer_stop(tim_t dev);
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif /* PERIPH_TIMER_H */
230 
timer_init
int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
Initialize the given timer.
timer_set_absolute
int timer_set_absolute(tim_t dev, int channel, unsigned int value)
Set an absolute timeout value for the given channel of the given timer.
timer_cb_t
void(* timer_cb_t)(void *arg, int channel)
Signature of event callback functions triggered from interrupts.
Definition: timer.h:98
tim_t
unsigned int tim_t
Default timer type.
Definition: timer.h:69
timer_isr_ctx_t::cb
timer_cb_t cb
callback executed from timer interrupt
Definition: timer.h:105
timer_set
int timer_set(tim_t dev, int channel, unsigned int timeout)
Set a given timer channel for the given timer device.
timer_isr_ctx_t::arg
void * arg
optional argument given to that callback
Definition: timer.h:106
timer_isr_ctx_t
Default interrupt context entry holding callback and argument.
Definition: timer.h:104
timer_start
void timer_start(tim_t dev)
Start the given timer.
timer_read
unsigned int timer_read(tim_t dev)
Read the current value of the given timer device.
timer_set_periodic
int timer_set_periodic(tim_t dev, int channel, unsigned int value, uint8_t flags)
Set an absolute timeout value for the given channel of the given timer.
timer_stop
void timer_stop(tim_t dev)
Stop the given timer.
timer_clear
int timer_clear(tim_t dev, int channel)
Clear the given channel of the given timer device.