diff options
-rw-r--r-- | firmware/target/hosted/rtc.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/firmware/target/hosted/rtc.c b/firmware/target/hosted/rtc.c index cb11d3ca3c..c1a3f3cbcc 100644 --- a/firmware/target/hosted/rtc.c +++ b/firmware/target/hosted/rtc.c | |||
@@ -22,6 +22,10 @@ | |||
22 | ****************************************************************************/ | 22 | ****************************************************************************/ |
23 | #include <time.h> | 23 | #include <time.h> |
24 | #include <sys/time.h> | 24 | #include <sys/time.h> |
25 | #include <sys/ioctl.h> | ||
26 | #include <linux/rtc.h> | ||
27 | #include <fcntl.h> | ||
28 | #include <unistd.h> | ||
25 | 29 | ||
26 | void rtc_init(void) | 30 | void rtc_init(void) |
27 | { | 31 | { |
@@ -37,10 +41,27 @@ int rtc_read_datetime(struct tm *tm) | |||
37 | 41 | ||
38 | int rtc_write_datetime(const struct tm *tm) | 42 | int rtc_write_datetime(const struct tm *tm) |
39 | { | 43 | { |
44 | #if defined(AGPTEK_ROCKER) | ||
40 | struct timeval tv; | 45 | struct timeval tv; |
46 | struct tm *tm_time; | ||
47 | |||
48 | int rtc = open("/dev/rtc0", O_WRONLY); | ||
41 | 49 | ||
42 | tv.tv_sec = mktime((struct tm *)tm); | 50 | tv.tv_sec = mktime((struct tm *)tm); |
43 | tv.tv_usec = 0; | 51 | tv.tv_usec = 0; |
44 | 52 | ||
45 | return settimeofday(&tv, NULL); | 53 | /* set system clock */ |
54 | settimeofday(&tv, NULL); | ||
55 | |||
56 | /* hw clock stores time in UTC */ | ||
57 | time_t now = time(NULL); | ||
58 | tm_time = gmtime(&now); | ||
59 | |||
60 | ioctl(rtc, RTC_SET_TIME, (struct rtc_time *)tm_time); | ||
61 | close(rtc); | ||
62 | |||
63 | return 0; | ||
64 | #else | ||
65 | return -1; | ||
66 | #endif | ||
46 | } | 67 | } |