mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
some coding style fixes for timex.c
This commit is contained in:
parent
3d85573f9d
commit
c6ace1bdbb
@ -1,30 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "timex.h"
|
||||
|
||||
timex_t timex_add(const timex_t a, const timex_t b) {
|
||||
timex_t timex_add(const timex_t a, const timex_t b)
|
||||
{
|
||||
timex_t result;
|
||||
result.seconds = a.seconds + b.seconds;
|
||||
result.microseconds = a.microseconds + b.microseconds;
|
||||
|
||||
if (result.microseconds < a.microseconds) {
|
||||
if(result.microseconds < a.microseconds) {
|
||||
result.seconds++;
|
||||
}
|
||||
|
||||
/* if (result.microseconds > 1000000) {
|
||||
result.microseconds -= 1000000;
|
||||
result.seconds++;
|
||||
}
|
||||
*/
|
||||
/* if (result.microseconds > 1000000) {
|
||||
result.microseconds -= 1000000;
|
||||
result.seconds++;
|
||||
}
|
||||
*/
|
||||
return result;
|
||||
}
|
||||
|
||||
void timex_normalize(timex_t *time) {
|
||||
void timex_normalize(timex_t *time)
|
||||
{
|
||||
time->seconds += (time->microseconds / 1000000);
|
||||
time->microseconds %= 1000000;
|
||||
}
|
||||
|
||||
timex_t timex_set(uint32_t seconds, uint32_t microseconds) {
|
||||
timex_t timex_set(uint32_t seconds, uint32_t microseconds)
|
||||
{
|
||||
timex_t result;
|
||||
result.seconds = seconds;
|
||||
result.microseconds = microseconds;
|
||||
@ -32,7 +36,8 @@ timex_t timex_set(uint32_t seconds, uint32_t microseconds) {
|
||||
return result;
|
||||
}
|
||||
|
||||
timex_t timex_sub(const timex_t a, const timex_t b) {
|
||||
timex_t timex_sub(const timex_t a, const timex_t b)
|
||||
{
|
||||
timex_t result;
|
||||
result.seconds = a.seconds - b.seconds;
|
||||
result.microseconds = a.microseconds - b.microseconds;
|
||||
@ -40,15 +45,26 @@ timex_t timex_sub(const timex_t a, const timex_t b) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int timex_cmp(const timex_t a, const timex_t b) {
|
||||
if (a.seconds < b.seconds) return -1;
|
||||
if (a.seconds == b.seconds) {
|
||||
if (a.microseconds < b.microseconds) return -1;
|
||||
if (a.microseconds == b.microseconds) return 0;
|
||||
int timex_cmp(const timex_t a, const timex_t b)
|
||||
{
|
||||
if(a.seconds < b.seconds) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(a.seconds == b.seconds) {
|
||||
if(a.microseconds < b.microseconds) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(a.microseconds == b.microseconds) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void timex_print(const timex_t t) {
|
||||
printf("Seconds: %u - Microseconds: %u\n", t.seconds, t.microseconds);
|
||||
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