/*============================================================================= Name: devBoMps.c Abs: Device support for MPS Link node (Arcturus Coldfire 5282 processor) binary out records. Derived from $EPICS/base/src/rec/boRecord.c Auth: 21-jan-2000, Dayle Kotturi (dayle): Initial version for MPS Link Node -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) xx-xxx-2007, Dayle Kotturi: xxxxxxxxxxxxxxxxxxx =============================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mpsLinkNodeMacros.h" #include "drvMpsLinkNode.h" typedef struct boMps_s { int routine; /* O=intr en/dis, 1=sw trig */ int module; /* Accommodate 4 PIC modules */ } boMps_t; typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN write; } BODSET; #ifdef DEBUG_PRINT int devBoMpsFlag = 2; #endif LOCAL long init_bo(); LOCAL long write_bo(); BODSET devBoMpsLinkNode = { 5, NULL, NULL, init_bo, NULL, write_bo }; epicsExportAddress(dset,devBoMpsLinkNode); static long init_bo(boRecord *pbo) { boMps_t *pbop; long rc =0; /* Allocate the memory for this records private data structure */ pbop = (boMps_t *) malloc(sizeof(boMps_t)); if (pbop == NULL) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devBoMpsFlag, ("init_longout: %s: out of memory\n", pbo->name)); #endif return S_dev_noMemory; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devBoMpsFlag, ("init_bo: %s: has initial value: %d\n", pbo->name, pbo->val)); #endif /* Read the DBLINK "out" field to get the routine */ DEBUGPRINT(DP_INFO, devBoMpsFlag, ("init_bo: %s: has parm: %s\n", pbo->name, pbo->out.value.instio.string)); sscanf(pbo->out.value.instio.string, "%d %d", &(pbop->routine), &(pbop->module)); DEBUGPRINT(DP_INFO, devBoMpsFlag, ("init_bo: %s's dpvt has routine: %d module: %d\n", pbo->name, pbop->routine, pbop->module)); /* Tell the record about its private data structure */ pbo->dpvt = pbop; /* dont convert */ rc=2; return rc; } /* end init_record() */ static long write_bo(boRecord *pbo) { long rc; boMps_t *pbop; /* Set this to facilitate easy access to index field */ if (pbo->dpvt == NULL) { DEBUGPRINT(DP_ERROR, devBoMpsFlag, ("write_bo: %s: dpvt is NULL\n", pbo->name)); return ERROR; } pbop = (boMps_t *)pbo->dpvt; switch (pbop->routine) { case 0: rc = mpsSetCSR1Reset(pbop->module); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devBoMpsFlag, ("write_bo: %s: resetting CSR1\n", pbo->name)); #endif break; case 1: rc = mpsSetCSR1DiagnosticModeEnable(pbop->module); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devBoMpsFlag, ("write_bo: %s: enabling diagnostic mode in CSR1\n", pbo->name)); #endif break; case 2: rc = mpsSetCSR1Arm(pbop->module); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devBoMpsFlag, ("write_bo: %s: arming CSR1\n", pbo->name)); #endif break; case 3: rc = mpsSetCSR1Enable(pbop->module); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devBoMpsFlag, ("write_bo: %s: enabling CSR1\n", pbo->name)); #endif break; case 4: /*4/13/9 There is only one trigger, so module shouldn't need to be specified */ rc = mpsSetCSR1TriggerEdgeSelect(pbop->module, pbo->val); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, devBoMpsFlag, ("write_bo: %s: setting trigger edge to %d (0=falling, 1=rising)\n", pbo->name, pbo->val)); #endif break; case 5: rc = mpsSetCSR1MissedTriggerStatus(pbop->module, pbo->val); break; case 6: rc = mpsSetCSR1SoftwareTrigger(pbop->module, pbo->val); break; case 7: rc = mpsSetCSR1DataReady(pbop->module, pbo->val); break; case 8: rc = mpsSetCSR1GateGeneratorSelect(pbop->module, pbo->val); break; case 9: rc = mpsSetCSR1GateTriggerSelect(pbop->module, pbo->val); break; case 10: rc = mpsSetCSR1GatePolarity(pbop->module, pbo->val); break; case 11: rc = mpsSetCSR1GateEnable(pbop->module, pbo->val); break; case 12: rc = mpsSetCSR2TestPulseEnable(pbop->module, pbo->val); break; case 13: rc = mpsSetCSR2TestPulsePolarity(pbop->module, pbo->val); break; case 14: rc = mpsSetCSR2TestPulseTriggerSelect(pbop->module, pbo->val); break; case 15: rc = mpsSetCSR3SyncOutputEnable(pbop->module, pbo->val); break; case 16: rc = mpsSetCSR3SyncPulsePolarity(pbop->module, pbo->val); break; case 17: rc = mpsSetCSR3SyncOutputMode(pbop->module, pbo->val); break; case 18: rc = mpsSetCSR3ADCRangeControl(pbop->module, pbo->val); break; case 19: rc = mpsSetCSR3FBC(pbop->module, pbo->val); break; case 20: rc = mpsClrTriggerErrorCounter(pbop->module); break; case 21: /* INVASIVE */ rc = mpsQADCReadout(pbop->module); break; case 22: switch (pbo->val) { case 0: /* off is represented by bit pattern: "10" */ rc = mpsSetPICHighVoltage(2); break; case 1: /* on is repesented by bit pattern: "01" */ rc = mpsSetPICHighVoltage(1); break; } break; default: rc = ERROR; #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, devBoMpsFlag, ("write_bo: %s: unrecognized routine in bo record: %d\n", pbo->name, (int) pbop->routine)); #endif } return rc; }