/* * devMpsBypass.c * mpsLinkProcessor * * Created by Stephen Norum. * Copyright 2008 Stanford Linear Accelerator Center. All rights reserved. * */ #include #include #include #include #include #include #include "MachineStateBuffer.h" /* * Driver private storage */ struct dpvtStruct { asynInterface asynCommon; asynInterface asynUInt32Digital; }; typedef struct dpvtStruct dpvt; #if 0 #pragma mark - #pragma mark asynCommon methods #endif /* * asynCommon methods */ static void mpsBypassReport(void *pvt, FILE *fp, int details) { if (details >= 3) { fprintf(fp, "report\n"); } } static asynStatus mpsBypassConnect(void *pvt, asynUser *pasynUser) { pasynManager->exceptionConnect(pasynUser); return asynSuccess; } static asynStatus mpsBypassDisconnect(void *pvt, asynUser *pasynUser) { pasynManager->exceptionDisconnect(pasynUser); return asynSuccess; } static asynCommon asynCommonMethods = { mpsBypassReport, mpsBypassConnect, mpsBypassDisconnect }; #if 0 #pragma mark - #pragma mark asynUInt32Digital methods #endif /* * asynUInt32Digital Methods */ static asynStatus readMpsStatusBuffer(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 = 1; 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 writeMpsBypassTime(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 = setBypassActiveForDurationInSeconds(index, value); if (writeStatus < 0) { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "Invalid uint32Digital write address %u, error %d", index, writeStatus); return asynError; } return asynSuccess; } static asynStatus noRead(void *pvt, asynUser *pasynUser, unsigned int *value, unsigned int mask) { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "This record is write only."); return asynError; } static asynStatus noWrite(void *pvt, asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask) { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "This record is read only."); return asynError; } static asynUInt32Digital asynUInt32DigitalMethodsWriteOnly = { writeMpsBypassTime, noRead }; #if 0 #pragma mark - #pragma mark Configure Port Instances #endif /* * Configure and register the port instances */ void devMpsBypassRegistrar() { int i; dpvt *pdpvt; asynStatus status; const char *portName; const char *portNames[2] = { "devMpsBypassControl", /* 0 */ "devMpsBypassReadback", /* 1 */ }; for(i = 0; i < sizeof(portNames)/sizeof(portNames[0]); i++) { portName = portNames[i]; pdpvt = callocMustSucceed(sizeof(dpvt), 1, portName); /* * 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. */ status = pasynManager->registerPort(portName, ASYN_MULTIDEVICE, 1, 0, 0); if(status!=asynSuccess) { printf("devMpsBypassRegistrar: 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("devMpsBypassRegistrar: registerInterface failed\n"); return; } pdpvt->asynUInt32Digital.interfaceType = asynUInt32DigitalType; switch(i) { case 0: case 1: pdpvt->asynUInt32Digital.pinterface = (void *)&asynUInt32DigitalMethodsWriteOnly; break; default: pdpvt->asynUInt32Digital.pinterface = NULL; printf("devMpsBypassRegistrar: bad portname, id = %d\n", i); continue; } pdpvt->asynUInt32Digital.drvPvt = pdpvt; status = pasynUInt32DigitalBase->initialize(portName, &pdpvt->asynUInt32Digital); if (status!=asynSuccess) { printf("devMpsBypassRegistrar: registerInterface failed\n"); return; } } } epicsExportRegistrar(devMpsBypassRegistrar);