#include #include #include #include "alarm.h" #include "cvtTable.h" #include "dbDefs.h" #include "devLib.h" #include "dbAccess.h" #include "recSup.h" #include "callback.h" #include "devSup.h" #include "dbScan.h" /* for SCAN_IO_EVENT */ #include "link.h" #include "longoutRecord.h" /* for longoutRecord structure */ #include "epicsExport.h" /* for epicsExportAddress */ #include #include /* for DEBUGPRINT */ #include "drvMpsLinkNode.h"/* for mpsSet* */ typedef struct loMps_s { int routine; int pic; int channel; int type; } loMps_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write_write; } LONGDSET; #ifdef DEBUG_PRINT int devLongoutMpsFlag = 0; #endif LOCAL long init_longout(); LOCAL long longout_ioinfo(); LOCAL long write_longout(); LONGDSET devLongoutMpsLinkNode = {5, NULL, NULL, init_longout, longout_ioinfo, write_longout}; epicsExportAddress(dset, devLongoutMpsLinkNode); LOCAL long init_longout(struct longoutRecord *plongout) { loMps_t *plop; /* Allocate the memory for this records private data structure */ plop = (loMps_t *) malloc(sizeof(loMps_t)); if (plop == NULL) { return S_dev_noMemory; } /* Read the DBLINK "out" field to get the routine */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("init_longout: %s: has parm: %s\n", plongout->name, plongout->out.value.instio.string)); #endif sscanf(plongout->out.value.instio.string, "%d %d %d %d", &(plop->routine), &(plop->pic), &(plop->channel), &(plop->type)); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("init_longout: %s's dpvt has routine: %d, pic:%d, ch:%d, thldty:%d\n", plongout->name, (int) plop->routine, (int) plop->pic, (int) plop->channel, (int) plop->type)); #endif /* Tell the record about its private data structure */ plongout->dpvt = plop; /* Idea: knowing that st.cmd called mpsParseNodeConfig already, get the values from SQL db that are now in memory, into the PVs */ switch (plop->routine) { case 0: plongout->val = mpsGetDebounceTime(plop->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("init_longout: %s: gets val %d from SQL via mpsGetDebounceTime(%d)\n", plongout->name, plongout->val, plop->channel)); #endif break; case 1: plongout->val = mpsGetDeadMan(plop->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("init_longout: %s: gets val %d from SQL via mpsGetDeadman(%d)\n", plongout->name, plongout->val, plop->channel)); #endif break; /* case 2: plongout->val = mpsGetDebounceTimeEnum(plop->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("init_longout: %s: gets val %d from SQL via mpsGetDebounceTime(%d)\n", plongout->name, plongout->val, plop->channel)); #endif break; */ case 3: plongout->val = mpsGetAutoRecoverable(plop->channel); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("init_longout: %s: gets val %d from SQL via mpsGetDebounceTime(%d)\n", plongout->name, plongout->val, plop->channel)); #endif break; case 12: /* hw initialises this to 0x2E at start */ plongout->val = mpsGetCSR2TestAcquisitionDelayControl(); break; /* nothing to do for routines 4-11, 13-28, but don't want error msg of default case default: errlogPrintf("init_longout: %s: unrecognized routine: %d", plongout->name, (int) plop->routine); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutMpsFlag, ("write_longout: %s: unrecognized value in routine: %d", plongout->name, (int) plop->routine)); #endif return ERROR; */ } return OK; } LOCAL long longout_ioinfo( int cmd, struct longoutRecord *plongout, IOSCANPVT *ppvt ) { return OK; } LOCAL long write_longout(struct longoutRecord *plongout) { int rc; loMps_t *plop; /* Set this to facilitate easy access to index field */ plop = (loMps_t *)plongout->dpvt; switch (plop->routine) { case 0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("write_longout: %s: mpsSetDebounceTime\n", plongout->name)); DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("for channel %d to %d microseconds\n", plop->channel, (int)plongout->val)); #endif rc = mpsSetDebounceTime(plop->channel, (int)plongout->val); if (rc == ERROR) { errlogPrintf("write_longout: %s: unable to set debounce time from usecs to: %d", plongout->name, (int) plongout->val); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutMpsFlag, ("write_longout: %s: unable to set debounce time from usecs to: %d", plongout->name, (int) plongout->val)); #endif } break; case 1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("write_longout: %s: mpsSetDeadMan\n", plongout->name)); DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("for channel %d to %d\n", plop->channel, (int)plongout->val)); #endif rc = mpsSetDeadMan(plop->channel, (int)plongout->val ); if (rc == ERROR) { errlogPrintf("write_longout: %s: unable to set deadman to: %d", plongout->name, (int) plongout->val); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutMpsFlag, ("write_longout: %s: unable to set deadman to: %d", plongout->name, (int) plongout->val)); #endif } break; case 2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("write_longout: %s: mpsSetDebounceEnum\n", plongout->name)); DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("for channel %d to %d\n", plop->channel, (int)plongout->val)); #endif rc = mpsSetDebounceEnum(plop->channel, (int) plongout->val); if (rc == ERROR) { errlogPrintf("write_longout: %s: unable to set debounce time from enum to: %d", plongout->name, (int) plongout->val); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutMpsFlag, ("write_longout: %s: unable to set debounce time from enum to: %d", plongout->name, (int) plongout->val)); #endif } break; case 3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("write_longout: %s: mpsSetAutoRecoverable\n", plongout->name)); DEBUGPRINT(DP_INFO, devLongoutMpsFlag, ("for channel %d to %d\n", plop->channel, (int)plongout->val)); #endif rc = mpsSetAutoRecoverable(plop->channel, (int)plongout->val); if (rc == ERROR) { errlogPrintf("write_longout: %s: unable to set isAutoRecoverable to: %d", plongout->name, (int) plongout->val); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutMpsFlag, ("write_longout: %s: unable to set isAutoRecoverable to: %d", plongout->name, (int) plongout->val)); #endif } break; case 4: rc = mpsSetPICThreshold(plop->pic, plop->channel, plop->type, plongout->val); break; case 5: rc = mpsSetBYKADCNumPresamples(plongout->val); break; case 6: rc = mpsSetBYKADCNumSamples(plongout->val); break; case 7: rc = mpsSetBYKADCDelay(plongout->val); break; case 8: rc = mpsSetQADCCSR(plop->type, (unsigned short) plongout->val); break; /* moved to ao 2/26/9 case 9: rc = mpsSetFiducialDelay((unsigned) plongout->val); break; case 10: rc = mpsSetFiducialWidth((unsigned) plongout->val); break; */ case 11: rc = mpsSetFiducialDCMPhase((unsigned) plongout->val); break; case 12: rc = mpsSetCSR2TestAcquisitionDelayControl(plongout->val); break; case 13: rc = mpsSetTriggerDelay(plongout->val); break; case 14: rc = mpsClrTriggerErrorCounter(); break; case 15: #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, devLongoutMpsFlag, ("write_longout: %s: mpsSetTestPulseGeneratorDelay(%d)\n", plongout->name, (int) plongout->val)); #endif rc = mpsSetTestPulseGeneratorDelay(plongout->val); break; case 16: rc = mpsSetTestPulseGeneratorWidth(plongout->val); break; case 17: rc = mpsSetGateGeneratorDelay(plongout->val); break; case 18: rc = mpsSetGateGeneratorWidth(plongout->val); break; case 19: rc = mpsSetSyncOutDelay(plongout->val); break; case 20: rc = mpsSetSyncOutWidth(plongout->val); break; case 21: rc = mpsSetGeneralPurposeIOControl(plongout->val); break; case 22: rc = mpsSetGateADCDelay(plongout->val); break; case 23: rc = mpsSetBeamToTestAcqDelay(plongout->val); break; case 24: rc = mpsSetTestToBaseAcqDelay(plongout->val); break; case 25: rc = mpsSetExtendedGateGeneratorDelay(plongout->val); break; case 26: rc = mpsSetExtendedGateGeneratorWidthLow(plongout->val); break; case 27: rc = mpsSetExtendedGateGeneratorWidthHigh(plongout->val); break; case 28: rc = mpsSetExtendedGateGeneratorWidth((unsigned int)(plongout->val)); break; default: rc = ERROR; errlogPrintf("write_longout: %s: unable to set isAutoRecoverable to: %d", plongout->name, (int) plongout->val); #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devLongoutMpsFlag, ("write_longout: %s: unrecognized value in routine: %d\n", plongout->name, (int) plop->routine)); #endif } return rc; }