OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 12:30 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Error in CMOS Time and Date code?
PostPosted: Tue Aug 27, 2013 7:33 am 
Offline
Member
Member
User avatar

Joined: Fri Jul 03, 2009 6:21 am
Posts: 359
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:
    } 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:
    } while( ! (last_second == second) && (last_minute == minute) && (last_hour == hour) &&
               (last_day == day) && (last_month == month) && (last_year == year) &&
               (last_century == century) );


Top
 Profile  
 
 Post subject: Re: Error in CMOS Time and Date code?
PostPosted: Tue Aug 27, 2013 8:59 am 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
Hi bwat - you do realize you didn't actually negate the full expression - just one of its terms?


Top
 Profile  
 
 Post subject: Re: Error in CMOS Time and Date code?
PostPosted: Tue Aug 27, 2013 11:37 am 
Offline
Member
Member
User avatar

Joined: Fri Jul 03, 2009 6:21 am
Posts: 359
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.


Top
 Profile  
 
 Post subject: Re: Error in CMOS Time and Date code?
PostPosted: Tue Aug 27, 2013 9:39 pm 
Offline
Member
Member
User avatar

Joined: Sat Apr 30, 2011 12:50 am
Posts: 308
It looks correct to me:
Fetch new values while they're the same... that is exactly what the coder wanted.


Top
 Profile  
 
 Post subject: Re: Error in CMOS Time and Date code?
PostPosted: Wed Aug 28, 2013 10:29 am 
Offline
Member
Member
User avatar

Joined: Fri Jul 03, 2009 6:21 am
Posts: 359
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.


Top
 Profile  
 
 Post subject: Re: Error in CMOS Time and Date code?
PostPosted: Thu Aug 29, 2013 5:11 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
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.


Top
 Profile  
 
 Post subject: Re: Error in CMOS Time and Date code?
PostPosted: Thu Aug 29, 2013 1:12 pm 
Offline
Member
Member
User avatar

Joined: Fri Jul 03, 2009 6:21 am
Posts: 359
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group