diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2018-04-10 22:49:09 +0200 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2018-06-12 10:31:16 +0200 |
commit | a81391b62330e18c82ecb8b277528828d7e0e516 (patch) | |
tree | 1c38a033eeb7a257cadb3c42942a4365d491d76c /firmware/target/hosted | |
parent | 1af78b99d90629cfc90805b18270afaa486ddb50 (diff) | |
download | rockbox-a81391b62330e18c82ecb8b277528828d7e0e516.tar.gz rockbox-a81391b62330e18c82ecb8b277528828d7e0e516.zip |
Agptek Rocker: Fix saving time in hwclock
Rocker is configured with CST (China Standard Time) timezone
which is UTC+8. Time in RTC is stored in UTC.
Change-Id: Ib9c03e0f0a1d3ea3a69f238cb083809ea9386e2a
Diffstat (limited to 'firmware/target/hosted')
-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 @@ ****************************************************************************/ #include <time.h> #include <sys/time.h> +#include <sys/ioctl.h> +#include <linux/rtc.h> +#include <fcntl.h> +#include <unistd.h> void rtc_init(void) { @@ -37,10 +41,27 @@ int rtc_read_datetime(struct tm *tm) int rtc_write_datetime(const struct tm *tm) { +#if defined(AGPTEK_ROCKER) struct timeval tv; + struct tm *tm_time; + + int rtc = open("/dev/rtc0", O_WRONLY); tv.tv_sec = mktime((struct tm *)tm); tv.tv_usec = 0; - return settimeofday(&tv, NULL); + /* set system clock */ + settimeofday(&tv, NULL); + + /* hw clock stores time in UTC */ + time_t now = time(NULL); + tm_time = gmtime(&now); + + ioctl(rtc, RTC_SET_TIME, (struct rtc_time *)tm_time); + close(rtc); + + return 0; +#else + return -1; +#endif } |