/* DEMO4.C : Use EVTIRQ to count event */ /* step 1 : a.Clock source select 1MHz (JP1 P3,P4 short) */ /* b.Connect P4.3 to CLK3(P5.1) */ /* (use the 10KHz to emulate external event signal and*/ /* Counter3's counter value=10000.So when the event */ /* happen 10000 times(source from CLK3) the EVTIRQ */ /* will be trigger.) */ /* step 2 : run DEMO4.EXE */ /* -------------------------------------------------------------- */ #include "PIO.H" #define A1_8259 0x20 #define A2_8259 0xA0 #define EOI 0x20 WORD init_high(); WORD pio_d64_c3(char cConfig, char cLow, char cHigh); void interrupt *oldfunc; // (); static void interrupt irq_service(); WORD wBase,wIrq; int irqmask,now_int_state,new_int_state,invert,int_c,int_num; int CNT_L1,CNT_L2,CNT_L3,CNT_L4; int CNT_H1,CNT_H2,CNT_H3,CNT_H4; unsigned counter; int main() { int i,j,k1,k2,l1,l2,jj,dd,j1,i1,j2,i2; WORD wBoards,wRetVal,t1,t2,t3,t4,t5; WORD wSubVendor,wSubDevice,wSubAux,wSlotBus,wSlotDevice; long lOutPad1,lOutPad2,lInPad1,lInPad2; char c; float width; _clearscreen(0); /* step 1: find address-mapping of PIO/PISO cards */ wRetVal=PIO_DriverInit(&wBoards,0x80,0x01,0x20); /* for PIO-D64 */ printf("\nThrer are %d PIO_D64 Cards in this PC",wBoards); if (wBoards==0) exit(0); printf("\n--------------- The Configuration Space ---------------"); for(i=0; i "); ShowPioPiso(wSubVendor,wSubDevice,wSubAux); } /* select card_0 */ PIO_GetConfigAddressSpace(0,&wBase,&wIrq,&t1,&t2,&t3,&t4,&t5); /* step 2: enable all D/I/O port */ outp(wBase,1); /* enable D/I/O */ init_high(); printf("\n\n"); for(;;) { printf("\rEvent(10K/10000) happen times : %d ",CNT_L2); if (kbhit()!=0) break; } _disable(); outp(wBase+5,0); /* disable all interrupt */ if (wIrq<8) { _dos_setvect(wIrq+8,oldfunc); } else { _dos_setvect(wIrq-8+0x70,oldfunc); } PIO_DriverClose(); } /* -------------------------------------------------------------- */ WORD init_high() { DWORD dwVal; _disable(); outp(wBase+5,0); /* disable all interrupt */ if (wIrq<8) { oldfunc=_dos_getvect(wIrq+8); irqmask=inp(A1_8259+1); outp(A1_8259+1,irqmask & (0xff ^ (1 << wIrq))); _dos_setvect(wIrq+8, irq_service); } else { oldfunc=_dos_getvect(wIrq-8+0x70); irqmask=inp(A1_8259+1); outp(A1_8259+1,irqmask & 0xfb); /* IRQ2 */ irqmask=inp(A2_8259+1); outp(A2_8259+1,irqmask & (0xff ^ (1 << (wIrq-8)))); _dos_setvect(wIrq-8+0x70, irq_service); } pio_d64_c3(0x34,0x10,0x27); /* U5.COUNTER3,MODE-2 */ /* when the event happend 10000 times,the EVTIRQ will be trigger */ outp(wBase+0x2a,0); /* invert EVTIRQ */ /* depend on initial state */ int_num=0; CNT_L1=CNT_L2=CNT_L3=CNT_L4=0; /* Low_pulse counter */ CNT_H1=CNT_H2=CNT_H3=CNT_H4=0; /* High_pulse counter */ now_int_state=0x2; /* now EVTIRQ is high */ outp(wBase+5,0x2); /* enable EVTIRQ interrupt */ _enable(); } /* -------------------------------------------------------------- */ void interrupt irq_service() { int_num++; new_int_state=inp(wBase+7)&0x0f; int_c=new_int_state^now_int_state; if ((int_c&0x1)!=0) /* now INT_CHAN_0 change to high */ { if ((new_int_state&0x01)!=0) { CNT_H1++; } else /* now INT_CHAN_0 change to low */ { CNT_L1++; } invert=invert^1; /* generate a high pulse */ } if ((int_c&0x2)!=0) /* now INT_CHAN_1 change to high */ { if ((new_int_state&0x02)!=0) { CNT_H2++; } else /* now INT_CHAN_1 change to low */ { CNT_L2++; } invert=invert^2; /* generate a high pulse */ } if ((int_c&0x4)!=0) /* now INT_CHAN_2 change to high */ { if ((new_int_state&0x04)!=0) { CNT_H3++; } else /* now INT_CHAN_2 change to low */ { CNT_L3++; } invert=invert^4; /* generate a high pulse */ } if ((int_c&0x8)!=0) /* now INT_CHAN_3 change to high */ { if ((new_int_state&0x08)!=0) { CNT_H4++; } else /* now INT_CHAN_3 change to low */ { CNT_L4++; } invert=invert^8; /* generate a high pulse */ } now_int_state=new_int_state; outp(wBase+0x2a,invert); if (wIrq>=8) outp(A2_8259,0x20); outp(A1_8259,0x20); } /* -------------------------------------------------------------- */ void pio_d64_CN1_do(long lDoValue) { outp(wBase+0xc0,(lDoValue&0xff)); outp(wBase+0xc4,((lDoValue>>8)&0xff)); } /* -------------------------------------------------------------- */ void pio_d64_CN3_do(long lDoValue) { outp(wBase+0xc8,(lDoValue&0xff)); outp(wBase+0xcc,((lDoValue>>8)&0xff)); } /* -------------------------------------------------------------- */ long pio_d64_CN2_di(void) { long lDiValue; lDiValue=(inp(wBase+0xc4)<<8); lDiValue=(lDiValue|(inp(wBase+0xc0)))&0xffff; return(lDiValue); } /* -------------------------------------------------------------- */ long pio_d64_CN4_di(void) { long lDiValue; lDiValue=(inp(wBase+0xcc)<<8); lDiValue=(lDiValue|(inp(wBase+0xc8))&0xffff); return(lDiValue); } /* -------------------------------------------------------------- */ WORD pio_d64_c3(char cConfig, char cLow, char cHigh) { outp(wBase+0xec,cConfig); outp(wBase+0xe0,cLow); outp(wBase+0xe0,cHigh); return(NoError); }