Loading...
Searching...
No Matches
rtt.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
41
42#include <stdint.h>
43
44#include "periph_conf.h"
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
55#ifdef DOXYGEN
56# define RTT_FREQUENCY
57#endif
58
65#ifdef DOXYGEN
66# define RTT_MAX_VALUE
67#endif
68
83#ifndef RTT_MIN_OFFSET
84# pragma message "RTT_MIN_OFFSET is undefined. Using default value of 2. " \
85 "Please test your CPU using RIOT/tests/periph/rtt_min and " \
86 "define RTT_MIN_OFFSET in periph_cpu.h accordingly."
87# define RTT_MIN_OFFSET (2U)
88#endif
89
90/* Allow mock-RTT for unit tests */
91#ifdef MOCK_RTT_FREQUENCY
92# undef RTT_FREQUENCY
93# define RTT_FREQUENCY MOCK_RTT_FREQUENCY
94#else
95# ifndef RTT_FREQUENCY
96# warning "RTT_FREQUENCY undefined. Set RTT_FREQUENCY to the number of ticks " \
97 "per second for the current architecture."
98# endif
99#endif
100
101/* Allow mock-RTT for unit tests */
102#ifdef MOCK_RTT_MAX_VALUE
103# undef RTT_MAX_VALUE
104# define RTT_MAX_VALUE MOCK_RTT_MAX_VALUE
105#else
106# ifndef RTT_MAX_VALUE
107# warning "RTT_MAX_VALUE is undefined. Set RTT_MAX_VALUE to the maximum value " \
108 "for the RTT counter, ensure it is (2^n - 1)."
109# endif
110#endif
111
117#define RTT_US_TO_TICKS(us) (RTT_SEC_TO_TICKS(us) / 1000000UL)
118
124#define RTT_MS_TO_TICKS(ms) (RTT_SEC_TO_TICKS(ms) / 1000UL)
125
131#define RTT_SEC_TO_TICKS(sec) (sec * RTT_FREQUENCY)
132
138#define RTT_MIN_TO_TICKS(min) (RTT_SEC_TO_TICKS((min) * 60))
139
145#define RTT_TICKS_TO_US(ticks) ((uint64_t)(ticks) * 1000000UL / RTT_FREQUENCY)
146
152#define RTT_TICKS_TO_MS(ticks) (RTT_TICKS_TO_US(ticks) / 1000)
153
159#define RTT_TICKS_TO_SEC(ticks) (RTT_TICKS_TO_MS(ticks) / 1000)
160
166#define RTT_TICKS_TO_MIN(ticks) (RTT_TICKS_TO_SEC(ticks) / 60)
167
174typedef void (*rtt_cb_t)(void *arg);
175
179void rtt_init(void);
180
187void rtt_set_overflow_cb(rtt_cb_t cb, void *arg);
188
193
199uint32_t rtt_get_counter(void);
200
208void rtt_set_counter(uint32_t counter);
209
217void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg);
218
226uint32_t rtt_get_alarm(void);
227
232
236void rtt_poweron(void);
237
241void rtt_poweroff(void);
242
243#ifdef __cplusplus
244}
245#endif
246
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:174
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.