Loading...
Searching...
No Matches
rtt.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for more
6 * details.
7 */
8
38#ifndef PERIPH_RTT_H
39#define PERIPH_RTT_H
40
41#include <stdint.h>
42
43#include "periph_conf.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
54#ifdef DOXYGEN
55#define RTT_FREQUENCY
56#endif
57
64#ifdef DOXYGEN
65#define RTT_MAX_VALUE
66#endif
67
82#ifndef RTT_MIN_OFFSET
83#define RTT_MIN_OFFSET (2U)
84#endif
85
86/* Allow mock-RTT for unit tests */
87#ifdef MOCK_RTT_FREQUENCY
88#undef RTT_FREQUENCY
89#define RTT_FREQUENCY MOCK_RTT_FREQUENCY
90#else
91#ifndef RTT_FREQUENCY
92#warning "RTT_FREQUENCY undefined. Set RTT_FREQUENCY to the number of ticks " \
93 "per second for the current architecture."
94#endif
95#endif
96
97/* Allow mock-RTT for unit tests */
98#ifdef MOCK_RTT_MAX_VALUE
99#undef RTT_MAX_VALUE
100#define RTT_MAX_VALUE MOCK_RTT_MAX_VALUE
101#else
102#ifndef RTT_MAX_VALUE
103#warning "RTT_MAX_VALUE is undefined. Set RTT_MAX_VALUE to the maximum value " \
104 "for the RTT counter, ensure it is (2^n - 1)."
105#endif
106#endif
107
113#define RTT_US_TO_TICKS(us) (RTT_SEC_TO_TICKS(us) / 1000000UL)
114
120#define RTT_MS_TO_TICKS(ms) (RTT_SEC_TO_TICKS(ms) / 1000UL)
121
127#define RTT_SEC_TO_TICKS(sec) (sec * RTT_FREQUENCY)
128
134#define RTT_MIN_TO_TICKS(min) (RTT_SEC_TO_TICKS((min) * 60))
135
141#define RTT_TICKS_TO_US(ticks) ((uint64_t)(ticks) * 1000000UL / RTT_FREQUENCY)
142
148#define RTT_TICKS_TO_MS(ticks) (RTT_TICKS_TO_US(ticks) / 1000)
149
155#define RTT_TICKS_TO_SEC(ticks) (RTT_TICKS_TO_MS(ticks) / 1000)
156
162#define RTT_TICKS_TO_MIN(ticks) (RTT_TICKS_TO_SEC(ticks) / 60)
163
170typedef void(*rtt_cb_t)(void *arg);
171
175void rtt_init(void);
176
183void rtt_set_overflow_cb(rtt_cb_t cb, void *arg);
184
189
195uint32_t rtt_get_counter(void);
196
204void rtt_set_counter(uint32_t counter);
205
213void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg);
214
222uint32_t rtt_get_alarm(void);
223
228
232void rtt_poweron(void);
233
237void rtt_poweroff(void);
238
239#ifdef __cplusplus
240}
241#endif
242
243#endif /* PERIPH_RTT_H */
uint32_t rtt_get_alarm(void)
Get the value of a set alarm.
void rtt_poweron(void)
Turn the RTT hardware module on.
void rtt_init(void)
Initialize RTT module.
uint32_t rtt_get_counter(void)
Get the current RTT counter.
void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)
Set a callback for the counter overflow event.
void(* rtt_cb_t)(void *arg)
Signature for the alarm callback.
Definition rtt.h:170
void rtt_poweroff(void)
Turn the RTT hardware module off.
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
Set an alarm for RTT to the specified absolute target time.
void rtt_clear_alarm(void)
Clear any set alarm, do nothing if nothing set.
void rtt_set_counter(uint32_t counter)
Set the RTT counter to a specified value.
void rtt_clear_overflow_cb(void)
Clear the overflow callback.