dpl_time.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Inria
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef DPL_DPL_TIME_H
21 #define DPL_DPL_TIME_H
22 
23 #include "xtimer.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
32 #define DPL_TICKS_PER_SEC (XTIMER_HZ)
33 
39 static inline dpl_time_t dpl_time_get(void)
40 {
41  return xtimer_now().ticks32;
42 }
43 
52 static inline dpl_error_t dpl_time_ms_to_ticks(uint32_t ms, dpl_time_t *out_ticks)
53 {
54  *out_ticks = xtimer_ticks_from_usec(ms * US_PER_MS).ticks32;
55  return DPL_OK;
56 }
57 
66 static inline dpl_error_t dpl_time_ticks_to_ms(dpl_time_t ticks, uint32_t *out_ms)
67 {
68  xtimer_ticks32_t val = {.ticks32 = ticks};
69  *out_ms = xtimer_usec_from_ticks(val) * US_PER_MS;
70  return DPL_OK;
71 }
72 
80 static inline dpl_time_t dpl_time_ms_to_ticks32(uint32_t ms)
81 {
83 }
84 
93 {
94  xtimer_ticks32_t val = {.ticks32 = ticks};
95  return xtimer_usec_from_ticks(val) * US_PER_MS;
96 }
97 
103 static inline void dpl_time_delay(dpl_time_t ticks)
104 {
105  xtimer_ticks32_t val = {.ticks32 = ticks};
107 }
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* DPL_DPL_TIME_H */
dpl_time_get
static dpl_time_t dpl_time_get(void)
Returns the low 32 bits of cputime.
Definition: dpl_time.h:39
xtimer_ticks32_t::ticks32
uint32_t ticks32
Tick count.
Definition: xtimer.h:70
xtimer_now
static xtimer_ticks32_t xtimer_now(void)
get the current system time as 32bit time stamp value
dpl_time_ms_to_ticks32
static dpl_time_t dpl_time_ms_to_ticks32(uint32_t ms)
Converts the given number of milliseconds into cputime ticks.
Definition: dpl_time.h:80
xtimer_tsleep32
static void xtimer_tsleep32(xtimer_ticks32_t ticks)
Stop execution of a thread for some time, 32bit version.
dpl_time_ms_to_ticks
static dpl_error_t dpl_time_ms_to_ticks(uint32_t ms, dpl_time_t *out_ticks)
Converts the given number of milliseconds into cputime ticks.
Definition: dpl_time.h:52
xtimer_ticks_from_usec
static xtimer_ticks32_t xtimer_ticks_from_usec(uint32_t usec)
Convert microseconds to xtimer ticks.
dpl_time_t
uint32_t dpl_time_t
dpl time type
Definition: dpl_types.h:55
dpl_time_ticks_to_ms32
static dpl_time_t dpl_time_ticks_to_ms32(dpl_time_t ticks)
Convert the given number of ticks into milliseconds.
Definition: dpl_time.h:92
dpl_time_delay
static void dpl_time_delay(dpl_time_t ticks)
Wait until the number of ticks has elapsed, BLOICKING.
Definition: dpl_time.h:103
xtimer_ticks32_t
xtimer timestamp (32 bit)
Definition: xtimer.h:69
xtimer_usec_from_ticks
static uint32_t xtimer_usec_from_ticks(xtimer_ticks32_t ticks)
Convert xtimer ticks to microseconds.
dpl_error_t
enum dpl_error dpl_error_t
dep error type
Definition: dpl_error.h:49
US_PER_MS
#define US_PER_MS
The number of microseconds per millisecond.
Definition: timex.h:54
xtimer.h
xtimer interface definitions
dpl_time_ticks_to_ms
static dpl_error_t dpl_time_ticks_to_ms(dpl_time_t ticks, uint32_t *out_ms)
Convert the given number of ticks into milliseconds.
Definition: dpl_time.h:66