OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 44 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: print correctly BCD CMOS RTC values
PostPosted: Sat Oct 13, 2018 4:28 pm 
Offline
Member
Member

Joined: Wed Aug 29, 2018 4:42 pm
Posts: 122
hi,
i'm trying to implement a rtc with cmos(it isn't updated in github)i can get the values, but when i try to print it i only get something buggy.when i was reading some other post, i understood that this is cause it is in BCD and not as int values, so i have to convert it, but the only two abiavle ways that can compile with my code, doesn't work, they just display the same.how can i convert a BCD to a int value?


Attachments:
cmos bug.jpg
cmos bug.jpg [ 12.34 KiB | Viewed 2251 times ]
Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sat Oct 13, 2018 4:35 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
https://en.wikipedia.org/wiki/Binary-coded_decimal


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sat Oct 13, 2018 4:37 pm 
Offline
Member
Member

Joined: Wed Aug 29, 2018 4:42 pm
Posts: 122
thanks, but this actually didn't work for me.


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sat Oct 13, 2018 5:38 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
alberinfo wrote:
thanks, but this actually didn't work for me.

How so? Elaborate please.


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sat Oct 13, 2018 5:49 pm 
Offline
Member
Member

Joined: Wed Aug 29, 2018 4:42 pm
Posts: 122
i didn't see anything to 'convert' BCD to INT, also the only two ways that i see that are:
Code:
(((hour & 0xF0) >> 4) < 10)

and:
Code:
((hour & 0xF0) >> 4) * 10 + (hour & 0x0F)

makes the same result as the image above


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sat Oct 13, 2018 6:03 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
Then, perhaps, the problem is not in conversion but in reading the values from the chip or your prgram being somehow broken (not read from disk correctly, not having correct values in e.g. segment registers).


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sun Oct 14, 2018 4:01 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
CMOS Please look at the wiki before posting.


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sun Oct 14, 2018 7:22 am 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
You can look at how I've implemented it: https://gitlab.com/sortix/sortix/blob/master/kernel/x86-family/cmos.cpp

That should be a readable & good example. It also avoids race conditions when the value is being updated.


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sun Oct 14, 2018 6:07 pm 
Offline
Member
Member

Joined: Wed Aug 29, 2018 4:42 pm
Posts: 122
thanks, but either the CMOS method or the method provided by sortie didnt work, still displaying the 'S' in the screen


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sun Oct 14, 2018 6:11 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
alberinfo wrote:
thanks, but either the CMOS method or the method provided by sortie didnt work, still displaying the 'S' in the screen


Can you test separately:
  • single character printing
  • string printing
  • conversion of integer to hex digits and hex chars ('0'-'9','A'-'F')
  • conversion of integer to decimal digits and chars ('0'-'9')
  • conversion from BCD to integer


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Sun Oct 14, 2018 11:49 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
Could you post your source, since your github is severely outdated.


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Mon Oct 15, 2018 8:15 am 
Offline
Member
Member

Joined: Wed Aug 29, 2018 4:42 pm
Posts: 122
i've updated it, but anyway, i don't know what or why fails


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Mon Oct 15, 2018 8:21 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
You've swapped around your outb functions, the correct syntax for you outb function is
Code:
void outb(word port, word value);
and you're using
Code:
void outb(word value, word port);
also you should really reorganise your project a good example for this is Meaty_Skeleton.
And because you have copied and pasted so much code by @pvc there are 2 outb functions outb and outportb, OSDev is more than just copying code from others it's about writing code yourself and creating your own OS.


Last edited by thomtl on Mon Oct 15, 2018 8:23 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Mon Oct 15, 2018 8:23 am 
Offline
Member
Member

Joined: Wed Aug 29, 2018 4:42 pm
Posts: 122
i see in the outportb function that is first the port and then the data as you say.


Top
 Profile  
 
 Post subject: Re: print correctly BCD CMOS RTC values
PostPosted: Mon Oct 15, 2018 8:23 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
Please read my edit


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 44 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 55 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