The friendly Operating System for the Internet of Things
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 
23 #ifndef RTT_H
24 #define RTT_H
25 
26 #include "periph_conf.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /* guard file in case no RTT device was specified */
33 #if RTT_NUMOF
34 
35 #ifndef RTT_FREQUENCY
36 #warning "RTT_FREQUENCY undefined. Set RTT_FREQUENCY to the number of ticks" \
37  "per second for the current architecture."
38 #endif
39 
45 #define RTT_US_TO_TICKS(us) ((uint32_t)((uint64_t)(us) * RTT_FREQUENCY / 1000000UL))
46 
52 #define RTT_MS_TO_TICKS(ms) ( RTT_US_TO_TICKS((ms) * 1000) )
53 
59 #define RTT_SEC_TO_TICKS(sec) ( RTT_MS_TO_TICKS((sec) * 1000) )
60 
66 #define RTT_MIN_TO_TICKS(min) ( RTT_SEC_TO_TICKS((min) * 60) )
67 
73 #define RTT_TICKS_TO_US(ticks) ((uint32_t)((uint64_t)(ticks) * 1000000UL / RTT_FREQUENCY))
74 
80 #define RTT_TICKS_TO_MS(ticks) (RTT_TICKS_TO_US(ticks) / 1000)
81 
87 #define RTT_TICKS_TO_SEC(ticks) (RTT_TICKS_TO_MS(ticks) / 1000)
88 
94 #define RTT_TICKS_TO_MIN(ticks) (RTT_TICKS_TO_SEC(ticks) / 60)
95 
102 typedef void(*rtt_cb_t)(void *arg);
103 
107 void rtt_init(void);
108 
115 void rtt_set_overflow_cb(rtt_cb_t cb, void *arg);
116 
120 void rtt_clear_overflow_cb(void);
121 
127 uint32_t rtt_get_counter(void);
128 
134 void rtt_set_counter(uint32_t counter);
135 
143 void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg);
144 
152 uint32_t rtt_get_alarm(void);
153 
157 void rtt_clear_alarm(void);
158 
162 void rtt_poweron(void);
163 
167 void rtt_poweroff(void);
168 
169 #endif /* RTT_NUMOF */
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif /* RTT_H */
176 
void rtt_clear_overflow_cb(void)
Clear the overflow callback.
void(* rtt_cb_t)(void *arg)
Signature for the alarm callback.
Definition: rtt.h:102
void rtt_clear_alarm(void)
Clear any set alarm, do nothing if nothing set.
void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)
Set a callback for the counter overflow event.
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
Set an alarm for RTT to the specified value.
void rtt_set_counter(uint32_t counter)
Set the RTT counter to a specified value.
void rtt_init(void)
Initialize RTT module.
uint32_t rtt_get_counter(void)
Get the current RTT counter.
uint32_t rtt_get_alarm(void)
Get the value of a set alarm.
void rtt_poweroff(void)
Turn the RTT hardware module off.
void rtt_poweron(void)
Turn the RTT hardware module on.