/* demo 12: detect the pulse_width of low_pulse */ /* (Use CH-3 to simulate external pulse) */ /* step 1 : CLK-3 select clock2=80K --> simulate ext signal */ /* step 2 : CLK-1 select clock1=8M --> generate BASE clock */ /* step 3 : CLK-2 select COUT1=1K --> measure pulse-width */ /* step 4 : J25 select CH3 */ /* step 5 : run demo12.exe */ /* ----------------------------------------------------------- */ #include "PCITMC12.H" #define A1_8259 0x20 #define A2_8259 0xA0 #define EOI 0x20 WORD pci_tmc12_select8254(char cChip); WORD pci_tmc12_c0(char cConfig, char cLow, char cHigh); WORD pci_tmc12_c1(char cConfig, char cLow, char cHigh); WORD pci_tmc12_c2(char cConfig, char cLow, char cHigh); WORD init_CH3(); WORD wBaseAddr,wIrq,wPLX; static void interrupt irq_service(); int COUNT3,WIDTH3,CNT_H,CNT_L,irqmask,now_int_state; int main() { int i,j; WORD wBoards,wRetVal,count; char c; DWORD dwVal; float low_pulse_width; clrscr(); wRetVal=PTMC12_DriverInit(&wBoards); printf("\n(1) Threr are %d PCI-TMC12 Cards in this PC",wBoards); if ( wBoards==0 ) { putch(0x07); putch(0x07); putch(0x07); printf("(1) There are no PCI-TMC12 card in this PC !!!\n"); exit(0); } printf("\n(2) Show the Configuration Space of all PCI-TMC12:"); for(i=0; i CH3 */ /* 80K*65536_count=0.8192 sec --> high_width=0.4096 sec */ /* --> high_width=0.4 sec, low_width=0.4 sec */ pci_tmc12_c0(0x36,0,32); /* CH-1,mode-3,low=0,high=32,cout=1K */ _outpd(wPLX+0x4c,0x41); /* channel_1, interrupt active_Low */ now_int_state=1; /* now int_signal is High */ 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 */ outportb(A1_8259+1,irqmask & (0xff ^ (1 << wIrq))); irqmask=inportb(A2_8259+1); outportb(A2_8259+1,irqmask & (0xff ^ (1 << (wIrq-8)))); setvect(wIrq-8+0x70, irq_service); } enable(); } void interrupt irq_service() { if (now_int_state==0) { COUNT3++; /* find a HIGH_pulse */ if (COUNT3==4) /* stop down-count & read-counter */ { outportb(wBaseAddr+0x0C,0x40); /* latch counter1 */ CNT_L=inportb(wBaseAddr+0x04); CNT_H=inportb(wBaseAddr+0x04); _outpd(wPLX+0x4c,0); /* disable all interrupt */ } _outpd(wPLX+0x4c,0x41); /* channel_1, interrupt active_Low */ now_int_state=1; /* now int_signal is High */ } else { COUNT3++; /* find a low_pulse */ if (COUNT3==3) /* start counter */ pci_tmc12_c1(0x70,0xff,0xff);/* CH-2,mode-0 down count ffff */ _outpd(wPLX+0x4c,0x43); /* channel_1, interrupt active_High*/ now_int_state=0; /* now int_signal is Low */ } if (wIrq>=8) outportb(A2_8259,0x20); outportb(A1_8259,0x20); } /* -------------------------------------------------------------------- */ WORD pci_tmc12_select8254(char cChip) { outportb(wBaseAddr+0x10,cChip); return(NoError); } WORD pci_tmc12_c0(char cConfig, char cLow, char cHigh) { outportb(wBaseAddr+0x0C,cConfig); outportb(wBaseAddr ,cLow); outportb(wBaseAddr ,cHigh); return(NoError); } WORD pci_tmc12_c1(char cConfig, char cLow, char cHigh) { outportb(wBaseAddr+0x0C,cConfig); outportb(wBaseAddr+4 ,cLow); outportb(wBaseAddr+4 ,cHigh); return(NoError); } WORD pci_tmc12_c2(char cConfig, char cLow, char cHigh) { outportb(wBaseAddr+0x0C,cConfig); outportb(wBaseAddr+8 ,cLow); outportb(wBaseAddr+8 ,cHigh); return(NoError); }