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 PERIPH_RTT_H
24 #define PERIPH_RTT_H
25 
26 #include <stdint.h>
27 
28 #include "periph_conf.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #ifndef RTT_FREQUENCY
35 #warning "RTT_FREQUENCY undefined. Set RTT_FREQUENCY to the number of ticks" \
36  "per second for the current architecture."
37 #endif
38 
44 #define RTT_US_TO_TICKS(us) ((uint32_t)((uint64_t)(us) * RTT_FREQUENCY / 1000000UL))
45 
51 #define RTT_MS_TO_TICKS(ms) ( RTT_US_TO_TICKS((ms) * 1000) )
52 
58 #define RTT_SEC_TO_TICKS(sec) ( RTT_MS_TO_TICKS((sec) * 1000) )
59 
65 #define RTT_MIN_TO_TICKS(min) ( RTT_SEC_TO_TICKS((min) * 60) )
66 
72 #define RTT_TICKS_TO_US(ticks) ((uint32_t)((uint64_t)(ticks) * 1000000UL / RTT_FREQUENCY))
73 
79 #define RTT_TICKS_TO_MS(ticks) (RTT_TICKS_TO_US(ticks) / 1000)
80 
86 #define RTT_TICKS_TO_SEC(ticks) (RTT_TICKS_TO_MS(ticks) / 1000)
87 
93 #define RTT_TICKS_TO_MIN(ticks) (RTT_TICKS_TO_SEC(ticks) / 60)
94 
101 typedef void(*rtt_cb_t)(void *arg);
102 
106 void rtt_init(void);
107 
114 void rtt_set_overflow_cb(rtt_cb_t cb, void *arg);
115 
119 void rtt_clear_overflow_cb(void);
120 
126 uint32_t rtt_get_counter(void);
127 
133 void rtt_set_counter(uint32_t counter);
134 
142 void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg);
143 
151 uint32_t rtt_get_alarm(void);
152 
156 void rtt_clear_alarm(void);
157 
161 void rtt_poweron(void);
162 
166 void rtt_poweroff(void);
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 #endif /* PERIPH_RTT_H */
173 
void rtt_clear_overflow_cb(void)
Clear the overflow callback.
void(* rtt_cb_t)(void *arg)
Signature for the alarm callback.
Definition: rtt.h:101
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.