Skip to content

Commit

Permalink
setdate: support decimal encoded RTC devices
Browse files Browse the repository at this point in the history
From: dennowiggle@github

The purpose of this issue is to document a change that may be helpful for
others.
I modified function rtcwrite() in the setdate application to support the real
time clock decimal format in addition to binary coded decimal.

I tested on an eZ80 system I am working on and could write both BCD and DEC
formats successfully. The eZ80 internal RTC supports both modes.

Here is the updated rtcwrite() function for setdate.c based on the 0.4 code
base.  (merged with 0.5 changes - AC)

Closes: #1122
  • Loading branch information
EtchedPixels committed Dec 5, 2024
1 parent 445ce9a commit 9dc3775
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions Applications/util/setdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int rtcwrite(void)
close(fd);
return 0;
}
if (rtc.type != CMOS_RTC_BCD) {
if (rtc.type != CMOS_RTC_BCD && rtc.type != CMOS_RTC_DEC) {
close (fd);
return 0;
}
Expand All @@ -191,14 +191,27 @@ int rtcwrite(void)
tm = localtime(&t);

p = rtc.data.bytes;
*p++ = bc((tm->tm_year + 1900) / 100);
*p++ = bc((tm->tm_year + 1900) % 100);
*p++ = bc(tm->tm_mon);
*p++ = bc(tm->tm_mday);
*p++ = bc(tm->tm_hour);
*p++ = bc(tm->tm_min);
*p++ = bc(tm->tm_sec);
*p = bc(tm->tm_wday);
if (rtc.type == CMOS_RTC_BCD)
{
*p++ = bc((tm->tm_year + 1900) / 100);
*p++ = bc((tm->tm_year + 1900) % 100);
*p++ = bc(tm->tm_mon);
*p++ = bc(tm->tm_mday);
*p++ = bc(tm->tm_hour);
*p++ = bc(tm->tm_min);
*p++ = bc(tm->tm_sec);
*p = bc(tm->tm_wday);
} else { /* CMOS_RTC_DEC */
uint16_t year = tm->tm_year + 1900;
*p++ = year & 0xFF;
*p++ = year >> 8;
*p++ = tm->tm_mon;
*p++ = tm->tm_mday;
*p++ = tm->tm_hour;
*p++ = tm->tm_min;
*p++ = tm->tm_sec;
*p = tm->tm_wday;
}

lseek(fd, 0, SEEK_SET);
puts("writing\n");
Expand Down

0 comments on commit 9dc3775

Please sign in to comment.