Page 1 of 1

RTC data format?

Posted: Sun Oct 30, 2005 10:45 pm
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?

Re:RTC data format?

Posted: Mon Oct 31, 2005 12:35 am
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

Re:RTC data format?

Posted: Mon Oct 31, 2005 12:51 am
by Crazed123
Since things are written in a strange format on this subject, Todah Rabah!

[edit]Spelling corrected by a kind Guest.[/edit]

Re:RTC data format?

Posted: Mon Oct 31, 2005 3:22 am
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.

Re:RTC data format?

Posted: Mon Oct 31, 2005 2:59 pm
by [x-=09]
You probably mean Toda Rabah, Eliahu.

Re:RTC data format?

Posted: Mon Oct 31, 2005 7:32 pm
by Crazed123
Must have missed the dot that makes a vet a bet when learning it that term. Darn.

Re:RTC data format?

Posted: Tue Nov 01, 2005 6:01 am
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>

Re:RTC data format?

Posted: Tue Nov 01, 2005 7:21 am
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.