I'm trying to display current time in the bootloader to calculate how much a function takes to be executed. I used the time.h library but it doesn't work perfectly. any idea? used code:
#include<stdio.h>
#include<time.h>
time_t t;
time(&t);
printf("\before watchdog init: %s", ctime(&t));
error: implicit declaration of function 'time' [-Werror=implicit-function-declaration]
error: implicit declaration of function 'ctime' [-Werror=implicit-function-declaration]
There is no need for any C code to display the current time. Just execute the shell command date
.
To update the RTC time via the network use the sntp
command. If your board does not have a real time clock, you can emulate it with configuration setting CONFIG_RTC_EMULATION=y.
If you still need a solution in C, look at the code in cmd/date.c:
struct rtc_time tm;
int rcode = 0;
rcode = dm_rtc_get(dev, &tm);
if (rcode) {
puts("## Get date failed\n");
break;
}
printf ("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
tm.tm_year, tm.tm_mon, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.