/* DEMO5.C : Use TMRIRQ to generate 0.5Hz squa. */ /* step 1 : run DEMO5.EXE */ /* Note : Counter4 base on 4MHz clock source and Counter4.out */ /* cascade to Counter5.clk. */ /* -------------------------------------------------------------- */ #include "PIO.H" #define A1_8259 0x20 #define A2_8259 0xA0 #define EOI 0x20 WORD init_high(); WORD pio_d64_c4(char cConfig, char cLow, char cHigh); WORD pio_d64_c5(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("\rDO[0] state = %x",CNT_L3&1); 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_c4(0x76,0xe8,0x3); /* U5.COUNTER4,MODE-3,1/1000*/ pio_d64_c5(0xb6,0xa0,0xf); /* U5.COUNTER5,MODE-3,1/4000*/ for (;;) { if ((inp(wBase+7)&4)==4) break; /* wait TMRIRQ=HIGH */ } outp(wBase+0x2a,0xb); /* invert TMRIRQ */ /* 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=0x4; /* now TMRIRQ is high */ outp(wBase+5,0x4); /* enable TMRIRQ 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++; outp(wBase+0xc0,CNT_L3&1); } 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_c4(char cConfig, char cLow, char cHigh) { outp(wBase+0xec,cConfig); outp(wBase+0xe4,cLow); outp(wBase+0xe4,cHigh); return(NoError); } /* -------------------------------------------------------------- */ WORD pio_d64_c5(char cConfig, char cLow, char cHigh) { outp(wBase+0xec,cConfig); outp(wBase+0xe8,cLow); outp(wBase+0xe8,cHigh); return(NoError); }