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 
21 #ifndef PERIPH_TIMER_H
22 #define PERIPH_TIMER_H
23 
24 #include <limits.h>
25 
26 #include "periph_cpu.h"
28 #include "periph/dev_enums.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
39 #ifndef TIMER_DEV
40 #define TIMER_DEV(x) (x)
41 #endif
42 
46 #ifndef TIMER_UNDEF
47 #define TIMER_UNDEF (UINT_MAX)
48 #endif
49 
56 #ifndef HAVE_TIMER_T
57 typedef unsigned int tim_t;
58 #endif
59 
66 typedef void (*timer_cb_t)(void *arg, int channel);
67 
72 #ifndef HAVE_TIMER_ISR_CTX_T
73 typedef struct {
75  void *arg;
77 #endif
78 
100 int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg);
101 
116 int timer_set(tim_t dev, int channel, unsigned int timeout);
117 
129 int timer_set_absolute(tim_t dev, int channel, unsigned int value);
130 
140 int timer_clear(tim_t dev, int channel);
141 
149 unsigned int timer_read(tim_t dev);
150 
158 void timer_start(tim_t dev);
159 
167 void timer_stop(tim_t dev);
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif /* PERIPH_TIMER_H */
174 
void timer_stop(tim_t dev)
Stop the given timer.
void * arg
optional argument given to that callback
Definition: timer.h:75
timer_cb_t cb
callback executed from timer interrupt
Definition: timer.h:74
void timer_start(tim_t dev)
Start the given timer.
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.
unsigned int tim_t
Default timer type.
Definition: timer.h:57
int timer_clear(tim_t dev, int channel)
Clear the given channel of the given timer device.
Default interrupt context entry holding callback and argument.
Definition: timer.h:73
unsigned int timer_read(tim_t dev)
Read the current value of the given timer device.
int timer_set(tim_t dev, int channel, unsigned int timeout)
Set a given timer channel for the given timer device.
Device enumerations for backward compatibility with existing peripheral driver implementations.
void(* timer_cb_t)(void *arg, int channel)
Signature of event callback functions triggered from interrupts.
Definition: timer.h:66
int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
Initialize the given timer.