Skip to content

Commit c72f37a

Browse files
Merge pull request RIOT-OS#3174 from daniel-k/periph_rtt_conv
periph/rtt: add macros for time to tick conversion
2 parents 38a5f41 + 80c13d1 commit c72f37a

File tree

1 file changed

+33
-0
lines changed
  • drivers/include/periph

1 file changed

+33
-0
lines changed

drivers/include/periph/rtt.h

+33
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,39 @@ extern "C" {
3232
/* guard file in case no RTT device was specified */
3333
#if RTT_NUMOF
3434

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+
40+
/**
41+
* @brief Convert microseconds to rtt ticks
42+
* @param[in] us number of microseconds
43+
* @return rtt ticks
44+
*/
45+
#define RTT_US_TO_TICKS(us) ((uint32_t)((uint64_t)(us) * RTT_FREQUENCY / 1000000UL))
46+
47+
/**
48+
* @brief Convert milliseconds to rtt ticks
49+
* @param[in] ms number of milliseconds
50+
* @return rtt ticks
51+
*/
52+
#define RTT_MS_TO_TICKS(ms) ( RTT_US_TO_TICKS((ms) * 1000) )
53+
54+
/**
55+
* @brief Convert seconds to rtt ticks
56+
* @param[in] sec number of seconds
57+
* @return rtt ticks
58+
*/
59+
#define RTT_SEC_TO_TICKS(sec) ( RTT_MS_TO_TICKS((sec) * 1000) )
60+
61+
/**
62+
* @brief Convert minutes to rtt ticks
63+
* @param[in] min number of minutes
64+
* @return rtt ticks
65+
*/
66+
#define RTT_MIN_TO_TICKS(min) ( RTT_SEC_TO_TICKS((min) * 60) )
67+
3568
/**
3669
* @brief Signature for the alarm callback
3770
*

0 commit comments

Comments
 (0)