/* demo 5 : INT_CHAN_2, 16-bit event counter (no interrupt) */ /* step 1 : apply a init_HIGH & active_LOW signal to PC0 of port-2 */ /* step 2 : run demo5.exe */ /* --------------------------------------------------------------- */ #include "PIO.H" #define A1_8259 0x20 #define A2_8259 0xA0 #define EOI 0x20 WORD init_high(); WORD wBase,wIrq; WORD pio_d48_c0(char cConfig, char cLow, char cHigh); WORD pio_d48_c1(char cConfig, char cLow, char cHigh); WORD pio_d48_c2(char cConfig, char cLow, char cHigh); int main() { int i,j; WORD wBoards,wRetVal; WORD wSubVendor,wSubDevice,wSubAux,wSlotBus,wSlotDevice,t1,t2,t3,t4,t5; char c; DWORD dwVal; unsigned int high,low,count; /* step 1: find address-mapping of PIO/PISO cards */ clrscr(); wRetVal=PIO_DriverInit(&wBoards,0x80,0x01,0x30); /* for PIO-D48 */ printf("\nThrer are %d PIO_D48 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 */ outportb(wBase,1); /* enable D/I/O */ /* step 3: select PC0 of port2 as init_HIGH & active_LOW sinal */ outportb(wBase+0xf0,0); /* CTRL_D1=0 -> init_HIGH, active_LOW */ /* step 4: latch&read COUNTER-0 to compute low-pulse-count */ printf("\n*** 16-bit event down counter ***\n"); /* NOTE : The 8254 need the extra starting two event_clock to initialize */ /* So the counter value before the starting two clock is error */ pio_d48_c0(0x30,0xff,0xff); /* COUNTER0,mode-0 down count 0xffff */ for (;;) { outportb(wBase+0xec,0x00); /* latch counter_0 */ low=inportb(wBase+0xe0); /* read low-count */ high=inportb(wBase+0xe0); /* read high-count */ count=(0xff-high)*256+(0xff-low)+2; /* add the starting two clock */ printf("\nhigh=%x, low=%x, LOW_pulse_count=%u",high,low,count); if (kbhit()!=0) {getch(); break;} } outportb(wBase+5,0); /* disable all interrupt */ PIO_DriverClose(); } /* -------------------------------------------------------------------- */ WORD pio_d48_c0(char cConfig, char cLow, char cHigh) /* COUNTER_0 */ { outportb(wBase+0xec,cConfig); outportb(wBase+0xe0,cLow); outportb(wBase+0xe0,cHigh); return(NoError); } WORD pio_d48_c1(char cConfig, char cLow, char cHigh) /* COUNTER_1 */ { outportb(wBase+0xec,cConfig); outportb(wBase+0xe4,cLow); outportb(wBase+0xe4,cHigh); return(NoError); } WORD pio_d48_c2(char cConfig, char cLow, char cHigh) /* COUNTER_2 */ { outportb(wBase+0xec,cConfig); outportb(wBase+0xe8,cLow); outportb(wBase+0xe8,cHigh); return(NoError); }