flat assembler
Message board for the users of flat assembler.

Index > Main > clock interrupt?

Author
Thread Post new topic Reply to topic
asmrox



Joined: 19 Jan 2008
Posts: 160
asmrox 25 Feb 2008, 12:10
i was reading an aritcle about interrupts and i found 'clock interrupt'. wasnt documented, and i cant find anything about it.

Would it be possible to use this int instead of lame sleep()?
Post 25 Feb 2008, 12:10
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 25 Feb 2008, 22:26
as irq are just signals, you shall seek into the sheet about rtc.
helppc contain an overview

there are 3 irq possible on rtc

the update terminate, the periodic and the alarm
alarm normally launch int 4Ah
and periodic one will be made each second, at 1Hz frequency...
to know what is the current active signal there are flags in a status registers.
the update terminated is not reallly needed as it is used to update system
the periodic one can replace it.
Post 25 Feb 2008, 22:26
View user's profile Send private message Visit poster's website Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86 25 Feb 2008, 23:09
The timer interrupt is IRQ 0, int 8h, it is generated by RTC channel 0 by default 18.2 times per second. Intercept int 8h or int 1Ch (the BIOS int 8h handler calls int 1Ch) to get timer interrupts. To change the configuration or frequency of the timer, use ports 40h/43h.
Post 25 Feb 2008, 23:09
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 25 Feb 2008, 23:36
no, the timer is not the RTC
don't confuse them
timer is IRQ 0 int 8
rtc is irq 8, int 70h

the timer is set to 18,2 HZ cause of the counter value of the chanel assigned to IRQ0
the rtc is not dependant to the platform, it is possible to have RTC on various PCB, as a time reference.
the old RTC chip, as found on old 286, 386 boards needs a battery to save the values of SRAM (CMOS) and continue to count the time without power supply.
the timer is just a timer, started at boot and stopped at power off


the routine to handle the timer is not the same as the one for the RTC.
RTC is originally a DALLAS(r) component available for general purpose timing assisted by µP
Post 25 Feb 2008, 23:36
View user's profile Send private message Visit poster's website Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86 26 Feb 2008, 02:39
Sorry, you are right, edfed. The timer interrupt is generated by the PIT (channel 0), that's the 18.2 per second timer, use ports 40h-43h for that. The RTC generates the clock interrupt, and it always keeps time, even when the PC is off.
Post 26 Feb 2008, 02:39
View user's profile Send private message Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth 26 Feb 2008, 08:04
edfed wrote:

and periodic one will be made each second, at 1Hz frequency...


IIRC the default value for the RTC frequency is 1024 Hz, not just 1 Hz.
Post 26 Feb 2008, 08:04
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 26 Feb 2008, 11:18
happy to know that.
1024Hz is better than the 1Hz value.
i would prefer to have a 1000 Hz frequency... is it possible?

how to change the period? there is probably a register to program...

port 70h, 71h
Post 26 Feb 2008, 11:18
View user's profile Send private message Visit poster's website Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86 26 Feb 2008, 21:21
It's possible to configure the PIT to 1000 Hz, just take a sound function and get it to program channel 0 instead of channel 2. If you must change the RTC interrupt frequency (not PIT), then you can use status register A of CMOS/RTC (write 0Ah to port 70h to access it at port 71h), but it doesn't seem to support exactly 1000 Hz, it only supports none, 122 microseconds, 500 milliseconds, and 976.562 microseconds (the default, or 1024 Hz).
Post 26 Feb 2008, 21:21
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 26 Feb 2008, 22:19
then i'll use the 500 millisecond one.
it's better for time precision to use rtc than pit.
rtc is stable, very old PC, never used since some years have the time still valid.. effective (not typical) time shift is like 1 or 2 minutes after 2 or 3 years for a 386 pc i have

pit used in conjunction to rtc will expand the possibilities.
the rtc used as feedback to adjust the pit counters...
Post 26 Feb 2008, 22:19
View user's profile Send private message Visit poster's website Reply with quote
daniel.lewis



Joined: 28 Jan 2008
Posts: 92
daniel.lewis 26 Feb 2008, 23:28
Razz You guys might be programming for a 286 or 386 platform...

