Hi,
I have been working on some basic low level communication through the number 1 port of a UART through C and now we have been asked to include interrupts instead of polling. With polling i had no problems using either in/outportb or int86. But now that we have to use the 8259 PIC something goes wrong. I use the go32 and dpmi functions in order to replace the ISR in the vector that is associated with the 0Ch interrupt (which corresponds to the serial port 1 interrupt) but it seems that even though i have unmasked and enabled all the required bits, when i send a character the UART does not send an interrupt or the PIC does not recognize it. Some help would be appreciated!
#include <stdio.h>
#include <pc.h>
#include <dos.h>
#include <dpmi.h>
#include <go32.h>
#include "com.h"
#define PORTINT 0x0C
_go32_dpmi_seginfo OldISR, NewISR; //Structs
char ch;
void Port_Routine(void)
{
ch=inportb(0x3F8);
printf("Received: %c\n",ch);
}
void chip_init(void){
com_init(COM1,0xEF); //Initializes the UART baud rate parity etc.
outportb(COM1+1,0x0F); //Initializes the UART interrupt registers
outportb(0x21,inportb(0x21)&0xEF); //We and out the bit of IRQ4 in order
//to enable the interrupt mask register
}
void handler_set(void){
//point NewISR to the proper selector:offset for handler
//function
NewISR.pm_offset = (int)Port_Routine;
NewISR.pm_selector = _go32_my_cs();
//load the address of the old timer ISR into the OldISR structure
_go32_dpmi_get_protected_mode_interrupt_vector(PORTINT, &OldISR);
_go32_dpmi_allocate_iret_wrapper(&NewISR);
_go32_dpmi_set_protected_mode_interrupt_vector(PORTINT, &NewISR);
puts("New ISR set");
}
void handler_reset(void)
{
_go32_dpmi_free_iret_wrapper(&NewISR);
_go32_dpmi_set_protected_mode_interrupt_vector(PORTINT, &OldISR);
}
int main(void)
{
//Initializing COM port
chip_init();
printf("About to set the new ISR onto the old timer ISR..\n");
getkey();
handler_set();
while(!kbhit());
handler_reset();
printf("Removing new ISR from the timer ISR chain\n");
return 0;
}