aboutsummaryrefslogtreecommitdiff
path: root/libc/gettimeofday.c
blob: b0561c36b5b6daff017964183e7e3b09c6ef1de2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdint.h>

#include "stm32f4xx_hal.h"

/* Don't #include <sys/time.h> because of conflicting prototype in newlib. */

/* from the manpage: */
struct timeval {
    time_t      tv_sec;     /* seconds */
    suseconds_t tv_usec;    /* microseconds */
};

struct timezone {
    int tz_minuteswest;     /* minutes west of Greenwich */
    int tz_dsttime;         /* type of DST correction */
};

int gettimeofday(struct timeval *tv, struct timezone *tz)
{
    uint32_t tick = HAL_GetTick();      /* uptime in ms */

    tv->tv_sec = tick / 1000;
    tv->tv_usec = (tick % 1000) * 1000;

    return 0;
}