real-time clock driver
real-time clock driver
Can someone point me to documentation on writing read, write, and open functions for the x86 real-time clock? I've been searching but I haven't come up with anything yet. I searched the wiki here and couldn't find anything there either. Thanks
Dan
Dan
the PIT?
if that is what you are referring to, look harder through the wiki, and read Bran's tutorial at osdever.net
if that is what you are referring to, look harder through the wiki, and read Bran's tutorial at osdever.net
Website: https://joscor.com
I've never heard of the PIT and if its related to the RTC its beyond the scope of what I need to accomplish (I looked at the Wiki page regarding the PIT and its not what I need). Essentially I have a linux RTC driver and I need to communicate with it, i.e. read the current time, set the current time, change the clock frequency, etc.01000101 wrote:the PIT?
if that is what you are referring to, look harder through the wiki, and read Bran's tutorial at osdever.net
are you talking about the CMOS clock?
It is quite easy to get the time from this (finds code)
It is quite easy to get the time from this (finds code)
Code: Select all
#define BCD2BIN(bcd) ((((bcd)&15) + ((bcd)>>4)*10))
unsigned char readCMOS(unsigned char addr)
{
unsigned char ret;
outb(0x70,addr);
__asm__ __volatile__ ("jmp 1f; 1: jmp 1f;1:");
ret = inb(0x71);
__asm__ __volatile__ ("jmp 1f; 1: jmp 1f;1:");
return ret;
}
void writeCMOS(unsigned char addr, unsigned int value)
{
outb(0x70, addr);
__asm__ __volatile__ ("jmp 1f; 1: jmp 1f;1:");
outb(0x71, value);
__asm__ __volatile__ ("jmp 1f; 1: jmp 1f;1:");
}
//Gets CMOS actual time
datetime_t getDatetime()
{
datetime_t now;
cli();
now.sec = BCD2BIN(readCMOS(0x0));
now.min = BCD2BIN(readCMOS(0x2));
now.hour = BCD2BIN(readCMOS(0x4));
now.day = BCD2BIN(readCMOS(0x7));
now.month = BCD2BIN(readCMOS(0x8));
now.year = BCD2BIN(readCMOS(0x9));
sti();
return now;
}
the PIT is the Programmable Interrupt Timer (CMOS Timer), which is explained in the above post.
Website: https://joscor.com
I think you guys are still thinking more in depth than I need. I need to write a device driver that communicates with the existing linux rtc driver. It was my impression that the RTC driver interacts with the cmos and then the kernel interacts with the RTC driver. I'm guessing I'm not asking/approaching this correctly since I thought these were extremely generic/common functions. That also might also explain why I'm having trouble finding any information about them.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
The CMOS clock is the RTC (= Real Time Clock). The PIT is a different timer.
Anyway, it took me 2 seconds to find documentation on it. Actually, its the first hit on google
Anyway, it took me 2 seconds to find documentation on it. Actually, its the first hit on google
I never did that keyword search. That helps a bunch, thanksCombuster wrote:The CMOS clock is the RTC (= Real Time Clock). The PIT is a different timer.
Anyway, it took me 2 seconds to find documentation on it. Actually, its the first hit on google
lol I just read through that link and came up with a small function that returns the ext memory, x87 fpu existance, time, and date. =)
Website: https://joscor.com
That is not correct, the PIT and RTC are 2 seperate clocks, that run at 2 different frequencies, and trigger 2 different IRQ's and are used for 2 different things. In my OS, I use the PIT to deliver interrupts with varying time slices for multitasking, and the RTC to keep track of the system time (which is used for my delay/timeout functions). Please be careful about trhrowing information about that is not correct, it tends to confuse people even more than they already are. Acronym's are a killer nowadays, PIC, PIT, RTC, etc, and they can have more than 1 meaning, like a search on google for PIC will return plenty of information on pic microcontrollers and compilers, not so much on the programmable interrupt controller. I found more information searching google by using cmos clock than I did real time clock. Anyways, plenty of good info, and if the CPU supports the RTC, I recommend using it, the #'s tend to be easier to work with anyways (like, you can set it to 1024 hz, which is much easier to count seconds with than a fractional number you will get with the PIT). And, it can be set to interrupt at different times and/or on alarms (you can check the register to see if it was an alarm or normal interrupt for example, so you can use both at once). So, if you want to wakeup/execute a virus protection program at 3am saturday morning, you can program the RTC with the time/program and when the interrupt handler finds it, it will execute. You can store a list/queue, sorted by time (obviously), and trigger as many alarms as you want. You can set the frequency different than 1024, but that's what I use, give's me a little better than 1ms accuracy in my clock (although, i may change this later due to the # of interrupts being generated, may change my timing function later on (possibly to use RDTSC (read time stamp counter).01000101 wrote:the PIT is the Programmable Interrupt Timer (CMOS Timer), which is explained in the above post.
that was an extremely lengthy post telling me something that was already said above. =)
I know that they are seperate timers now, and I said about that I already read through that paper.
I know that they are seperate timers now, and I said about that I already read through that paper.
Website: https://joscor.com
Yes, I realize, but that entire post wasn't just for you, I wanted to explain a bit how the timers are utilized. Sure data sheets can tell you things like how to program them, but when it comes to actually using some of the functionality, some may not be to clear on it.01000101 wrote:that was an extremely lengthy post telling me something that was already said above. =)
I know that they are seperate timers now, and I said about that I already read through that paper.