/* * ASYN UInt32Digital driver for MPS Buffer Readback */ #include #include #include #include #include #include #include #include "Timing.h" #include "MachineStateBuffer.h" #include "Mitigation.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 report(void *pvt, FILE *fp, int details) { if (details >= 3) { fprintf(fp, "report\n"); } } static asynStatus connect(void *pvt, asynUser *pasynUser) { pasynManager->exceptionConnect(pasynUser); return asynSuccess; } static asynStatus disconnect(void *pvt, asynUser *pasynUser) { pasynManager->exceptionDisconnect(pasynUser); return asynSuccess; } static asynCommon asynCommonMethods = { report, connect, disconnect }; #if 0 #pragma mark - #pragma mark asynUInt32Digital methods #endif static asynStatus readValue(void *pvt, asynUser *pasynUser, epicsUInt32 *value, unsigned int mask) { asynStatus status; int index = 0; int err = MPS_ERROR; epicsUInt32 tmpval = 0; /* Get index */ status = pasynManager->getAddr(pasynUser, &index); if (status != asynSuccess) { return status; } /* Read */ tmpval = 0; switch (index) { /* Misc */ case 1: err = mpsTimingIsStable(&tmpval); break; case 2: err = mpsTimingSourceIsEvg(&tmpval); break; default: err = MPS_ERROR; break; } if (err != MPS_SUCCESS) { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "Invalid uint32Digital read address %d, error %d", index, err); return asynError; } *value = tmpval; return asynSuccess; } static asynStatus writeValue(void *pvt, asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask) { asynStatus status; unsigned int index; int err; /* Get index */ status = pasynManager->getAddr(pasynUser, (int *) &index); if (status != asynSuccess) { return status; } /* Write */ switch (index) { default: err = MPS_ERROR; break; } if (err != MPS_SUCCESS) { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "Invalid uint32Digital write address %u, error %d", index, err); return asynError; } return asynSuccess; } static asynUInt32Digital asynUInt32DigitalMethods = { writeValue, readValue }; #if 0 #pragma mark - #pragma mark Configure Port Instances #endif /* * Configure and register the port instances */ void devMpsMiscRegistrar() { int attributes; dpvt *pdpvt; asynStatus status; const char *portName = "devMpsMisc"; /* * 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("devMpsMiscRegistrar: 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("devMpsMiscRegistrar: registerInterface failed\n"); return; } pdpvt->asynUInt32Digital.interfaceType = asynUInt32DigitalType; pdpvt->asynUInt32Digital.pinterface = (void *) &asynUInt32DigitalMethods; pdpvt->asynUInt32Digital.drvPvt = pdpvt; status = pasynUInt32DigitalBase->initialize(portName, &pdpvt->asynUInt32Digital); if (status!=asynSuccess) { printf("devMpsMiscRegistrar: registerInterface failed\n"); return; } } epicsExportRegistrar(devMpsMiscRegistrar);