#include "P1002.H" /* -------------------------------------------------------------------- */ float P1002_FloatSub2(float fA, float fB) { return(fA-fB); } short P1002_ShortSub2(short nA, short nB) { return(nA-nB); } WORD P1002_DriverInit(WORD *wBoards) { WORD wReturnCode; wReturnCode=GetAddress(); if ( wReturnCode ) { *wBoards=0; return( wReturnCode ); } *wBoards=wTotalBoards; return( wReturnCode ); } WORD P1002_DriverClose(void) { return( NoError ); } WORD P1002_GetDriverVersion(WORD *wDriverVersion) { *wDriverVersion=0x100; return( NoError ); } /* -------------------------------------------------------------------- */ WORD P1002_GetConfigAddressSpace(WORD wBoardNo, WORD *wBaseAddr, WORD *wIrq , WORD *wPLX) { WORD wIndex; if (wGetAddress==0) { if (GetAddress()!=0) return(FindBoardError); } if ( wBoardNo>=wTotalBoards ) return ExceedBoardNumber; wIndex=wBoardNo; *wBaseAddr = wConfigSpace[wIndex][0]; *wIrq = wConfigSpace[wIndex][1]; *wPLX = wConfigSpace[wIndex][2]; return(NoError); } WORD GetAddress(void) { DWORD dConfigAddress,dBaseAddress,dwVal; WORD HiWord,LoWord,wVal; WORD ReturnCode,ww; UCHAR Bus,Device,Function,WhichLong; WORD VendorID,DeviceID; WORD SubVendorID,SubDeviceID; WORD wIrqNumber; wTotalBoards=0; /* initial board number is 0 */ Bus=0; for (Bus=0; Bus<32; Bus++) /* max 32 PCI-SLOT */ { Function=0; WhichLong=1; for(Device=0; Device<32; Device++) { WhichLong=0; WriteAddress(Bus,Device,Function,WhichLong); VendorID=inport(0xcfc); DeviceID=inport(0xcfe); /* WhichLong=0x0b; WriteAddress(Bus,Device,Function,WhichLong); SubVendorID=inport(0xcfc); SubDeviceID=inport(0xcfe); */ if ( VendorID==0x1234 && DeviceID==0x1002) /* 1002 */ { WhichLong=5; /* PLX base address */ WriteAddress(Bus,Device,Function,WhichLong); wVal=(inport(0xcfc)&0xfffe); wConfigSpace[wTotalBoards][2]=wVal; WhichLong=6; /* TMC12 base address */ WriteAddress(Bus,Device,Function,WhichLong); dBaseAddress=_inpd(0xcfc); wVal=(WORD)(dBaseAddress&0xfffe); wConfigSpace[wTotalBoards][0]=wVal; WhichLong=15; /* interrupt channel */ WriteAddress(Bus,Device,Function,WhichLong); dwVal=_inpd(0xcfc); wConfigSpace[wTotalBoards][1]=dwVal&0xff; wTotalBoards++; /* increment board number */ if (wTotalBoards >16) return ExceedBoardNumber; wGetAddress=1; } } } return( NoError ); } void WriteAddress(UCHAR bBus, UCHAR bDevice, UCHAR bFunction, UCHAR bWhichLong) { DWORD dOutData; WORD HiWord,LoWord; UCHAR HiByte,LoByte; HiWord=0x8000|bBus; HiByte=(bDevice<<3)|bFunction; LoByte=(bWhichLong<<2) & 0xfc; LoWord=( (WORD)HiByte<<8 )|LoByte; dOutData=( (DWORD)HiWord<<16 ) | LoWord; _outpd(0xcf8,dOutData); } //////// //WORD P1002_Delay(WORD wDownCount) //{ // WORD h,l; // int count; // wDownCount &= 0x7fff; // if (wDownCount<1) wDownCount=1; /* Clock in=4M --> count 4000 = 1 ms ,count 1 = 0.25 us */ // l=wDownCount&0xff; // wDownCount=wDownCount / 256; // h=wDownCount&0xff; // outp(wBaseAddr+3*4,0xB0); /* mode_0, counter_2 */ // outp(wBaseAddr+2*4,l); /* counter_2 low byte first */ // outp(wBaseAddr+2*4,h); /* counter_2 high byte ,0x07D0=2000 */ // outp(wBaseAddr+3*4,0x80); /* latch counter_2 */ // l=inp(wBaseAddr+2*4); /* delay starting two clks */ // h=inp(wBaseAddr+2*4); // for (count=32767;count>0;count--){ // outp(wBaseAddr+3*4,0x80); /* latch counter_2 */ // l=inp(wBaseAddr+2*4); // h=inp(wBaseAddr+2*4); // if (h>=0x80) return NoError; // } // return TimeOut; //} //*/