VXB_RESOURCE * AIO_pRes; unsigned AIO_IRQ; unsigned AIO_ADDR; ?? AIO_IVEC; DEV_HDR * pHdr; STATUS AIO_OpenDevice( void * reserved_parameters ){ int busno, devno, funcno; /* Locate the device on the PCI bus */ if (pciFindDevice (0x494F, 0x0100, 0, &busno, &devno, &funcno) == OK) // might be kernel only { // Device found // acquire address of important register block at BAR[2] pciConfigInLong (busno, devno, funcno, PCI_CFG_BASE_ADDRESS_2, &AIO_ADDR ); AIO_ADDR &= 0xFFFC; // clear out I/O bits etc // acquire IRQ# from PCI Config registers pciConfigInByte (busno, devno, funcno, PCI_CFG_DEV_INT_LINE, &AIO_IRQ ); // convert PCI IRQ# to Interrupt Vector ID needed by intConnect() AIO_IVEC = INUM_TO_IVEC (sysInumTbl[(int)AIO_IRQ]); } else return (ERROR); pciConfigInByte( bus, devno, funcno, 0x18, &AIO_ADDR ); // 0x18 == BAR2 if ((AIO_ADDR <= 0x0100) || (AIO_ADDR == 0xFFFC)) { AIO_ADDR = 0; return ERROR; } } STATUS AIO_IRQ_Handler((void *)() customerIRQhandler){ return intConnect (AIO_IVEC, customerIRQhandler, 0); } void AIO_DIO_Configure(bool A, B, CHi, CLo){ return sysOutByte(AIO_ADDR+3, (A?0:0x10) | (B?0:0x02) | (CHi?0:0x08) | (CLo?0:0x01) | 0x80 ); // "0" is output per port bit, "0x80" is "set mode", all other bits are left "0" for "82C55 Mode 0" compatibility } void AIO_DIO_WriteAll(UInt32 Data){ if (AIO_ADDR) sysOutLong (AIO_ADDR, Data & 0x00FFFFFF); // write to port A B C, don't write "D31 set" to +3 or it would issue a Mode command... } UInt32 AIO_DIO_ReadAll(void){ if (AIO_ADDR) return sysInLong(AIO_ADDR) & 0x00FFFFFF; // read ports A B C, don't readback the mode byte } byte AIO_IRQ_Status(){ if (AIO_ADDR) return sysInByte(AIO_ADDR+0x29, 0xFF) & 0x01; // "1" means an IRQ is latched } void AIO_IRQ_Enable(){ if (AIO_ADDR) sysOutByte(AIO_ADDR+0x28, 0xFF); } void AIO_IRQ_Clear(){ if (AIO_ADDR) sysOutByte(AIO_ADDR+0x29, 0xFF); } void AIO_IRQ_Disable(){ if (AIO_ADDR) sysOutByte(AIO_ADDR+0x29, 0xFF); } void AIO_CloseDevice(){ AIO_ADDR = 0; } void main(void) // test routine / sample program { if (OpenDevice() == SUCCESS) { DIO_Configure(OUTPUT, OUTPUT, INPUT, OUTPUT); // port A, B, CHi, CLo direction control DIO_WriteAll(0x012345L); // write 24 bits of output; bits for CHi ("4"), will be ignored as it is an input UInt32 DIO_Data = DIO_ReadAll(); // read 24 bits of input; reads from outputs provide stored register value ("readback") IRQ_Handler(myISR); IRQ_Clear(); IRQ_Enable(); ... handle IRQ stuff ... CloseDevice(); } }