static asynStatus writeReadOnce(const char *port, int addr, const char *write_buffer, size_t write_buffer_len, char *read_buffer, size_t read_buffer_len, double timeout, size_t *nbytesOut, size_t *nbytesIn, int *eomReason, const char *drvInfo) { asynStatus status; asynUser *pasynUser; status = connect(port,addr,&pasynUser,drvInfo); if(status!=asynSuccess) { asynPrint(pasynUser, ASYN_TRACE_ERROR, "asynOctetSyncIO connect failed %s\n",pasynUser->errorMessage); disconnect(pasynUser); return status; } status = writeRead(pasynUser,write_buffer,write_buffer_len, read_buffer,read_buffer_len, timeout,nbytesOut,nbytesIn,eomReason); if(status!=asynSuccess) { asynPrint(pasynUser, ASYN_TRACE_ERROR, "asynOctetSyncIO writeReadOnce failed %s\n",pasynUser->errorMessage); } disconnect(pasynUser); return status; }
asynStatus ddriveController::writeRead(char *input, size_t *nread, const char *fmt, ...) { va_list argptr; va_start(argptr,fmt); asynStatus ret=writeRead(input, nread, fmt, argptr); va_end(argptr); return ret; }
asynStatus MMC100Controller::writeReadInt(int& value, const char* fmt, ...) { static const char* functionName = "MMC100Controller::writeReadInt"; size_t read; va_list argptr; char input[MMC100_STRING_SIZE]; va_start(argptr,fmt); asynStatus status = writeRead(input, &read, fmt, argptr); va_end(argptr); if (status != asynSuccess || input[0] != '#') { if (read == 0) { asynPrint(pasynUser_, ASYN_TRACE_ERROR, "%s: writeRead failed: %s (ret=%d) no data received\n", functionName, outString_, status); } else { asynPrint(pasynUser_, ASYN_TRACE_ERROR, "%s: writeRead failed: %s (ret=%d) received: %s\n", functionName, outString_, status, input); } return asynError; } else { value = atoi(&input[1]); } return status; }
asynStatus ddriveController::writeRead(double& value, const char* fmt, ...) { va_list argptr; va_start(argptr,fmt); asynStatus ret=writeRead(value, fmt, argptr); va_end(argptr); return ret; }
asynStatus ddriveController::writeReadMatch(char *ret_buf, const char* fmt, va_list argptr) { char output[DD_STRING_LEN]; vsnprintf(output, DD_STRING_LEN, fmt, argptr); size_t nread; char input[DD_STRING_LEN]; asynStatus status; status = writeRead(input, (char*)output, &nread); if (status != asynSuccess) { asynPrint(pasynUser_, ASYN_TRACE_ERROR, "%s: writeRead failed: %s (ret=%d) received: %s (len=%d)\n", __func__, output, status, input, nread); fprintf(stderr, "%s: writeRead failed: %s (ret=%d) received: %s (len=%d)\n", __func__, output, status, input, nread); if (nread > 0) strncpy(ret_buf, input, nread + 1); else ret_buf[0] = 0; return asynError; } // assume wrote something like: // mess,0 // then the output should match the input up to the input's length: // mess,0 <-- in // mess,0,10.0 <-- out // match^ if (strncmp(input, output, strlen(output))) { asynPrint(pasynUser_, ASYN_TRACE_ERROR, "%s: writeRead failed: %s input mismatch: %s\n", __func__, output, input); fprintf(stderr, "%s: writeRead failed: %s input mismatch: %s\n", __func__, output, input); if (nread > 0) strncpy(ret_buf, input, nread + 1); else ret_buf[0] = 0; return asynError; } char *response=&input[strlen(output)]; if (response[0] != ',') { asynPrint(pasynUser_, ASYN_TRACE_ERROR, "%s: writeRead failed: %s input mismatch: %s -> %s\n", __func__, output, input, response); return asynError; } else { response++; strncpy(ret_buf, response, DD_STRING_LEN - strlen(output) - 1); return asynSuccess; } return writeReadMatch(ret_buf, output); }
asynStatus ddriveController::writeRead(float& value, const char* fmt, ...) { double dval; va_list argptr; va_start(argptr,fmt); asynStatus ret=writeRead(dval, fmt, argptr); va_end(argptr); value = dval; return ret; }
static asynStatus writeCmdOnly(Command* pcommand,asynUser* pasynUser,void* data,ifaceType asynIface) { int eomReason; asynStatus status; char inpBuf[BUFFER_SIZE]; writeRead(pcommand->pport,pasynUser,pcommand->writeCommand,inpBuf,sizeof(inpBuf),&eomReason); status = (epicsStrCaseCmp(inpBuf,"OK")==0 ) ? asynSuccess : asynError; return( status ); }
static asynStatus writeFloatParam(Command* pcommand,asynUser* pasynUser,void* data,ifaceType asynIface) { int eomReason; asynStatus status; char inpBuf[BUFFER_SIZE],outBuf[BUFFER_SIZE]; sprintf(outBuf,pcommand->writeCommand,*(epicsFloat64*)data); writeRead(pcommand->pport,pasynUser,outBuf,inpBuf,sizeof(inpBuf),&eomReason); status = (epicsStrCaseCmp(inpBuf,"OK")==0 ) ? asynSuccess : asynError; return( status ); }
static asynStatus writeChannelDelay(int which, Port *pport,void* data,ifaceType asynIface) { asynStatus status; int chan,eomReason; epicsFloat64 delay; char datBuf[BUFFER_SIZE]; status = writeRead(pport,commandTable[which].readCommand,datBuf,sizeof(datBuf),&eomReason); if( ASYN_ERROR(status) ) return status; sscanf(datBuf,"%d,%lf",&chan,&delay); sprintf((char*)datBuf,commandTable[which].writeCommand,chan,*(epicsFloat64*)data); status = writeOnly(pport,datBuf); if( ASYN_ERROR( status) || !pport->check_errors ) return status; return checkError(pport); }
static asynStatus checkError(Port *pport) { asynStatus status; int eom; int old_error; char inpBuf[BUFFER_SIZE]; char outBuf[6] = "LERR?"; old_error = pport->error; status = writeRead( pport, outBuf, inpBuf, sizeof(inpBuf), &eom); if( ASYN_ERROR( status) ) return status; pport->error = atoi(inpBuf); if(old_error != pport->error) signalStatusUpdate(pport); return status; }
static asynStatus readFloat64(void* ppvt,asynUser* pasynUser,epicsFloat64* value) { float readback; int addr,status; const char* pcmd; char inpBuf[BUFFER_SIZE]; Port* pport = (Port*)ppvt; asynPrint(pasynUser,ASYN_TRACE_FLOW,"drvAsynColby::readFloat64 %s: reason - %d\n",pport->myport,pasynUser->reason); if( pasynManager->getAddr(pasynUser,&addr)) return( asynError ); switch( addr ) { case 0: case 1: pcmd = "DEL?"; break; case 4: case 5: pcmd = "STEP?"; break; default: return( asynError ); } epicsMutexMustLock(pport->syncLock); status = writeRead(pport->pasynUser,pcmd,inpBuf,sizeof(inpBuf),pport->iface); epicsMutexUnlock(pport->syncLock); if( status ) return( asynError ); sscanf(inpBuf,"%e",&readback); if( epicsStrCaseCmp(pport->units,"ns")==0 ) *value=(epicsFloat64)readback/1.0E-9; else *value=(epicsFloat64)readback/1.0E-12; asynPrint(pasynUser,ASYN_TRACEIO_FILTER,"drvAsynColby::readFloat64 %s: asyn - 0x%8.8X, addr - %d, value - %f\n",pport->myport,pasynUser,addr,*value); return( asynSuccess ); }
int I2C::readRegister(unsigned char reg_addr, void *rbuf, size_t length) { return writeRead(®_addr, 1, rbuf, length); }
static asynStatus readParam(Command* pcommand,asynUser* pasynUser,char* inpBuf,int inputSize,int* eomReason,ifaceType asynIface) { return( writeRead(pcommand->pport,pasynUser,pcommand->readCommand,inpBuf,inputSize,eomReason) ); }
asynStatus ddriveController::writeRead(char *input, size_t* nread, const char *fmt, va_list argptr) { char output[DD_STRING_LEN]; vsnprintf(output, DD_STRING_LEN, fmt, argptr); return writeRead(input, nread, output); }
static asynStatus readParam(int which, Port *pport,char* inpBuf,int inputSize,int* eomReason,ifaceType asynIface) { return writeRead(pport,commandTable[which].readCommand,inpBuf,inputSize,eomReason); }
/**************************************************************************** * Define public interface methods ****************************************************************************/ int drvAsynDG645(const char* myport,const char* ioport,int ioaddr) { int status = asynSuccess; Port* pport; int eomReason; char inpBuf[BUFFER_SIZE]; asynStandardInterfaces *pInterfaces; pport = (Port*)callocMustSucceed(1,sizeof(Port),"drvAsynDG645"); pport->myport = epicsStrDup(myport); pport->ioport = epicsStrDup(ioport); pport->ioaddr = ioaddr; pport->check_errors = 1; status = pasynOctetSyncIO->connect(ioport,ioaddr,&pport->pasynUser,NULL); if (status != asynSuccess) { errlogPrintf("%s::drvAsynDG645 port %s can't connect " "to asynCommon on Octet server %s address %d.\n", driver, myport, ioport, ioaddr); return asynError; } // pasynManager->waitConnect(pport->pasynUser, 1.0); /* Create asynUser for asynTrace */ pport->pasynUserTrace = pasynManager->createAsynUser(0, 0); pport->pasynUserTrace->userPvt = pport; status = pasynManager->registerPort(myport,ASYN_CANBLOCK,1,0,0); if( status != asynSuccess) { errlogPrintf("%s::drvAsynDG645 port %s can't register port\n", driver, myport); return asynError; } pInterfaces = &pport->asynStdInterfaces; /* Initialize interface pointers */ pInterfaces->common.pinterface = (void *)&ifaceCommon; pInterfaces->drvUser.pinterface = (void *)&ifaceDrvUser; pInterfaces->octet.pinterface = (void *)&ifaceOctet; pInterfaces->int32.pinterface = (void *)&ifaceInt32; pInterfaces->float64.pinterface = (void *)&ifaceFloat64; pInterfaces->int32CanInterrupt = 1; // for status status = pasynStandardInterfacesBase->initialize(myport, pInterfaces, pport->pasynUserTrace, pport); if (status != asynSuccess) { errlogPrintf("%s::drvAsynDG645 port %s" " can't register standard interfaces: %s\n", driver, myport, pport->pasynUserTrace->errorMessage); return asynError; } #ifdef vxWorks /* Send a sacrificial clear status to vxworks device (i.e. VME)*/ /* This fixes a problem with *IDN? call when starting from a cold boot */ /* with the SBS IP-Octal hardware. */ if( writeOnly(pport,"") ) { errlogPrintf("%s::drvAsynDG645 port %s failed to write\n", driver, myport); return asynError; } #endif /* Identification query */ if( writeRead(pport,"*IDN?",inpBuf,sizeof(inpBuf),&eomReason) ) { errlogPrintf("%s::drvAsynDG645 port %s failed to acquire identification\n", driver, myport); return asynError; } strcpy(pport->ident,inpBuf); /* Error query */ if( writeRead(pport,"LERR?",inpBuf,sizeof(inpBuf),&eomReason) ) { errlogPrintf("%s::drvAsynDG645 port %s failed to acquire error status\n", driver, myport); return asynError; } pport->error = atoi(inpBuf); /* Clear status */ if( writeOnly(pport,"*CLS") ) { errlogPrintf("%s::drvAsynDG645 port %s failed to clear status\n", driver, myport); return asynError; } /* Complete initialization */ pport->init=1; return asynSuccess; }
int main(void) { xil_printf("Starting\r\n"); int Status; int i; u32 start_time; u32 end_time; u32 return_val[ACTUAL_READS]; // Initialize DMA Status = DMA_init(DMA_DEV_ID); if (Status != XST_SUCCESS) { xil_printf("XAxiDma_init: Failed %d\r\n", Status); return XST_FAILURE; } // Initialize PE Status = XNeedlemanwunsch_Initialize(&PE, PE_DEV_ID); if (Status != XST_SUCCESS) { xil_printf("XNeedlemanwunsch_Initialize: Failed %d\r\n", Status); return XST_FAILURE; } XNeedlemanwunsch_DisableAutoRestart(&PE); // Initialize timer with maximum value so we can see how far down it // goes. It should last about 12 seconds before hitting zero. Timer_init(TIMER_DEV_ID); XScuTimer_LoadTimer(&Timer, TIMER_MAX); XScuTimer_SetPrescaler(&Timer, TIMER_PRESCALE-1); start_time = TIMER_MAX; // Flush caches Xil_DCacheFlushRange((INTPTR)&ref_genome, sizeof(ref_genome)); XScuTimer_Start(&Timer); for (i=0; i<ACTUAL_READS; i++) { DMA_send(); writeRead(0, i); while(!XNeedlemanwunsch_IsIdle(&PE) && !XNeedlemanwunsch_IsReady(&PE)) { xil_printf("Waiting for idle/ready\r\n"); } XNeedlemanwunsch_Start(&PE); //if (XNeedlemanwunsch_IsIdle(&PE) || XNeedlemanwunsch_IsReady(&PE)) { //xil_printf("Is still idle/ready\r\n"); //} while(!XNeedlemanwunsch_IsDone(&PE) /*&& !XNeedlemanwunsch_IsIdle(&PE) && !XNeedlemanwunsch_IsReady(&PE)*/) { } return_val[i] = XNeedlemanwunsch_Get_return(&PE); } XScuTimer_Stop(&Timer); end_time = XScuTimer_GetCounterValue(&Timer); xil_printf("Done\r\n"); for (i=0; i<ACTUAL_READS; i++) { xil_printf("read %d best fit at %d\r\n", i, return_val[i]); } print_time(start_time, end_time); return 0; }
static asynStatus readItRaw(void* ppvt,asynUser* pasynUser,char* data,size_t maxchars,size_t* nbytes,int* eom) { int i,addr,status; const char *pcmd; char *token,*next; Port* pport = (Port*)ppvt; char inpBuf[BUFFER_SIZE],strings[5][24]; asynPrint(pasynUser,ASYN_TRACE_FLOW,"drvAsynColby::readItRaw %s: read\n",pport->myport); if( pasynManager->getAddr(pasynUser,&addr)) return( asynError ); switch( addr ) { case 8: case 9: case 10: case 11: case 12: pcmd = "NET?"; break; case 13: pcmd = "NETM?"; break; default: return( asynError ); } epicsMutexMustLock(pport->syncLock); status = writeRead(pport->pasynUser,pcmd,inpBuf,sizeof(inpBuf),pport->iface); epicsMutexUnlock(pport->syncLock); if( status ) {*nbytes=0;*eom=0;return( asynError );}; if( addr!=13 ) { token = epicsStrtok_r(inpBuf,",",&next); for( i=0; token; ++i ) {strcpy(strings[i],token);token=epicsStrtok_r(NULL,",",&next);}; } *eom = ASYN_EOM_END; switch( addr ) { case 8: strcpy(data,strings[0]); *nbytes=strlen(strings[0]); break; case 9: strcpy(data,strings[1]); *nbytes=strlen(strings[1]); break; case 10: strcpy(data,strings[2]); *nbytes=strlen(strings[2]); break; case 11: strcpy(data,strings[3]); *nbytes=strlen(strings[3]); break; case 12: strcpy(data,strings[4]); *nbytes=strlen(strings[4]); break; case 13: strcpy(data,inpBuf); *nbytes=strlen(inpBuf); break; } asynPrint(pasynUser,ASYN_TRACEIO_DRIVER,"drvAsynColby::readItRaw %s: read %.*s from %s\n",pport->myport,*nbytes,data,pport->ioport); return( asynSuccess ); }
/**************************************************************************** * Define public interface methods ****************************************************************************/ int drvAsynCoherentSDG(const char* myport,const char* ioport,int ioaddr) { Port* pport; int len,i,j,eomReason; char inpBuf[BUFFER_SIZE]; asynUser* pasynUser; asynOctet* pasynOctet; asynFloat64* pasynFloat64; asynUInt32Digital* pasynUInt32; if( pports ) { printf("drvAsynCoherentSDG:init %s: interface already established\n",myport); return( -1 ); } if( pasynOctetSyncIO->connect(ioport,ioaddr,&pasynUser,NULL) ) { printf("drvAsynCoherentSDG:init %s: cannot connect to asyn port %s\n",myport,ioport); return( -1 ); } i = strlen(myport)+1; j = strlen(ioport)+1; len = i+j+sizeof(Port)+sizeof(asynFloat64)+sizeof(asynUInt32Digital)+sizeof(asynOctet); pport = (Port*)callocMustSucceed(len,sizeof(char),"drvAsynCoherentSDG"); pasynUInt32 = (asynUInt32Digital*)(pport + 1); pasynFloat64 = (asynFloat64*)(pasynUInt32 + 1); pasynOctet = (asynOctet*)(pasynFloat64 + 1); pport->myport = (char*)(pasynOctet + 1); pport->ioport = (char*)(pport->myport + i); pport->ioaddr = ioaddr; pport->pasynUser = pasynUser; pport->syncLock = epicsMutexMustCreate(); strcpy(pport->myport,myport); strcpy(pport->ioport,ioport); if( pasynManager->registerPort(myport,ASYN_MULTIDEVICE|ASYN_CANBLOCK,1,0,0) ) { printf("drvAsynCoherentSDG::init %s: failure to register port\n",myport); return( -1 ); } pport->asynCommon.interfaceType = asynCommonType; pport->asynCommon.pinterface = &common; pport->asynCommon.drvPvt = pport; if( pasynManager->registerInterface(myport,&pport->asynCommon) ) { printf("drvAsynCoherentSDG::init %s: failure to register asynCommon\n",myport); return( -1 ); } pport->asynDrvUser.interfaceType = asynDrvUserType; pport->asynDrvUser.pinterface = &drvuser; pport->asynDrvUser.drvPvt = pport; if( pasynManager->registerInterface(myport,&pport->asynDrvUser) ) { printf("drvAsynCoherentSDG::init %s: failure to register asynDrvUser\n",myport); return( -1 ); } pasynFloat64->read = readFloat64; pasynFloat64->write = writeFloat64; pport->asynFloat64.interfaceType = asynFloat64Type; pport->asynFloat64.pinterface = pasynFloat64; pport->asynFloat64.drvPvt = pport; if( pasynFloat64Base->initialize(myport,&pport->asynFloat64) ) { printf("drvAsynCoherentSDG::init %s: failure to initialize asynFloat64Base\n",myport); return( -1 ); } pasynUInt32->read = readUInt32; pasynUInt32->write = writeUInt32; pport->asynUInt32.interfaceType = asynUInt32DigitalType; pport->asynUInt32.pinterface = pasynUInt32; pport->asynUInt32.drvPvt = pport; if( pasynUInt32DigitalBase->initialize(myport,&pport->asynUInt32) ) { printf("drvAsynCoherentSDG::init %s: failure to initialize asynUInt32DigitalBase\n",myport); return( -1 ); } pasynOctet->flush = flushOctet; pasynOctet->read = readOctet; pasynOctet->write = writeOctet; pport->asynOctet.drvPvt = pport; pport->asynOctet.pinterface = pasynOctet; pport->asynOctet.interfaceType = asynOctetType; if( pasynOctetBase->initialize(myport,&pport->asynOctet,0,0,0) ) { printf("drvAsynCoherentSDG::init %s: failure to initialize asynOctetBase\n",myport); return( -1 ); } /* Status query */ if( writeRead(pport,pasynUser,"status?",inpBuf,sizeof(inpBuf),&eomReason) ) { printf("drvAsynCoherentSDG::init %s: failure to acquire status\n",myport); strcpy(pport->ident,"*COMM FAILED*"); return( -1 ); } else strcpy(pport->ident,"Coherent SDG"); /* Complete initialization */ pport->init=1; for( i=0; i<commandLen; ++i ) commandTable[i].pport=pport; pports = pport; return( 0 ); }
/**************************************************************************** * Define public interface methods ****************************************************************************/ int drvAsynColby(const char* myport,const char* ioport,int addr,const char* units,int iface) { Port* pport; int len,i,j,k; char inpBuf[BUFFER_SIZE]; asynUser* pasynUser; asynOctet* pasynOctet; asynFloat64* pasynFloat64; asynUInt32Digital* pasynUInt32; if( pports ) { printf("drvAsynColby:init %s: interface already estamblished\n",myport); return( -1 ); } switch( iface ) { case IFACE_ETHER: case IFACE_SERIAL: break; default: printf("drvAsynColby:init %s: invalid interface type %d specified\n",myport,iface); return( -1 ); } if( pasynOctetSyncIO->connect(ioport,addr,&pasynUser,NULL) ) { printf("drvAsynColby:init %s: cannot connect to asyn port %s\n",myport,ioport); return( -1 ); } i = strlen(myport)+1; j = strlen(ioport)+1; k = strlen(units)+1; len = i+j+k+sizeof(Port)+sizeof(asynFloat64)+sizeof(asynUInt32Digital)+sizeof(asynOctet); pport = (Port*)callocMustSucceed(len,sizeof(char),"drvAsynColby"); pasynUInt32 = (asynUInt32Digital*)(pport + 1); pasynFloat64 = (asynFloat64*)(pasynUInt32 + 1); pasynOctet = (asynOctet*)(pasynFloat64 + 1); pport->myport = (char*)(pasynOctet + 1); pport->ioport = (char*)(pport->myport + i); pport->units = (char*)(pport->ioport + j); pport->addr = addr; pport->conn = 0; pport->pasynUser = pasynUser; pport->iface = (iface==0)?IFACE_ETHER:IFACE_SERIAL; strcpy(pport->myport,myport); strcpy(pport->ioport,ioport); strcpy(pport->units,units); pport->syncLock = epicsMutexMustCreate(); if( pasynManager->registerPort(myport,ASYN_MULTIDEVICE|ASYN_CANBLOCK,1,0,0) ) { printf("drvAsynColby::init %s: failure to register port\n",myport); free(pport); return( -1 ); } pport->asynCommon.interfaceType = asynCommonType; pport->asynCommon.pinterface = &common; pport->asynCommon.drvPvt = pport; if( pasynManager->registerInterface(myport,&pport->asynCommon) ) { printf("drvAsynColby::init %s: failure to register asynCommon\n",myport); return( -1 ); } pport->asynDrvUser.interfaceType = asynDrvUserType; pport->asynDrvUser.pinterface = &drvuser; pport->asynDrvUser.drvPvt = pport; if( pasynManager->registerInterface(myport,&pport->asynDrvUser) ) { printf("drvAsynColby::init %s: failure to register asynDrvUser\n",myport); return( -1 ); } pasynFloat64->read = readFloat64; pasynFloat64->write = writeFloat64; pport->asynFloat64.interfaceType = asynFloat64Type; pport->asynFloat64.pinterface = pasynFloat64; pport->asynFloat64.drvPvt = pport; if( pasynFloat64Base->initialize(myport,&pport->asynFloat64) ) { printf("drvAsynColby::init %s: failure to initialize asynFloat64Base\n",myport); return( -1 ); } pasynUInt32->read = readUInt32; pasynUInt32->write = writeUInt32; pport->asynUInt32.interfaceType = asynUInt32DigitalType; pport->asynUInt32.pinterface = pasynUInt32; pport->asynUInt32.drvPvt = pport; if( pasynUInt32DigitalBase->initialize(myport,&pport->asynUInt32) ) { printf("drvAsynColby::init %s: failure to initialize asynUInt32DigitalBase\n",myport); return( -1 ); } pasynOctet->flush = flushIt; pasynOctet->read = readItRaw; pasynOctet->write = writeItRaw; pport->asynOctet.drvPvt = pport; pport->asynOctet.pinterface = pasynOctet; pport->asynOctet.interfaceType = asynOctetType; if( pasynOctetBase->initialize(myport,&pport->asynOctet,0,0,0) ) { printf("drvAsynColby::init %s: failure to initialize asynOctetBase\n",myport); return( -1 ); } /* Identification query */ if( writeRead(pasynUser,"*IDN?",inpBuf,sizeof(inpBuf),pport->iface) ) return( -1 ); else strcpy(pport->ident,inpBuf); pports = pport; return( 0 ); }