1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum
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 ****************************************************************************/
33 int rtc_read_datetime(struct tm
*tm
)
35 tm
->tm_sec
= BCD2DEC(BCDSEC
);
36 tm
->tm_min
= BCD2DEC(BCDMIN
);
37 tm
->tm_hour
= BCD2DEC(BCDHOUR
);
38 tm
->tm_wday
= BCD2DEC(BCDDAY
) - 1; /* timefuncs wants 0..6 for wday */
39 tm
->tm_mday
= BCD2DEC(BCDDATE
);
40 tm
->tm_mon
= BCD2DEC(BCDMON
) - 1;
41 tm
->tm_year
= BCD2DEC(BCDYEAR
) + 100;
46 int rtc_write_datetime(const struct tm
*tm
)
48 BCDSEC
= DEC2BCD(tm
->tm_sec
);
49 BCDMIN
= DEC2BCD(tm
->tm_min
);
50 BCDHOUR
= DEC2BCD(tm
->tm_hour
);
51 BCDDAY
= DEC2BCD(tm
->tm_wday
) + 1; /* chip wants 1..7 for wday */
52 BCDDATE
= DEC2BCD(tm
->tm_mday
);
53 BCDMON
= DEC2BCD(tm
->tm_mon
+ 1);
54 BCDYEAR
= DEC2BCD(tm
->tm_year
- 100);
60 /* This alarm code works with a flashed bootloader. This will not work with
64 /* Check whether the unit has been started by the RTC alarm function */
65 bool rtc_check_alarm_started(bool release_alarm
)
69 GSTATUS3
&= ~release_alarm
;
78 /* Check to see if the alarm has flaged since the last it was checked */
79 bool rtc_check_alarm_flag(void)
81 bool ret
=SRCPND
& 0x40000000;
88 /* set alarm time registers to the given time (repeat once per day) */
89 void rtc_set_alarm(int h
, int m
)
91 ALMMIN
= DEC2BCD(m
); /* minutes */
92 ALMHOUR
= DEC2BCD(h
); /* hour */
95 /* read out the current alarm time */
96 void rtc_get_alarm(int *h
, int *m
)
99 *h
= BCD2DEC(ALMHOUR
);
102 /* turn alarm on or off by setting the alarm flag enable
104 void rtc_enable_alarm(bool enable
)