18 #ifndef XTIMER_TICK_CONVERSION_H
19 #define XTIMER_TICK_CONVERSION_H
22 #error "Do not include this file directly! Use xtimer.h instead"
32 #if (XTIMER_SHIFT != 0)
33 #if (XTIMER_HZ % 15625 != 0)
34 #error XTIMER_HZ must be a multiple of 15625 (5^6) when using XTIMER_SHIFT
36 #if (XTIMER_HZ > 1000000ul)
37 #if (XTIMER_HZ != (1000000ul << XTIMER_SHIFT))
38 #error XTIMER_HZ != (1000000ul << XTIMER_SHIFT)
42 static inline uint32_t _xtimer_ticks_from_usec(uint32_t usec) {
43 return (usec << XTIMER_SHIFT);
46 static inline uint64_t _xtimer_ticks_from_usec64(uint64_t usec) {
47 return (usec << XTIMER_SHIFT);
50 static inline uint32_t _xtimer_usec_from_ticks(uint32_t ticks) {
51 return (ticks >> XTIMER_SHIFT);
54 static inline uint64_t _xtimer_usec_from_ticks64(uint64_t ticks) {
55 return (ticks >> XTIMER_SHIFT);
59 #if ((XTIMER_HZ << XTIMER_SHIFT) != 1000000ul)
60 #error (XTIMER_HZ << XTIMER_SHIFT) != 1000000ul
64 static inline uint32_t _xtimer_ticks_from_usec(uint32_t usec) {
65 return (usec >> XTIMER_SHIFT);
68 static inline uint64_t _xtimer_ticks_from_usec64(uint64_t usec) {
69 return (usec >> XTIMER_SHIFT);
72 static inline uint32_t _xtimer_usec_from_ticks(uint32_t ticks) {
73 return (ticks << XTIMER_SHIFT);
76 static inline uint64_t _xtimer_usec_from_ticks64(uint64_t ticks) {
77 return (ticks << XTIMER_SHIFT);
80 #elif (XTIMER_HZ == (1000000ul)) || defined(MODULE_XTIMER_ON_ZTIMER)
83 static inline uint32_t _xtimer_usec_from_ticks(uint32_t ticks) {
87 static inline uint64_t _xtimer_usec_from_ticks64(uint64_t ticks) {
91 static inline uint32_t _xtimer_ticks_from_usec(uint32_t usec) {
95 static inline uint64_t _xtimer_ticks_from_usec64(uint64_t usec) {
99 #elif XTIMER_HZ == (32768ul)
104 static inline uint32_t _xtimer_ticks_from_usec(uint32_t usec) {
108 static inline uint64_t _xtimer_ticks_from_usec64(uint64_t usec) {
112 static inline uint32_t _xtimer_usec_from_ticks(uint32_t ticks) {
115 uint64_t usec = (uint64_t)ticks * 15625ul;
119 static inline uint64_t _xtimer_usec_from_ticks64(uint64_t ticks) {
121 uint64_t usec = (uint64_t)ticks * 15625ul;
127 #if ((XTIMER_HZ % 15625) == 0)
128 #error Unsupported hardware timer frequency (XTIMER_HZ), missing XTIMER_SHIFT in board.h? See xtimer.h documentation for more info
130 #error Unknown hardware timer frequency (XTIMER_HZ), check board.h and/or add an implementation in sys/include/xtimer/tick_conversion.h