2016-08-02 07:51:44 +02:00
|
|
|
#include <internals/rtc.h>
|
|
|
|
#include <rtc.h>
|
|
|
|
#include <mpu.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
integer()
|
|
|
|
Converts a BCD value to an integer.
|
|
|
|
*/
|
|
|
|
static int integer8(int bcd)
|
|
|
|
{
|
|
|
|
return (bcd & 0x0f) + 10 * (bcd >> 4);
|
|
|
|
}
|
|
|
|
static int integer16(int bcd)
|
|
|
|
{
|
|
|
|
return (bcd & 0xf) + 10 * ((bcd >> 4) & 0xf) + 100 * ((bcd >> 8) & 0xf)
|
|
|
|
+ 1000 * (bcd >> 12);
|
|
|
|
}
|
|
|
|
|
2016-08-08 15:01:33 +02:00
|
|
|
/*
|
|
|
|
rtc_getTime()
|
|
|
|
Reads the current time from the RTC. There is no guarantee that the
|
|
|
|
week day is correct (use the time API for that).
|
|
|
|
*/
|
2016-08-02 07:51:44 +02:00
|
|
|
struct RTCTime rtc_getTime(void)
|
|
|
|
{
|
|
|
|
volatile struct mod_rtc *rtc = isSH3() ? RTC_SH7705 : RTC_SH7305;
|
|
|
|
struct RTCTime time;
|
|
|
|
|
|
|
|
time.seconds = integer8(rtc->RSECCNT.BYTE);
|
|
|
|
time.minutes = integer8(rtc->RMINCNT.BYTE);
|
|
|
|
time.hours = integer8(rtc->RHRCNT.BYTE);
|
|
|
|
time.month_day = integer8(rtc->RDAYCNT.BYTE);
|
|
|
|
time.month = integer8(rtc->RMONCNT.BYTE);
|
2016-08-08 15:01:33 +02:00
|
|
|
time.year = integer16(rtc->RYRCNT.WORD);
|
2016-08-02 07:51:44 +02:00
|
|
|
time.week_day = rtc->RWKCNT;
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|