Ajay
Ajay

Reputation: 75

How to get system time in Zephyr RTOS?

I'm looking for ways to get current system time displayed in Zephyr RTOS(2.0) from user-space area. I'm using gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu tool-chain. Something similar to 'localtime' supported in GCC.

Upvotes: 3

Views: 5898

Answers (2)

Alexander Kozhinov
Alexander Kozhinov

Reputation: 11

You may use rtc_get_time function. Here is the code to sample: https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/drivers/rtc/src/main.c

In general Zephyr needs a date-time source it fetches at startup to be able to provide absolute time. The realtive timestamp could be aquired by reading systicks for example.

Mor on time utilities could be found here: https://docs.zephyrproject.org/latest/kernel/timeutil.html#

Upvotes: 0

Youssif Saeed
Youssif Saeed

Reputation: 13295

There is no such thing on Zephyr because this is an OS for embedded hardware and does not have the features of a full fledged OS. The C library function localtime gets its information from the OS as can be described in the links below:-

This is something that Zephyr does not have because most embedded hardware have no access to the internet and therefore have no concept of real time. The closest thing you can find on Zephyr are Kernel clocks and kernel timing services. Please see links below for more information:-

Upvotes: 5

Related Questions