/* DEMO4 : INT_CHAN_1, timer interrupt demo (initial low) */ /* (It is designed to be a machine independent timer) */ /* step1 : Run DEMO4.EXE */ /* -------------------------------------------------------------- */ #include "PIO.H" #define A1_8259 0x20 #define A2_8259 0xA0 #define EOI 0x20 static void interrupt irq_service(); void pio_da16_c0(char cConfig, char cLow, char cHigh); void pio_da16_c1(char cConfig, char cLow, char cHigh); void pio_da16_c2(char cConfig, char cLow, char cHigh); void init_int1_low(); WORD wBase,wIrq; int COUNT_L,COUNT_H,irqmask,now_int_state; int main() { int i,j; WORD wBoards,wRetVal,t1,t2,t3,t4,t5,t6; WORD wSubVendor,wSubDevice,wSubAux,wSlotBus,wSlotDevice; clrscr(); /* step1 : find address-mapping of PIO/PISO cards */ wRetVal=PIO_DriverInit(&wBoards,0x80,0x04,0x00);/*for PIO-DA16/8/4*/ printf("\n(1) Threr are %d PIO-DA16/8/4 Cards in this PC",wBoards); if ( wBoards==0 ) exit(0); printf("\n\n-------------- The Configuration Space --------------"); for(i=0;i "); ShowPioPiso(wSubVendor,wSubDevice,wSubAux); } PIO_GetConfigAddressSpace(0,&wBase,&wIrq,&t1,&t2,&t3,&t4,&t5); /* select card_0 */ /* step2 : enable all D/I/O port */ outportb(wBase,1); /* /RESET -> 1 */ printf("\n\n(2) DEMO4 Interrupt (1Hz) test"); init_int1_low(); /* interrupt initialize, INT1 is low now */ COUNT_L=0;COUNT_H=0; printf("\n\n*** Show the count of High_pulse ***\n"); for (;;) { gotoxy(1,10); printf("\nINT count = %d",COUNT_H); if (kbhit()!=0) break; } outportb(wBase+5,0); /* disable all interrupt */ PIO_DriverClose(); } /* Use INT_CHAN_1 as internal interrupt signal */ void init_int1_low() { DWORD dwVal; disable(); outportb(wBase+5,0); /* disable all interrupt */ if (wIrq<8) { irqmask=inportb(A1_8259+1); outportb(A1_8259+1,irqmask & (0xff ^ (1 << wIrq))); setvect(wIrq+8, irq_service); } else { irqmask=inportb(A1_8259+1); outportb(A1_8259+1,irqmask & 0xfb); /* IRQ2 */ irqmask=inportb(A2_8259+1); outportb(A2_8259+1,irqmask & (0xff ^ (1 << (wIrq-8)))); setvect(wIrq-8+0x70, irq_service); } /* CLK source = 4 MHz */ pio_da16_c1(0x76,0x90,0x01); /* COUNTER1, mode3, div 400 */ pio_da16_c2(0xb6,0x10,0x27); /* COUNTER2, mode3, div 10000 */ /* program Cout2 1Hz squr */ /* note : the 8254 need extra 2-clock for initialization */ for (;;) { if ((inportb(wBase+7)&2)==0) break; /* wait Cout2 = low */ } /* note : Cout2 = low, INV1 must select the non-inverted Cout2 */ /* --> INT_CHAN_1 = Cout2 = init_low, active_high */ outportb(wBase+0x2a,2); /* INV1 = 1, non-inverted Cout2*/ now_int_state=0; /* now Cout2 is low */ outportb(wBase+5,2); /* EN1 = 1, enable INT_CHAN_1 */ /* as interrupt source */ enable(); } /* -------------------------------------------------------------- */ void interrupt irq_service() { if (now_int_state==1) /* now INT1(Cout2) changed to low */ { /* --> INT_CHAN_1=!INT1=high now */ COUNT_L++; /* find a low pulse (INT1) */ if((inportb(wBase+7)&2)==0) /* INT1 is still fixed in low -> */ { /* need to generate a high pulse */ outportb(wBase+0x2a,2); /* INV1 select non-inverted input */ /* INT_CHAN_1=INT1=low --> */ /* INT_CHAN_1 generate high pulse */ now_int_state=0; /* now INT1=low */ } else now_int_state=1; /* now INT1=high */ /* don't have to gen. high pulse */ } else /* now INT1(Cout2) changed to high */ { /* --> INT_CHAN_1=INT1=high now */ COUNT_H++; /* find a low pulse (INT1) */ if((inportb(wBase+7)&2)==2) /* INT1 is still fixed in high -> */ { /* need to generate a high pulse */ outportb(wBase+0x2a,0); /* INV1 select inverted input */ /* INT_CHAN_1=!INT1=low --> */ /* INT_CHAN_1 generate high_pulse */ now_int_state=1; /* now INT1=high */ } else now_int_state=0; /* now INT1=low */ /* don't have to gen. high pulse */ } if (wIrq>=8) outportb(A2_8259,0x20); outportb(A1_8259,0x20); } /* -------------------------------------------------------------- */ void pio_da16_c0(char cConfig, char cLow, char cHigh) /* COUNTER0 */ { outportb(wBase+0xcc,cConfig); outportb(wBase+0xc0,cLow); outportb(wBase+0xc0,cHigh); } void pio_da16_c1(char cConfig, char cLow, char cHigh) /* COUNTER1 */ { outportb(wBase+0xcc,cConfig); outportb(wBase+0xc4,cLow); outportb(wBase+0xc4,cHigh); } void pio_da16_c2(char cConfig, char cLow, char cHigh) /* COUNTER2 */ { outportb(wBase+0xcc,cConfig); outportb(wBase+0xc8,cLow); outportb(wBase+0xc8,cHigh); }