Time#
Internal timers and the timer application rely on a concept of time. The hardware abstraction layer provides functions for this purpose
State and functions#
Functions
-
void timeGetTimeInfo(timeInfo_t *ti)#
Get the current time.
- Parameters
ti – [out] pointer to a structure that will be filled out
-
void timeGetDateInfo(dateInfo_t *di)#
Get the current date.
- Parameters
di – [out] pointer to a structure that will be filled out
-
uint32_t timeCurrentMs(void)#
Get the current time in milliseconds.
This is the wall clock time. It should increase when the program isn’t running.
- Returns
time in milliseconds
-
uint32_t timeUptimeMs(void)#
Get the uptime in milliseconds.
This doesn’t need to reflect the current time but should be monotonically increasing during runtime. It can pause when the program is off.
- Returns
time in milliseconds
-
void timeSleep(uint32_t timeInMs)#
Sleep for a fixed period of time.
- Parameters
timeInMs – [in] amount of time to sleep
-
struct timeInfo_t#
- #include <time.h>
Structure for the time in a day.
-
struct dateInfo_t#
- #include <time.h>
Structure for a date in the Gregorian calendar.
Example#
In almost all cases it is better to use timeUptimeMs than timeCurrentMs
as it is simpler.
uint32_t firstTime = timeUptimeMs();
...
uint32_t elapsedTime = timeUptimeMs() - firstTime;
This doesn’t cope with the 32-bit wrap around. More work is needed in these cases.
To set the time/date of the calculator, ensure that all fields of the structure are filled in. This functionality won’t work with the simulator.
dateInfo_t date;
date.year = 2022;
date.month = 1;
date.day = 30;
timeSetDateInfo(&date);
To retrieve the time/date supply an allocated structure that will be written to.
timeInfo_t time;
timeGetTimeInfo(&time);
printf("This is the current hour: %d\n", time.hour);