Page 1 of 1

Error in CMOS Time and Date code?

Posted: Tue Aug 27, 2013 7:33 am
by bwat
Can someone take a look at this page:

http://wiki.osdev.org/CMOS

go down to the C code example with the heading "Reading All RTC Time and Date Registers". Now look at the do-while loop which contains the comment "This uses the "read registers until you get the same values twice in a row". Is the condition in the do-while loop not wrong? instead of

Code: Select all

    } while( (last_second == second) && (last_minute == minute) && (last_hour == hour) &&
               (last_day == day) && (last_month == month) && (last_year == year) &&
               (last_century == century) );
would you not want its negation:

Code: Select all

    } while( ! (last_second == second) && (last_minute == minute) && (last_hour == hour) &&
               (last_day == day) && (last_month == month) && (last_year == year) &&
               (last_century == century) );

Re: Error in CMOS Time and Date code?

Posted: Tue Aug 27, 2013 8:59 am
by sortie
Hi bwat - you do realize you didn't actually negate the full expression - just one of its terms?

Re: Error in CMOS Time and Date code?

Posted: Tue Aug 27, 2013 11:37 am
by bwat
Well spotted! The idea was to negate the entire conjunction not just the first conjunct.

Re: Error in CMOS Time and Date code?

Posted: Tue Aug 27, 2013 9:39 pm
by Nessphoro
It looks correct to me:
Fetch new values while they're the same... that is exactly what the coder wanted.

Re: Error in CMOS Time and Date code?

Posted: Wed Aug 28, 2013 10:29 am
by bwat
But the comment in the code is "This uses the "read registers until you get the same values twice in a row" - emphasis mine. Surely reading the same values twice means it has stabilised.

Re: Error in CMOS Time and Date code?

Posted: Thu Aug 29, 2013 5:11 am
by Brendan
Hi,
bwat wrote:Can someone take a look at this page:

http://wiki.osdev.org/CMOS

go down to the C code example with the heading "Reading All RTC Time and Date Registers". Now look at the do-while loop which contains the comment "This uses the "read registers until you get the same values twice in a row". Is the condition in the do-while loop not wrong?
It was wrong - I've changed it. :)


Cheers,

Brendan

Re: Error in CMOS Time and Date code?

Posted: Thu Aug 29, 2013 1:12 pm
by bwat
A big thank you to you and everyone who contributes to the wiki. Your efforts are appreciated!