/* * ASYN UInt32Digital driver for MPS Buffer Readback */ #include #include #include #include #include #include #include "MachineStateBuffer.h" /* * Driver private storage */ typedef struct dpvtStruct { asynInterface asynCommon; asynInterface asynUInt32Digital; } dpvt; #if 0 #pragma mark - #pragma mark asynCommon methods #endif /* * asynCommon methods */ static void mpsBufferReport(void *pvt, FILE *fp, int details) { if (details >= 3) { fprintf(fp, "report\n"); } } static asynStatus mpsBufferConnect(void *pvt, asynUser *pasynUser) { pasynManager->exceptionConnect(pasynUser); return asynSuccess; } static asynStatus mpsBufferDisconnect(void *pvt, asynUser *pasynUser) { pasynManager->exceptionDisconnect(pasynUser); return asynSuccess; } static asynCommon asynCommonMethods = { mpsBufferReport, mpsBufferConnect, mpsBufferDisconnect }; #if 0 #pragma mark - #pragma mark asynUInt32Digital methods #endif static asynStatus readMpsBypassValue(void *pvt, asynUser *pasynUser, unsigned int *value, unsigned int mask) { asynStatus status; int index; int mpsInputStatus; /* Get index */ if ((status = pasynManager->getAddr(pasynUser, &index)) != asynSuccess) { return status; } /* Read */ mpsInputStatus = getBypassValue(index); if (mpsInputStatus < 0) { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "Invalid uint32Digital read address %d, error %d", index, mpsInputStatus); return asynError; } *value = mpsInputStatus ? 1 : 0; return asynSuccess; } static asynStatus writeMpsBypassValue(void *pvt, asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask) { asynStatus status; unsigned int index; int writeStatus; /* Get index */ if ((status = pasynManager->getAddr(pasynUser, (int *) &index)) != asynSuccess) { return status; } /* Write */ writeStatus = setBypassValue(index, value); if (writeStatus < 0) { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "Invalid uint32Digital write address %u, error %d", index, writeStatus); return asynError; } return asynSuccess; } static asynUInt32Digital asynUInt32DigitalMethodsBypassControl = { writeMpsBypassValue, readMpsBypassValue }; #if 0 #pragma mark - #pragma mark Configure Port Instances #endif /* * Configure and register the port instances */ void devMpsControlRegistrar() { int attributes; dpvt *pdpvt; asynStatus status; const char *portName = "devMpsBypassValueBufferControl"; /* * Register with ASYN * * registerPort(portName, attributes, autoConnect, priority (for worker thread), stack size (for worker thread)) * Note: I/O actions do not block read thread. Therefore, no worker thread is created. Priority and stack size should be zero. */ attributes = 0; attributes |= ASYN_MULTIDEVICE; status = pasynManager->registerPort(portName, attributes, 1, 0, 0); if(status!=asynSuccess) { printf("devMpsControlRegistrar: registerPort failed\n"); return; } pdpvt = callocMustSucceed(sizeof(dpvt), 1, portName); pdpvt->asynCommon.interfaceType = asynCommonType; pdpvt->asynCommon.pinterface = (void *)&asynCommonMethods; pdpvt->asynCommon.drvPvt = pdpvt; status = pasynManager->registerInterface(portName, &pdpvt->asynCommon); if (status!=asynSuccess) { printf("devMpsControlRegistrar: registerInterface failed\n"); return; } pdpvt->asynUInt32Digital.interfaceType = asynUInt32DigitalType; pdpvt->asynUInt32Digital.pinterface = (void *) &asynUInt32DigitalMethodsBypassControl; pdpvt->asynUInt32Digital.drvPvt = pdpvt; status = pasynUInt32DigitalBase->initialize(portName, &pdpvt->asynUInt32Digital); if (status!=asynSuccess) { printf("devMpsControlRegistrar: registerInterface failed\n"); return; } } epicsExportRegistrar(devMpsControlRegistrar);