1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2011 by Amaury Pouly
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 #include "timefuncs.h"
27 #include "rtc-imx233.h"
29 #define YEAR1980 315532800 /* 1980/1/1 00:00:00 in UTC */
33 /* rtc-imx233 is initialized by the system */
36 int rtc_read_datetime(struct tm
*tm
)
38 uint32_t seconds
= imx233_rtc_read_seconds();
39 #if defined(SANSA_FUZEPLUS) || defined(CREATIVE_ZENXFI3)
40 /* The OF uses PERSISTENT2 register to keep the adjustment and only changes
41 * SECONDS if necessary. */
42 seconds
+= imx233_rtc_read_persistent(2);
44 /* The Freescale recommended way of keeping time is the number of seconds
45 * since 00:00 1/1/1980 */
49 gmtime_r(&seconds
, tm
);
54 int rtc_write_datetime(const struct tm
*tm
)
58 seconds
= mktime((struct tm
*)tm
);
60 #if defined(SANSA_FUZEPLUS) || defined(CREATIVE_ZENXFI3)
61 /* The OF uses PERSISTENT2 register to keep the adjustment and only changes
62 * SECONDS if necessary.
63 * NOTE: the OF uses this mechanism to prevent roll back in time. Although
64 * Rockbox will handle a negative PERSISTENT2 value, the OF will detect
65 * it and won't return in time before SECONDS */
66 imx233_rtc_write_persistent(2, seconds
- imx233_rtc_read_seconds());
68 /* The Freescale recommended way of keeping time is the number of seconds
69 * since 00:00 1/1/1980 */
70 imx233_rtc_write_seconds(seconds
- YEAR1980
);
76 void rtc_set_alarm(int h
, int m
)
82 void rtc_get_alarm(int *h
, int *m
)
88 void rtc_enable_alarm(bool enable
)
93 bool rtc_check_alarm_started(bool release_alarm
)
99 bool rtc_check_alarm_flag(void)