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 
34 #ifndef PERIPH_RTT_H
35 #define PERIPH_RTT_H
36 
37 #include <stdint.h>
38 
39 #include "periph_conf.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
50 #ifdef DOXYGEN
51 #define RTT_FREQUENCY
52 #endif
53 
60 #ifdef DOXYGEN
61 #define RTT_MAX_VALUE
62 #endif
63 
78 #ifndef RTT_MIN_OFFSET
79 #define RTT_MIN_OFFSET (2U)
80 #endif
81 
82 /* Allow mock-RTT for unit tests */
83 #ifdef MOCK_RTT_FREQUENCY
84 #undef RTT_FREQUENCY
85 #define RTT_FREQUENCY MOCK_RTT_FREQUENCY
86 #else
87 #ifndef RTT_FREQUENCY
88 #warning "RTT_FREQUENCY undefined. Set RTT_FREQUENCY to the number of ticks " \
89  "per second for the current architecture."
90 #endif
91 #endif
92 
93 /* Allow mock-RTT for unit tests */
94 #ifdef MOCK_RTT_MAX_VALUE
95 #undef RTT_MAX_VALUE
96 #define RTT_MAX_VALUE MOCK_RTT_MAX_VALUE
97 #else
98 #ifndef RTT_MAX_VALUE
99 #warning "RTT_MAX_VALUE is undefined. Set RTT_MAX_VALUE to the maximum value " \
100  "for the RTT counter, ensure it is (2^n - 1)."
101 #endif
102 #endif
103 
109 #define RTT_US_TO_TICKS(us) (RTT_SEC_TO_TICKS(us) / 1000000UL)
110 
116 #define RTT_MS_TO_TICKS(ms) (RTT_SEC_TO_TICKS(ms) / 1000UL)
117 
123 #define RTT_SEC_TO_TICKS(sec) (sec * RTT_FREQUENCY)
124 
130 #define RTT_MIN_TO_TICKS(min) (RTT_SEC_TO_TICKS((min) * 60))
131 
137 #define RTT_TICKS_TO_US(ticks) ((uint64_t)(ticks) * 1000000UL / RTT_FREQUENCY)
138 
144 #define RTT_TICKS_TO_MS(ticks) (RTT_TICKS_TO_US(ticks) / 1000)
145 
151 #define RTT_TICKS_TO_SEC(ticks) (RTT_TICKS_TO_MS(ticks) / 1000)
152 
158 #define RTT_TICKS_TO_MIN(ticks) (RTT_TICKS_TO_SEC(ticks) / 60)
159 
166 typedef void(*rtt_cb_t)(void *arg);
167 
171 void rtt_init(void);
172 
179 void rtt_set_overflow_cb(rtt_cb_t cb, void *arg);
180 
184 void rtt_clear_overflow_cb(void);
185 
191 uint32_t rtt_get_counter(void);
192 
198 void rtt_set_counter(uint32_t counter);
199 
207 void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg);
208 
216 uint32_t rtt_get_alarm(void);
217 
221 void rtt_clear_alarm(void);
222 
226 void rtt_poweron(void);
227 
231 void rtt_poweroff(void);
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 
237 #endif /* PERIPH_RTT_H */
238 
rtt_poweroff
void rtt_poweroff(void)
Turn the RTT hardware module off.
rtt_clear_overflow_cb
void rtt_clear_overflow_cb(void)
Clear the overflow callback.
rtt_cb_t
void(* rtt_cb_t)(void *arg)
Signature for the alarm callback.
Definition: rtt.h:166
rtt_clear_alarm
void rtt_clear_alarm(void)
Clear any set alarm, do nothing if nothing set.
rtt_set_overflow_cb
void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)
Set a callback for the counter overflow event.
rtt_set_counter
void rtt_set_counter(uint32_t counter)
Set the RTT counter to a specified value.
rtt_set_alarm
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
Set an alarm for RTT to the specified absolute target time.
rtt_init
void rtt_init(void)
Initialize RTT module.
rtt_get_counter
uint32_t rtt_get_counter(void)
Get the current RTT counter.
rtt_get_alarm
uint32_t rtt_get_alarm(void)
Get the value of a set alarm.
rtt_poweron
void rtt_poweron(void)
Turn the RTT hardware module on.