On modern systems, the LAPIC, ACPI-PM and HPET provide a plethora of clock interfaces that are apparently more accurate and manageable than the PIT. I've been told each has advantages - the LAPIC timer and HPET are excellent for sleep and interval timing, ACPI-PM has excellent precision. It's also preferable to use the more modern forms because they're more efficient to use because they don't need error correction code, and simply avoid the RTC, PIT and PIC altogether.

I had thought that the PIC was one of the things the x86-64 long mode didn't support, but I just googled it and I was wrong. It's more or less considered obsolete though.

_________________
dd 0x90909090 ; problem solved.


Last edited by daniel.lewis on 26 Feb 2008, 23:38; edited 1 time in total
Post 26 Feb 2008, 23:28
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 26 Feb 2008, 23:36
386 modules are available for embeded applications.
for these modules there are all the minimal PC platform.

APIC is the PIC
it is the same I/O port, the same functionality.
Post 26 Feb 2008, 23:36
View user's profile Send private message Visit poster's website Reply with quote
daniel.lewis



Joined: 28 Jan 2008
Posts: 92
daniel.lewis 26 Feb 2008, 23:46
For reference, the PIT is the 8253 chip, with the 8254 PIT always being dedicated to memory refreshing and otherwise useless. The 8259 chip is the PIC chip.

http://lists.ntp.isc.org/pipermail/questions/2007-September/015360.html
http://lists.freebsd.org/pipermail/freebsd-current/2005-February/046898.html
http://www.cs.rice.edu/CS/Systems/Soft-timers/code/README.html
http://en.wikipedia.org/wiki/Intel_8253

APIC is not the PIC. It's not even an upgrade, it's an entirely different system.

http://en.wikipedia.org/wiki/Local_APIC

"In systems containing an 8259 PIC, the 8259 may physically be connected to the LAPIC in the system's bootstrap processor (BSP), or to one of the system's I/O APICs, or both. Logically, however, the 8259 is only connected once at any given time."
Post 26 Feb 2008, 23:46
View user's profile Send private message Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86 27 Feb 2008, 00:10
The RTC and PIT are supported on all systems (old and new), have a very standard, simple, and old interface, are supported under DOS, and have BIOS support. Use them unless you need the features of HPET/APIC/other stuff.
Post 27 Feb 2008, 00:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20306
Location: In your JS exploiting you and your system
revolution 27 Feb 2008, 00:15
My old 8088 system don't have an RTC, nor does the original IBM PC. It became standard, IIRC, with the IBM AT (80286) systems.
Post 27 Feb 2008, 00:15
View user's profile Send private message Visit poster's website Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86 27 Feb 2008, 00:20
True, the PIT and PIC though were supported since the IBM PC. Some IBM PC's had "clock cards" that have an RTC, but not all had that. I was talking about PC AT+ systems in the post (I should have been more clear), and since those the PIC/PIT/RTC/keyboard controller/CMOS/lots of other things have been standard.
Post 27 Feb 2008, 00:20
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue 27 Feb 2008, 20:52
Well, you can't use the timer interrupt instead of "lame" sleep(), because they are different things. If you program under unix/linux/windows/beos/osx/... you can't access interrupts. You can only access interrupts if you write a driver or program on the bare metal, in which case there won't be a sleep() available.
Post 27 Feb 2008, 20:52
View user's profile Send private message Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86 27 Feb 2008, 21:18
Quote:

ou can only access interrupts if you write a driver or program on the bare metal


Or if you are under DOS.
Post 27 Feb 2008, 21:18
View user's profile Send private message Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86 27 Feb 2008, 21:20
Quote:

Well, you can't use the timer interrupt instead of "lame" sleep(), because they are different things.


No, intercept the timer interrupt, increment a variable every time it is called, and when the variable reaches a certain count (meaning a certain amount of time elapsed) then do something.
Post 27 Feb 2008, 21:20
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 27 Feb 2008, 23:11
sleep( ) is not asm.
pit can be used as a watch dog.
but watchdog is used for what?
simply to know if the system is blocked.
if the watchdog is an irq, then to avoid this irq, the system must set it's counter periodically.
if the counter is not reset, it will cross zero, and then launch the isr.
Post 27 Feb 2008, 23:11
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.