Error in CMOS Time and Date code?

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Error in CMOS Time and Date code?

Post 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) );
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Error in CMOS Time and Date code?

Post by sortie »

Hi bwat - you do realize you didn't actually negate the full expression - just one of its terms?
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Error in CMOS Time and Date code?

Post by bwat »

Well spotted! The idea was to negate the entire conjunction not just the first conjunct.
Every universe of discourse has its logical structure --- S. K. Langer.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Error in CMOS Time and Date code?

Post by Nessphoro »

It looks correct to me:
Fetch new values while they're the same... that is exactly what the coder wanted.
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Error in CMOS Time and Date code?

Post 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.
Every universe of discourse has its logical structure --- S. K. Langer.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Error in CMOS Time and Date code?

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Error in CMOS Time and Date code?

Post by bwat »

A big thank you to you and everyone who contributes to the wiki. Your efforts are appreciated!
Every universe of discourse has its logical structure --- S. K. Langer.
Post Reply