RTC Day Byte

I directly read / write RTC through port 0x70 and 0x71. According to the manual, a weekday will contain the day of the week with Sunday = 1, and the values ​​range from 1 to 7. When I read the byte, I get today 4, that is, on Wednesday. Whereas when I read the RTC information with hwclock -r , this is Thursday, this is correct.

Setting the date using hwclock to another date and reading it using my code does not reflect changes in the weekday byte.

This problem persists on all systems. What could be the problem?

+4
source share
1 answer

From the OSDev Wiki (highlighted by me):

The RTC chip is able to track the current day of the week. All he increases his register "weekday" at midnight and reset it to zero if it reaches 7. Unfortunately, there is no guarantee that this registration was ever correctly installed (including when the user changes the time and date using the BIOS configuration screen). It is completely unreliable and should not be used.

The correct way to determine the current day of the week is to calculate it from the date.

I believe this answers both your initial question and why the manual change of the RTC date with hwclock does not reflect the change in the shift of the day of the week ( 0x07 ). If it's just an upside down counter at midnight, that explains a lot.

As for calculating the day of the week from the date without using system time functions such as strptime , look at this StackOverflow stream: C Program to find the day of the weekly date

+3
source

All Articles