Search code examples
linux-device-driveri2creal-time-clock

in Linux, when reading an I2C-based RTC, who handles counter carry-over conditions?


When reading multiple bytes from an I2C-based RTC, it seems that it is possible that while reading each byte, one of the values may increment.

For instance, if the time is:

2014-12-31 23:59:59

as you're reading this value, the time may roll-over to

2015-01-01 00:00:00

so you may actually read:

2015-01-01 23:59:59

(depending on which values you read first).

So, is it the rtc driver's responsibility to ensure a reliable read?


Solution

  • Reading the datasheet for the DS1337, page 9 states:

    When reading or writing the time and date registers, secondary (user) buffers are used to prevent errors when the internal registers update. When reading the time and date registers, the user buffers are synchronized to the internal registers on any start or stop and when the register pointer rolls over to zero.

    Therefore, if reading (or writing) occurs with a single I2C operation (without wrapping around), the RTC device guarantees that everything is synchronized.

    [I haven't examined the datasheets for any other devices, but I assume they all work similarly.]