mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
timex: make functions static inline
This commit makes all one- or two-liners in timex a static inline function, defined in the header file.
This commit is contained in:
parent
fe2284454d
commit
8c4a874161
@ -17,6 +17,7 @@
|
|||||||
#define __TIMEX_H
|
#define __TIMEX_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
// mspgcc bug : PRIxxx macros not defined before mid-2011 versions
|
// mspgcc bug : PRIxxx macros not defined before mid-2011 versions
|
||||||
@ -24,6 +25,8 @@
|
|||||||
#define PRIu32 "lu"
|
#define PRIu32 "lu"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SEC_IN_USEC 1000000
|
||||||
|
|
||||||
typedef struct timex_t {
|
typedef struct timex_t {
|
||||||
uint32_t seconds;
|
uint32_t seconds;
|
||||||
uint32_t microseconds;
|
uint32_t microseconds;
|
||||||
@ -47,32 +50,48 @@ int timex_cmp(const timex_t a, const timex_t b);
|
|||||||
/**
|
/**
|
||||||
* @brief Corrects timex_t structure so that microseconds < 1000000
|
* @brief Corrects timex_t structure so that microseconds < 1000000
|
||||||
*/
|
*/
|
||||||
void timex_normalize(timex_t *time);
|
static inline void timex_normalize(timex_t *time)
|
||||||
|
{
|
||||||
|
time->seconds += (time->microseconds / SEC_IN_USEC);
|
||||||
|
time->microseconds %= SEC_IN_USEC;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Tests a timex_t for normalization
|
* @brief Tests a timex_t for normalization
|
||||||
*
|
*
|
||||||
* @return true for a normalized timex_t, false otherwise
|
* @return true for a normalized timex_t, false otherwise
|
||||||
*/
|
*/
|
||||||
int timex_isnormalized(timex_t *time);
|
static inline int timex_isnormalized(timex_t *time)
|
||||||
|
{
|
||||||
|
return (time->microseconds < SEC_IN_USEC);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Denormalizes a timex_t to a uint64_t
|
* @brief Denormalizes a timex_t to a uint64_t
|
||||||
*
|
*
|
||||||
* @return timex representation as uint64_t
|
* @return timex representation as uint64_t
|
||||||
*/
|
*/
|
||||||
uint64_t timex_uint64(const timex_t a);
|
static inline uint64_t timex_uint64(const timex_t a)
|
||||||
|
{
|
||||||
|
return (uint64_t) a.seconds * SEC_IN_USEC + a.microseconds;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts a uint64_t of microseconds to a timex_t
|
* @brief Converts a uint64_t of microseconds to a timex_t
|
||||||
*
|
*
|
||||||
* @return a timex representation of an uint64 timestamp.
|
* @return a timex representation of an uint64 timestamp.
|
||||||
*/
|
*/
|
||||||
timex_t timex_from_uint64(const uint64_t timestamp);
|
static inline timex_t timex_from_uint64(const uint64_t timestamp)
|
||||||
|
{
|
||||||
|
return timex_set(timestamp / SEC_IN_USEC, timestamp % SEC_IN_USEC);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints a timex_t
|
* @brief Prints a timex_t
|
||||||
*/
|
*/
|
||||||
void timex_print(const timex_t t);
|
static inline void timex_print(const timex_t t)
|
||||||
|
{
|
||||||
|
printf("Seconds: %" PRIu32 " - Microseconds: %" PRIu32 "\n", t.seconds, t.microseconds);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __TIMEX_H */
|
#endif /* __TIMEX_H */
|
||||||
|
@ -26,8 +26,6 @@
|
|||||||
|
|
||||||
#include "timex.h"
|
#include "timex.h"
|
||||||
|
|
||||||
#define SEC_IN_USEC 1000000
|
|
||||||
|
|
||||||
timex_t timex_add(const timex_t a, const timex_t b)
|
timex_t timex_add(const timex_t a, const timex_t b)
|
||||||
{
|
{
|
||||||
#if ENABLE_DEBUG
|
#if ENABLE_DEBUG
|
||||||
@ -48,17 +46,6 @@ timex_t timex_add(const timex_t a, const timex_t b)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timex_normalize(timex_t *time)
|
|
||||||
{
|
|
||||||
time->seconds += (time->microseconds / SEC_IN_USEC);
|
|
||||||
time->microseconds %= SEC_IN_USEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
int timex_isnormalized(timex_t *time)
|
|
||||||
{
|
|
||||||
return (time->microseconds < SEC_IN_USEC);
|
|
||||||
}
|
|
||||||
|
|
||||||
timex_t timex_set(uint32_t seconds, uint32_t microseconds)
|
timex_t timex_set(uint32_t seconds, uint32_t microseconds)
|
||||||
{
|
{
|
||||||
timex_t result;
|
timex_t result;
|
||||||
@ -120,18 +107,3 @@ int timex_cmp(const timex_t a, const timex_t b)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t timex_uint64(const timex_t a)
|
|
||||||
{
|
|
||||||
return (uint64_t) a.seconds * SEC_IN_USEC + a.microseconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
timex_t timex_from_uint64(const uint64_t timestamp)
|
|
||||||
{
|
|
||||||
return timex_set(timestamp / SEC_IN_USEC, timestamp % SEC_IN_USEC);
|
|
||||||
}
|
|
||||||
|
|
||||||
void timex_print(const timex_t t)
|
|
||||||
{
|
|
||||||
printf("Seconds: %" PRIu32 " - Microseconds: %" PRIu32 "\n", t.seconds, t.microseconds);
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user