1
0
Fork 0
forked from len0rd/rockbox

Reworking of Archos RTC code to create a (slightly) more abstract RTC api

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8216 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Chapman 2005-12-11 00:47:40 +00:00
parent 6ddfac0806
commit 790b365595
3 changed files with 61 additions and 26 deletions

View file

@ -47,21 +47,18 @@ struct tm *get_time(void)
{
#ifndef SIMULATOR
#ifdef CONFIG_RTC
char rtcbuf[8];
char rtcbuf[7];
/* We don't need the first byte, but we want the indexes in the
buffer to match the data sheet */
rtc_read_multiple(1, &rtcbuf[1], 7);
rtc_read_datetime(rtcbuf);
tm.tm_sec = ((rtcbuf[0] & 0x70) >> 4) * 10 + (rtcbuf[0] & 0x0f);
tm.tm_min = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f);
tm.tm_hour = ((rtcbuf[2] & 0x30) >> 4) * 10 + (rtcbuf[2] & 0x0f);
tm.tm_wday = rtcbuf[3] & 0x07;
tm.tm_mday = ((rtcbuf[4] & 0x30) >> 4) * 10 + (rtcbuf[4] & 0x0f);
tm.tm_mon = ((rtcbuf[5] & 0x10) >> 4) * 10 + (rtcbuf[5] & 0x0f) - 1;
tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 100;
tm.tm_sec = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f);
tm.tm_min = ((rtcbuf[2] & 0x70) >> 4) * 10 + (rtcbuf[2] & 0x0f);
tm.tm_hour = ((rtcbuf[3] & 0x30) >> 4) * 10 + (rtcbuf[3] & 0x0f);
tm.tm_mday = ((rtcbuf[5] & 0x30) >> 4) * 10 + (rtcbuf[5] & 0x0f);
tm.tm_mon = ((rtcbuf[6] & 0x10) >> 4) * 10 + (rtcbuf[6] & 0x0f) - 1;
tm.tm_year = ((rtcbuf[7] & 0xf0) >> 4) * 10 + (rtcbuf[7] & 0x0f) + 100;
tm.tm_wday = rtcbuf[4] & 0x07;
if(tm.tm_wday == 7)
tm.tm_wday = 0;
tm.tm_yday = 0; /* Not implemented for now */
tm.tm_isdst = -1; /* Not implemented for now */
#else
@ -86,22 +83,19 @@ int set_time(const struct tm *tm)
{
#ifdef CONFIG_RTC
int rc;
int tmp;
char rtcbuf[7];
if (valid_time(tm))
{
rc = rtc_write(1, ((tm->tm_sec/10) << 4) | (tm->tm_sec%10));
rc |= rtc_write(2, ((tm->tm_min/10) << 4) | (tm->tm_min%10));
rc |= rtc_write(3, ((tm->tm_hour/10) << 4) | (tm->tm_hour%10));
tmp = tm->tm_wday;
if(tmp == 0)
tmp = 7;
rc |= rtc_write(4, tmp);
rc |= rtc_write(5, ((tm->tm_mday/10) << 4) | (tm->tm_mday%10));
rc |= rtc_write(6, (((tm->tm_mon+1)/10) << 4) | ((tm->tm_mon+1)%10));
rc |= rtc_write(7, (((tm->tm_year-100)/10) << 4) | ((tm->tm_year-100)%10));
rtcbuf[0]=((tm->tm_sec/10) << 4) | (tm->tm_sec%10);
rtcbuf[1]=((tm->tm_min/10) << 4) | (tm->tm_min%10);
rtcbuf[2]=((tm->tm_hour/10) << 4) | (tm->tm_hour%10);
rtcbuf[3]=tm->tm_wday;
rtcbuf[4]=((tm->tm_mday/10) << 4) | (tm->tm_mday%10);
rtcbuf[5]=(((tm->tm_mon+1)/10) << 4) | ((tm->tm_mon+1)%10);
rtcbuf[6]=(((tm->tm_year-100)/10) << 4) | ((tm->tm_year-100)%10);
rc |= rtc_write(8, 0x80); /* Out=1, calibration = 0 */
rc = rtc_write_datetime(rtcbuf);
if(rc)
return -1;