In this method, the intention is to only write back to the RTCC if the register value has changed or it wasn't read from the device in the first place (i.e. a bcdsecs value was passed in):
// Write back the data if it is different to the contents of the
// register. Always write back if the data wasn't fetched with
// readData as the contents of the stop bit are unknown.
if (s != s2 || bcdSec < 0)
writeData(reg, s2);
This code looks like it will write back IF the register has changed OR it was read from the device. So basically, every time. I think it should be:
// Write back the data if it is different to the contents of the
// register. Always write back if the data wasn't fetched with
// readData as the contents of the stop bit are unknown.
if (s != s2 || bcdSec >= 0)
writeData(reg, s2);
In this method, the intention is to only write back to the RTCC if the register value has changed or it wasn't read from the device in the first place (i.e. a bcdsecs value was passed in):
This code looks like it will write back IF the register has changed OR it was read from the device. So basically, every time. I think it should be:
// Write back the data if it is different to the contents of the
// register. Always write back if the data wasn't fetched with
// readData as the contents of the stop bit are unknown.
if (s != s2 || bcdSec >= 0)
writeData(reg, s2);