Page 1 of 1
system time
Posted: Wed Nov 06, 2002 1:03 am
by ncsu121978
how can i go about keeping track of the system time ?
I guess i need to get the value from cmos somehow every so often and store it in a variable....maybe ever timer tick i dont know.
what are your thoughts ? does anyone have some sample of how this is done ?
Re:system time
Posted: Wed Nov 06, 2002 12:20 pm
by Tim
Yep, that's the right idea. On every IRQ0, increment some global variable. You could synchronise it every so often with the RTC time of day value to account for clock drift.
Re:system time
Posted: Wed Nov 06, 2002 1:24 pm
by ncsu121978
i was thinking maybe just read the time once on startup
i have my timer running at 100 ticks per second so once it has fired 100 times i increment my second counter......would this be accurate enough so that i wouldnt have to get the time from cmos every time the timer fires. I guess i could maybe check the cmos once a minute or so to compare the results and modify my time if it is off.
Also.....what frequency do you guys run your timer at ? Like i said, mine is at 100 Hz and what do you do in thar isr.....right now i only keep track of time elapsed since computer was started. When you start doing multi-tasking then I guess the code to change tasks would go in there. I know there needs to be a limit on how much code you put into the timer so that it can finish executing it by the time the next interrupt fires....i guess it really depends on the speed of the machine.
But I would still like an example of how to actually get the time and date from cmos.........google has turned up nothing so far
Re:system time
Posted: Thu Nov 07, 2002 2:06 am
by Pype.Clicker
i have my clock at 1KHz, but most of the time, the handler do nothing but counting the ticks. The dispatcher (executive unit of the scheduler) for instance will wait 32 ticks before doing a switch in normal case, but it could do it earlier if some "urgent" thread has popped up ...
as machines now run about 1.000.000 instructions per millisecond, a few 200 cycles for an IRQ processing is only 0.02% of the CPU time -- which seems to be a very low overhead in my sense.
Re:system time
Posted: Thu Nov 07, 2002 6:38 am
by Tim
i was thinking maybe just read the time once on startup
You could do this, but if you do, you'll find that the system time will drift slowly. Not only is the IRQ0 timer is less accurate than the RTC, but you'll find that you can't get an exact frequency from it. For example, it's not possible to get a frequency of precisely 100Hz. Therefore you'll need to correct the clock periodically (every minute? every ten seconds?).
Re:system time
Posted: Thu Nov 07, 2002 6:58 am
by ncsu121978
i got my system time working just fine thanks guys......now my next step is writing a floppy drive device driver.......argh....
but that is in my other thread