Timer problems #5723
Unanswered
johnjspeth
asked this question in
Q&A
Timer problems
#5723
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I wonder if I have a 8253 hardware abstraction problem. I have resurrected an old program that programs the 8253 PIT. I'm trying to change it from running the default 55 msec to a custom 5 msec. The time tested wisdom always says to write 0x36 to the MODE register (IO port 0x43) and then the 16 bit timer value: LSB immediately followed by the MSB to the 8 bit counter register (IO port 0x40). It worked on real non-abstracted hardware long ago (hardware that I no longer have). The failing case hangs dosbox-x which requires me to close the dosbox-x window and then restart it.
Here's my code:
#define TIMER_VALUE 5966 // Timer countdown value for 5 msec assuming clock = 1.193 MHz
outp(0x43,0x36);
outp(0x40,TIMER_VALUE & 0xFF);
outp(0x40,TIMER_VALUE >> 8);
Interrupts are disabled prior to code execution. Interrupts are enabled after execution.
Using TIMER_VALUE = 0 tells the 8253 to interrupt at the slowest rate (55 msec default for DOS). That also fails. I'm concluding that writing anything to these registers causes problems.
Are there any known strategies or configuration options that might address my timer abstraction problems?
UPDATE: By the process of elimination/reduction, removing the MODE register configuration instruction will make the problem go away. Specifically, if I comment out "outp(0x43,0x36)" then I have no timer problem. The code works without the MODE control instruction for the various timer intervals I've tested (1, 5, and 55 msec).
UPDATE 2: Diving into source code, I discovered a comment that seems to be related. See timer.cpp in the hardware directory in the comment above write_latch(). A couple of possible workarounds are described but I'm not sure how to implement them. It appears many are confused about how to abstract the 8253.
UPDATE 3: Continuing with troubleshooting experiments, I can go no further after learning that using MODE=3 will make it hang. MODE=2 will work so the workaround is "outp(0x43,0x34)" whereas "outp(0x43,0x36)" will make it hang.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions