Click to See Complete Forum and Search --> : timer interrupt
Ianwalsh
May 7th, 2003, 10:15 AM
i'm trying to use a timer interrupt to perform a task at a fixed period, i'm having some trouble setting the vector:
#include <stdio.h>
#include <dos.h>
#ifdef __cplusplus
#define __CPPARGGS ....
#else
#define __CPPARGS
#endif
void setup_int(void);
void interrupt isr1(__CPPARGS);
void restore(void);
void interrupt (far *old_int8_vect)(__CPPARGS);
int x = 0;
int interrupt_flag = 0;
void main() {
unsigned int i;
outportb(0x43, 0x36);
printf("square wave set");
setup_int();
for(i=0; i <= 32000; i++) {
if(interrupt_flag == 1) {
printf("INTERRUPT!");
interrupt_flag = 0;
x = 0;
} else {
printf("line: %d \n", x);
x++;
}
}
restore();
}
void setup_int(void) {
disable();
old_int8_vect = getvect(8);
setvect(8, isr1);
printf("interrupt setup");
enable();
}
void interrupt isr1(__CPPARGS) {
disable();
interrupt_flag = 1;
old_int8_vect();
enable();
}
void restore(void) {
disable();
setvect(8, old_int8_vect);
enable();
}
any comments, what's wrong with this code? eventually it's going to be used in a control system application so restoring the isr isn't really required, and messing with the clock isn't going to cause a problem.
thanks a lot
-ian
PaulWendt
May 7th, 2003, 10:27 AM
What platform are you running this on? A lot of the old-style
interrupt code won't work with windows. I didn't even look at
the code, thinking this might be the case.
Ianwalsh
May 7th, 2003, 10:46 AM
is dos 6.2.2
cvogt61457
May 7th, 2003, 11:02 AM
What is the problem that you are seeing?
Are you getting a compile or link error?
Are you getting a runtime error? What is the error? Which line?
Is the ISR getting called?
Ianwalsh
May 7th, 2003, 11:58 AM
sorry, that was dumb on my part.
code compiles ok, but just prints some gibberesh to the screen then crashes, honestly i'm not sure if the isr is being called or not (is there an easy way to know?)
what i thought would happen is numbers would get displayed, counting up, until the interrupt fired when it would say "interrupt" and start over.
thanks for your help!
Paul McKenzie
May 7th, 2003, 12:32 PM
Originally posted by Ianwalsh
sorry, that was dumb on my part.
code compiles ok, but just prints some gibberesh to the screen then crashes, honestly i'm not sure if the isr is being called or not (is there an easy way to know?)
what i thought would happen is numbers would get displayed, counting up, until the interrupt fired when it would say "interrupt" and start over.
thanks for your help! Isn't it dangerous to call printf() during an interrupt? From what I remember, you shouldn't make any calls to 'C' library functions that may do any I/O.
I have some very old timer interrupt code, and I distinctly remember that there are functions you shouldn't call during an interrupt (there is an "InDos" flag, if I recall, that if it is ON, you can't make certain function calls).
If you can get a copy, get the book "PC Intern" by Michael Tischer. Here is a link:
http://www.abacuspub.com/catalog/b304.htm
If you are trying to write your own timer interrupt, and you don't have previous source code to learn from, you more than likely won't get too far.
Regards,
Paul McKenzie
cvogt61457
May 7th, 2003, 12:57 PM
Paul is correct about the printf inside the interrupt handler.
However, your printf is in the setup_int() not the ISR.
Do you know which printf is barfing?
What is the output that you've seen?
Does the setvect() work?
Are you seeing the "INTERRUPT" ever?
Do you see the "interrupt setup"?
Do you see the counter counting any?
Unfortunately, I don't have a DOS setup to work with. I'll have to
rely on what you are seeing.
rxbagain
May 7th, 2003, 08:08 PM
I tried your code and it gives my interrupt a "Stack overflow" error. What I did is I deleted the far in the old interrupt declaration
void interrupt (*old_int8_vect)(__CPPARGS);
And there is no error anymore.
Hope it will work for you
Ianwalsh
May 8th, 2003, 07:54 AM
thanks for your help, i'm looking into getting a copy of that book.
when i run the program i see the interrupt setup, and the counter, but never the "INTERRUPT!"
seems like this should be somthing obvious...
thanks again
-ian
rxbagain
May 8th, 2003, 09:24 AM
Sorry, I tested my code in win98. I made it show the "INTERRUPT!" in win98, but when I tested what you mentioned in DOS, I cannot see it anymore.
I tried to change the interrupt number to 9 (keyboard interrupt) just to make sure if the problem is in the code. While the program is running, I'm pressing the keyboard and I can see, the "INTERRUPT!" string.
With what I've done, I concluded that there is no problem with the code anymore. The problem now is that the interrupt 8 is not being called by the DOS system anymore. Maybe they changed the interrupt # (or any other reason).
Try to look at some new books on DOS about interrupt #s.
Ianwalsh
May 8th, 2003, 09:45 AM
Beauty! that worked, at least i can see the keyboard interrupt.
thanks a lot.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.