Loading...
Searching...
No Matches
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
9#pragma once
10
35#include <limits.h>
36#include <stdint.h>
37#include <stdbool.h>
38
39#include "architecture.h"
40#include "periph_cpu.h"
41#include "periph_conf.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
52#ifndef TIMER_DEV
53#define TIMER_DEV(x) (x)
54#endif
55
59#ifndef TIMER_UNDEF
60#define TIMER_UNDEF (UINT_FAST8_MAX)
61#endif
62
69#ifndef HAVE_TIMER_T
70typedef uint_fast8_t tim_t;
71#endif
72
78#ifndef TIM_FLAG_RESET_ON_SET
79#define TIM_FLAG_RESET_ON_SET (0x01)
80#endif
81
89#ifndef TIM_FLAG_RESET_ON_MATCH
90#define TIM_FLAG_RESET_ON_MATCH (0x02)
91#endif
92
99#ifndef TIM_FLAG_SET_STOPPED
100#define TIM_FLAG_SET_STOPPED (0x04)
101#endif
102
109typedef void (*timer_cb_t)(void *arg, int channel);
110
114#ifndef HAVE_TIMER_ISR_CTX_T
115typedef struct {
117 void *arg;
119#endif
120
141int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg);
142
157int timer_set(tim_t dev, int channel, unsigned int timeout);
158
173int timer_set_absolute(tim_t dev, int channel, unsigned int value);
174
193int timer_set_periodic(tim_t dev, int channel, unsigned int value, uint8_t flags);
194
204int timer_clear(tim_t dev, int channel);
205
213unsigned int timer_read(tim_t dev);
214
223
235
249__attribute__((pure))
251
263__attribute__((pure))
265
296uint32_t timer_query_freqs(tim_t dev, uword_t index);
297
314uint32_t timer_get_closest_freq(tim_t dev, uint32_t target);
315
316#if defined(DOXYGEN)
336/* As this function is polled, it needs to be inlined, so it is typically
337 * provided through timer_arch.h. If a platform ever does not need to go
338 * through static inline here, this declaration's condition can be extended to
339 * be `(defined(MODULE_PERIPH_TIMER_POLL) &&
340 * !defined(PERIPH_TIMER_PROVIDES_INLINE_POLL_CHANNEL) || defined(DOXYGEN)` or
341 * similar. */
342bool timer_poll_channel(tim_t dev, int channel);
343#endif
344
345#if defined(MODULE_PERIPH_TIMER_POLL)
346#include "timer_arch.h" /* IWYU pragma: export */
347#endif
348
349#ifdef __cplusplus
350}
351#endif
352
Platform-independent access to architecture details.
uword_t timer_query_freqs_numof(tim_t dev)
Get the number of different frequencies supported by the given timer.
unsigned int timer_read(tim_t dev)
Read the current value of the given timer device.
bool timer_poll_channel(tim_t dev, int channel)
Check whether a compare channel has matched.
void(* timer_cb_t)(void *arg, int channel)
Signature of event callback functions triggered from interrupts.
Definition timer.h:109
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.
uint32_t timer_get_closest_freq(tim_t dev, uint32_t target)
Search the frequency supported by the timer that is closest to a given target frequency,...
int timer_clear(tim_t dev, int channel)
Clear the given channel of the given timer device.
uint_fast8_t tim_t
Default timer type.
Definition timer.h:70
int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
Initialize the given timer.
uint32_t timer_query_freqs(tim_t dev, uword_t index)
Iterate over supported frequencies.
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.
void timer_stop(tim_t dev)
Stop the given timer.
uword_t timer_query_channel_numof(tim_t dev)
Get the number of timer channels for the given timer.
int timer_set(tim_t dev, int channel, unsigned int timeout)
Set a given timer channel for the given timer device.
void timer_start(tim_t dev)
Start the given timer.
uint< NUM > _t uword_t
Word sized unsigned integer.
Default interrupt context entry holding callback and argument.
Definition timer.h:115
void * arg
optional argument given to that callback
Definition timer.h:117
timer_cb_t cb
callback executed from timer interrupt
Definition timer.h:116
CPU specific part of the timer API.