mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-10 05:32:40 -05:00
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
This commit is contained in:
parent
1af78b99d9
commit
a81391b623
1 changed files with 22 additions and 1 deletions
|
|
@ -22,6 +22,10 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <linux/rtc.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
void rtc_init(void)
|
void rtc_init(void)
|
||||||
{
|
{
|
||||||
|
|
@ -37,10 +41,27 @@ int rtc_read_datetime(struct tm *tm)
|
||||||
|
|
||||||
int rtc_write_datetime(const struct tm *tm)
|
int rtc_write_datetime(const struct tm *tm)
|
||||||
{
|
{
|
||||||
|
#if defined(AGPTEK_ROCKER)
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
struct tm *tm_time;
|
||||||
|
|
||||||
|
int rtc = open("/dev/rtc0", O_WRONLY);
|
||||||
|
|
||||||
tv.tv_sec = mktime((struct tm *)tm);
|
tv.tv_sec = mktime((struct tm *)tm);
|
||||||
tv.tv_usec = 0;
|
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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue