- fix RTC write;
This commit is contained in:
mtabachenko 2008-09-29 09:37:23 +00:00
parent ca9c79639d
commit 0c3889afb1
1 changed files with 127 additions and 103 deletions

View File

@ -38,6 +38,8 @@ const u8 valRTC[100]= { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99 };
const u8 cmdSizes[8] = {1, 7, 3, 1, 3, 1, 1};
typedef struct
{
@ -72,9 +74,10 @@ void rtcInit()
//====================================================== RTC write
INLINE void rtcPost(u8 data)
{
if (rtc.cmdSize == 0)
{
if (rtc.bitPosRead != rtc.bitSizeRead) return;
rtc.bitPosRead = 0;
if ((data & 0x0F) == 0x06)
@ -91,6 +94,13 @@ INLINE void rtcPost(u8 data)
rtc.stat = (rtc.cmd & 0x01);
rtc.cmd = (rtc.cmd & 0x0E)>>1;
//printlog("+++++RTC: execute command 0x%02X (%s)\n", rtc.cmd, rtc.stat?"read":"write");
if (!rtc.stat)
{
rtc.cmdSize = cmdSizes[rtc.cmd];
return;
}
else
rtc.cmdSize = 0;
if (rtc.stat)
{
@ -114,9 +124,15 @@ INLINE void rtcPost(u8 data)
time_t tm;
time(&tm);
struct tm *tm_local= localtime(&tm);
u8 hour = tm_local->tm_hour, noon=0;
if (hour>11)
{
hour-=12;
noon=1;
}
rtc.dataRead2 = ( ((valRTC[tm_local->tm_hour] & 0x3F) << 0)
| ((tm_local->tm_hour>12?1:0) << 6)
rtc.dataRead2 = ( ((valRTC[hour]) << 0)
//| (noon << 7)
| (valRTC[tm_local->tm_min] << 8)
| (valRTC[tm_local->tm_sec] << 16));
@ -134,8 +150,15 @@ INLINE void rtcPost(u8 data)
time_t tm;
time(&tm);
struct tm *tm_local= localtime(&tm);
rtc.dataRead1 = ( ((valRTC[tm_local->tm_hour] & 0x3F) << 0)
| ((tm_local->tm_hour>12?1:0) << 6)
u8 hour = tm_local->tm_hour, noon=0;
if (hour>11)
{
hour-=12;
noon=1;
}
rtc.dataRead1 = ( ((valRTC[hour]) << 0)
//| (noon << 6)
| (valRTC[tm_local->tm_min] << 8)
| (valRTC[tm_local->tm_sec] << 16));
@ -159,9 +182,10 @@ INLINE void rtcPost(u8 data)
break;
}
}
else
{
//printlog("RTC: write %X\n", rtc.cmd);
return;
}
rtc.cmdSize--;
//printlog("RTC: write %X val=%X\n", rtc.cmd, data);
switch (rtc.cmd)
{
case 0: // status1
@ -198,7 +222,6 @@ INLINE void rtcPost(u8 data)
}
}
}
INLINE u8 rtcRead()
{
@ -227,6 +250,7 @@ INLINE void rtcWrite(u16 val)
rtc.bitPosWrite++;
if (rtc.bitPosWrite == 8)
{
//printlog("RTC: write\n");
rtcPost(rtc.dataWrite);
rtc.bitPosWrite = 0;
rtc.dataWrite = 0;