1.5. time — System time

Source code: src/kernel/time.h, src/kernel/time.c

Test code: tst/kernel/time/main.c

Test coverage: src/kernel/time.c


Functions

int time_get(struct time_t *now_p)

Get current time in seconds and nanoseconds. The resolution of the time is implementation specific and may vary a lot between different architectures.

Return
zero(0) or negative error code.
Parameters
  • now_p: Read current time.

int time_set(struct time_t *new_p)

Set current time in seconds and nanoseconds.

Return
zero(0) or negative error code.
Parameters
  • new_p: New current time.

int time_add(struct time_t *res_p, struct time_t *left_p, struct time_t *right_p)

Add given times.

Return
zero(0) or negative error code.
Parameters
  • res_p: The result of the adding left_p to right_p.
  • left_p: First operand.
  • right_p: Second operand.

int time_subtract(struct time_t *res_p, struct time_t *left_p, struct time_t *right_p)

Subtract given times.

Return
zero(0) or negative error code.
Parameters
  • res_p: The result of the subtrancting left_p from right_p.
  • left_p: The operand to subtract from.
  • right_p: The operand to subtract.

void time_busy_wait_us(long useconds)

Busy wait for given number of microseconds.

NOTE: The maximum allowed time to sleep is target specific.

Return
void
Parameters
  • useconds: Microseconds to busy wait.

int time_unix_time_to_date(struct date_t *date_p, struct time_t *time_p)

Convert given unix time to a date.

Return
zero(0) or negative error code.
Parameters
  • date_p: Converted time.
  • time_p: Unix time to convert.

struct time_t
#include <time.h>

Public Members

int32_t seconds

Number of seconds.

int32_t nanoseconds

Number of nanoseconds.

struct date_t
#include <time.h>

A date in year, month, date, day, hour, minute and seconds.

Public Members

int second

Second [0..59].

int minute

Minute [0..59].

int hour

Hour [0..23].

int day

Weekday [1..7], where 1 is Monday and 7 is Sunday.

int date

Day in month [1..31]

int month

Month [1..12] where 1 is January and 12 is December.

int year

Year [1970..].