RTC data format?
RTC data format?
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?
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:RTC data format?
Here you are
HtH
Code: Select all
static int bcd2bin(int val){
int data;
data=((int) ((((val & 0xF0) >> 4) * 10) + (val & 0x0F)));
return data;
}
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:RTC data format?
Since things are written in a strange format on this subject, Todah Rabah!
[edit]Spelling corrected by a kind Guest.[/edit]
[edit]Spelling corrected by a kind Guest.[/edit]
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:RTC data format?
"BCD" (binary coded decimal) is another legacy we carry from 8088 times 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.
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?
Must have missed the dot that makes a vet a bet when learning it that term. Darn.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:RTC data format?
<omg>
they're talking hebrew, now ... I suppose he'll say "Nes gadol haya sham" when a bug will be fixed !?
</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?
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.