/* * ASYN UInt32Digital driver for MPS Buffer Readback */ #include #include #include #include #include #include #include #include "MachineStateBuffer.h" /* * Driver private storage */ typedef struct dpvtStruct { asynInterface asynCommon; asynInterface asynUInt32Digital; int (*readFunc)(unsigned int index); } 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 readMpsStatusBuffer(void *pvt, asynUser *pasynUser, unsigned int *value, unsigned int mask) { dpvt *pdpvt = (dpvt *) pvt; asynStatus status; int index; int mpsInputStatus; /* Get index */ if ((status = pasynManager->getAddr(pasynUser, &index)) != asynSuccess) { return status; } /* Read */ mpsInputStatus = pdpvt->readFunc(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 asynUInt32Digital asynUInt32DigitalMethodsReadOnly = { NULL, readMpsStatusBuffer }; #if 0 #pragma mark - #pragma mark Configure Port Instances #endif /* * Configure and register the port instances */ void devMpsStatusRegistrar() { int i; int attributes; dpvt *pdpvt; asynStatus status; const char *portName; const char *portNames[4] = { "devMpsStatusBufferReadback", /* 0 */ "devMpsBypassActiveBufferReadback", /* 1 */ "devMpsBypassValueBufferReadback", /* 2 */ "devMpsLatchedBufferReadback" /* 3 */ }; for(i = 0; i < sizeof(portNames)/sizeof(portNames[0]); i++) { portName = portNames[i]; pdpvt = callocMustSucceed(sizeof(dpvt), 1, portName); switch(i) { case 0: pdpvt->readFunc = getDeviceState; break; case 1: pdpvt->readFunc = inputIsByassed; break; case 2: pdpvt->readFunc = getBypassValue; break; case 3: pdpvt->readFunc = getLatchedDeviceState; break; default: pdpvt->readFunc = NULL; printf("devMpsStatusRegistrar: bad portname\n"); continue; } /* * 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("devMpsStatusRegistrar: registerPort failed\n"); return; } pdpvt->asynCommon.interfaceType = asynCommonType; pdpvt->asynCommon.pinterface = (void *)&asynCommonMethods; pdpvt->asynCommon.drvPvt = pdpvt; status = pasynManager->registerInterface(portName, &pdpvt->asynCommon); if (status != asynSuccess) { printf("devMpsStatusRegistrar: registerInterface failed\n"); return; } pdpvt->asynUInt32Digital.interfaceType = asynUInt32DigitalType; switch(i) { case 0: case 1: case 2: case 3: pdpvt->asynUInt32Digital.pinterface = (void *) &asynUInt32DigitalMethodsReadOnly; break; default: pdpvt->asynUInt32Digital.pinterface = NULL; printf("devMpsStatusRegistrar: bad portname\n"); continue; } pdpvt->asynUInt32Digital.drvPvt = pdpvt; status = pasynUInt32DigitalBase->initialize(portName, &pdpvt->asynUInt32Digital); if (status != asynSuccess) { printf("devMpsStatusRegistrar: registerInterface failed\n"); return; } } } epicsExportRegistrar(devMpsStatusRegistrar);