RTC data format?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Crazed123

RTC data format?

Post by Crazed123 »

I want to use the RTC to provide periodic interrupts and an initial time setting (I think I'll leave it to userspace to interpret that as UTC or wall time, since the clock itself doesn't know), but don't know about BCD. This is apparently the data format that the RTC uses by default (and somehow I don't think dual-boot systems would like me if I forced it into hex mode), so how does one transform the values returned from the RTC register into numbers usable for performing time calculations?
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:RTC data format?

Post by distantvoices »

Here you are :-)

Code: Select all

static int bcd2bin(int val){
  int data;
  data=((int) ((((val & 0xF0) >> 4) * 10) + (val & 0x0F)));
  return data;
}
HtH
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Crazed123

Re:RTC data format?

Post by Crazed123 »

Since things are written in a strange format on this subject, Todah Rabah!

[edit]Spelling corrected by a kind Guest.[/edit]
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:RTC data format?

Post by Pype.Clicker »

"BCD" (binary coded decimal) is another legacy we carry from 8088 times :P What it actually means is that each digit (as in, base 10 digits) actually takes 4 full bits. 1234 will thus be encoded as 0x1234 using BCD, and (still using BCD) 0x1239 + 1 = 0x1240 ...

So:
- you can use hex-printing routines to display BCD numbers.
- you can use AAD AAM AAS opcodes and the like to operate directly on BCD numbers.
- you can also encode/decode them and work only with "regular" numbers.
[x-=09]

Re:RTC data format?

Post by [x-=09] »

You probably mean Toda Rabah, Eliahu.
Crazed123

Re:RTC data format?

Post by Crazed123 »

Must have missed the dot that makes a vet a bet when learning it that term. Darn.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:RTC data format?

Post by Pype.Clicker »

<omg>
they're talking hebrew, now ... I suppose he'll say "Nes gadol haya sham" when a bug will be fixed !?
</omg>
Crazed123

Re:RTC data format?

Post by Crazed123 »

Nope. It's a "funny data format". I'm not so religious as to call a bugfix I or someone else made with their own hands a miracle.
Post Reply