1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

added timex_uint64 function

This commit is contained in:
Christian Mehlis 2013-12-25 17:01:55 +01:00
parent c9b0f4784a
commit 5a6e16cfc3
2 changed files with 18 additions and 4 deletions

View File

@ -41,6 +41,13 @@ int timex_cmp(const timex_t a, const timex_t b);
*/
void timex_normalize(timex_t *time);
/**
* @brief Denormalizes a timex_t to a uint64_t
*
* @return timex representation as uint64_t
*/
uint64_t timex_uint64(const timex_t a);
/**
* @brief Prints a timex_t
*/

View File

@ -3,6 +3,8 @@
#include "timex.h"
#define SEC_IN_USEC 1000000
timex_t timex_add(const timex_t a, const timex_t b)
{
timex_t result;
@ -13,8 +15,8 @@ timex_t timex_add(const timex_t a, const timex_t b)
result.seconds++;
}
/* if (result.microseconds > 1000000) {
result.microseconds -= 1000000;
/* if (result.microseconds > SEC_IN_USEC) {
result.microseconds -= SEC_IN_USEC;
result.seconds++;
}
*/
@ -23,8 +25,8 @@ timex_t timex_add(const timex_t a, const timex_t b)
void timex_normalize(timex_t *time)
{
time->seconds += (time->microseconds / 1000000);
time->microseconds %= 1000000;
time->seconds += (time->microseconds / SEC_IN_USEC);
time->microseconds %= SEC_IN_USEC;
}
timex_t timex_set(uint32_t seconds, uint32_t microseconds)
@ -64,6 +66,11 @@ int timex_cmp(const timex_t a, const timex_t b)
return 1;
}
uint64_t timex_uint64(const timex_t a)
{
return (uint64_t) a.seconds * SEC_IN_USEC + a.microseconds;
}
void timex_print(const timex_t t)
{
printf("Seconds: %"PRIu32" - Microseconds: %"PRIu32"\n", t.seconds, t.microseconds);