/*============================================================================= Name: mgntPauUsr.c Abs: PAU user routines to be registered with pau module Side: The decision for pattern aware magnets to read fcom blob value or data slot value depends on the FBCK PV (= ON, OFF) soley For phase 2, we can add an additional check to see if FBCKFCOM == FCOM ie, original thoughts: IF (FBCK==ON and FBCKFCOM = 1 (FCOM)) Read FCOM value from PAU: fcomGetBlob (deviceGID:SID | data slot #, กฤ) Else (IF FBCK==OFF or FBCKFCOM=0 (CA) Read BCTRL value from PAU: pMux->dataSlot[slot #] NOTE: Modified common/mgnt_ip231_dac.template to add DACCARD PV Also added MCORDEVNAME PV to mgnt_pau.template April 23 - To Do: clean up code; boot with push function = null in st.cmd Since the pull function reads from fcom, does all conversions and writes to DAC Auth: 10-feb-2010, drogind (DROGIND) Rev: dd-mmm-yyyy, Reviewer's Name -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: 26-May-2023, K. Luchini (LUCHINI): 64-bit changes 10-Oct-2012, K. Luchini (LUCHINI): impliment use of ASLO and AOFF when converting from from volts to dac counts 29-Jun-2011, drogind (DROGIND): moved fcomReleaseBlob(&pblob) =============================================================================*/ #include "debugPrint.h" #ifdef DEBUG_PRINT int mgntPauUsrFlag = DP_WARN; #endif #include /* for ip231Write */ #include /* for calloc */ #include /* for strcpy */ #include /* for uint32_t_t */ /* epics */ #include #include #include #include #include /* EPICS dbAddr struct */ #include /* for struct waveformRecord */ #include /* for struct subRecord */ #include #include #include /* for menuConvertLINEAR, menuConvertSLOPE */ #include #include #include #include #include /* MGNT_MAX_POLY_COEF */ #include /* Data slot specific fields */ typedef struct { FcomID fcomId; /* fcom ID corresponding to index GETFCOM_i */ char pvname_ca[PVNAME_MAX]; /* slotted pv name to which to subscribe */ double Bval; /* B field desired value */ double Ival; /* I raw calculated des value */ double Vval; /* V calculated dac VSETPT */ signed int dacval; /* converted raw val sent to dac */ unsigned int calcBadCnt; /* calc'ed value of I or V invalid */ unsigned int fcomBadCnt; /* when matched (active, current) PULSEID does not match sent blob PULSEID */ unsigned int fcomCnt; /* when (active, current) PULSEID matches */ unsigned int fcomExc1Cnt; /* FCOM communication error */ unsigned int fcomExc2Cnt; /* FCOM version or data type mismatch */ } usrDataSlot_ts; /* Device specific fields */ typedef struct { double polycoef[ MGNT_MAX_POLY_COEF]; /* array of polynomials */ int initPullBad; /* whether pull init is bad or not */ int getPVsBadCnt; /* whether reading from PVs is bad */ uint32_t nelm; /* number of polynomials */ signed int dacval; /* converted raw val sent to dac */ char mcorDevice_ca[PVNAME_MAX]; /* MCOR device name */ double i2vslope; /* I2VSLOPE PV calc output */ double bctrlHi; /* high val for dev BCTRL - not used */ double bctrlLo; /* low val for mcor BCTRL - not used */ double isetptHi; /* high val for mcor ISETPT*/ double isetptLo; /* low val for mcor ISETPT */ double vsetptHi; /* high val for mcor VSETPT*/ double vsetptLo; /* low val for mcor VSETPT */ double vsetptESLO; /* eng slope for VSETPT used in val->raw calc */ double vsetptEOFF; /* eng offset for VSETPT used in val->raw calc */ double vsetptASLO; /* eng slope for VSETPT used in val->raw calc */ double vsetptAOFF; /* eng offset for VSETPT used in val->raw calc */ unsigned short vsetptLINR; /* eng offset for VSETPT used in val->raw calc */ double dacchan; /* dac chan # from mcor DACCHAN PV */ char daccard_ca[PVNAME_MAX]; /* dac card # from mcor DACCARD PV */ DBADDR pwfAddr; /* pointer to $(DEV):IVB dbAddr struct to read polys */ DBADDR vsetptAddrESLO; /* pointer to MCOR VSETPT.ESLO dbAddr struct to read ESLO */ DBADDR vsetptAddrEOFF; /* pointer to MCOR VSETPT.EOFF dbAddr struct to read EOFF */ DBADDR vsetptAddrASLO; /* pointer to MCOR VSETPT.ASLO dbAddr struct to read ASLO */ DBADDR vsetptAddrAOFF; /* pointer to MCOR VSETPT.AOFF dbAddr struct to read AOFF */ DBADDR vsetptAddrLINR; /* pointer to MCOR VSETPT.LINR dbAddr struct to read LINR */ DBADDR i2vslopeAddr; /* point to I2VSLOPE */ DBADDR isetptAddrHi; DBADDR isetptAddrLo; DBADDR vsetptAddrHi; DBADDR vsetptAddrLo; DBADDR vsetptAddr; IP231_ID pcard; usrDataSlot_ts dataSlot[MAXNUM_DATASLOTS]; /* array of data per MUX data slot */ } pullUsrData_ts; pullUsrData_ts * ppullUsrData = 0; static int mgntCalcBtoI(mux_ts * pMux, int slot); static int mgntCalcItoV(mux_ts * pMux, int slot); static int mgntsetDAC (mux_ts * pMux, int slot); static void mgntPauUsrPushInit(mux_ts * pMux); /*============================================================================= Name: mgntfcomStatus Abs: Diagnostic to dump information about various fcmom status items available Args: none Rem: Called as an iocsh command to look at diagnostics counters Side: Ret: None NOTE: set IP231_DRV_DEBUG = 1 to see DAC values sent to ip231 driver ==============================================================================*/ /**procedure**/ void mgntfcomStatus(void) { int i; if (ppullUsrData) { /*for (i=0;idataSlot[i].fcomId);*/ /* fcom ID corresponding to index GETFCOM_i */ printf ("Bval = %f\n", ppullUsrData->dataSlot[i].Bval); /* B field desired value */ printf (" Ival = %f\n", ppullUsrData->dataSlot[i].Ival); /* I raw calculated des value */ printf (" Vval = %f\n", ppullUsrData->dataSlot[i].Vval); /* V calculated dac VSETPT */ printf (" dacval = %d\n", ppullUsrData->dataSlot[i].dacval); /* converted raw val sent to dac */ printf (" calcBadCnt= %d\n", ppullUsrData->dataSlot[i].calcBadCnt); /* status of calc'ed value */ printf (" fcomBadCnt = %u\n", ppullUsrData->dataSlot[i].fcomBadCnt); /* when not matched (active, current)PULSEID */ printf (" total fcomCnt = %u\n", ppullUsrData->dataSlot[i].fcomCnt); printf (" fcom comm err = %u\n", ppullUsrData->dataSlot[i].fcomExc1Cnt); printf (" fcom vers/data type mismatch = %d\n", ppullUsrData->dataSlot[i].fcomExc2Cnt ); } } else printf(" Invalid Command. Data variable is empty \n"); } /*============================================================================= =============================================================================== Name: mgntfcomInit - Registered Function NOT USED Abs: The function mgntFcomInit initializes the fcom Args: IP addr string Rem: Deprecated Design This function is registered for ioc shell This function is called once from st.cmd if fcom is configured. It is called after all other IOC initialization is done. Side: Look at fcom_api and decide what calls are per device and what calls are init. Place the per device calls into mgntPauUsr.c . Ret: none =============================================================================*/ void mgntfcomInit(const char * fcomIP_p) { int status = 0; DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntfcomInit reached !! \n")); /* create the fcomInitEvent_ps fcomInitEvent_ps = epicsEventMustCreate(epicsEventEmpty);*/ DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntfcomInit calling fcomInit(239.255.0.0,20) !! \n")); status = fcomInit("239.255.0.0", 20); /*status = fcomInit (fcomIP_p, 20);*/ /*if (fcomInitEvent_ps) { epicsEventSignal(fcomInitEvent_ps ); }*/ if(status != 0) { errlogPrintf("mgntfcomInit: fcomInit failed: %s\n", fcomStrerror(status)); return; } return; } /*============================================================================= =============================================================================== Name: mgntfcomPVName - Registered Function NOT USED Abs: The function mgntFcomInit initializes the fcom Args: const char * pv name Rem: Design deprecated This function is registered for usage from ioc shell; but was never used This function is called from st.cmd if fcom is configured. It is called after mgntfcomInit() to init each group It passes in a pv name for every fcom group for which the ioc want to subscribe Side: NOT IMPLEMENTED Ret: none =============================================================================*/ void mgntfcomPVName(const char * mgntfcomPVName_p ) { errlogPrintf("mgntfcomPVName: Not implemented yet\n"); return; } /*============================================================================= Name: mgntPauUsrGetFieldsFromPVsInit Abs: upon init, read pertinent values configured in the MCOR EPICS DB via PVs Args: const char * pv name Rem: Stores, in UsrPull memory the following : pMux->pPullUsr->i2vslopeAddr pMux->pPullUsr->isetptAddrHi for MCOR ISETPT.HOPR PV access pMux->pPullUsr->isetptAddrLo for MCOR ISETPT.LOPR PV access pMux->pPullUsr->vsetptAddrHi for MCOR VSETPT.HOPR PV access pMux->pPullUsr->vsetptAddrLo for MCOR VSETPT.LOPR PV access pMux->pPullUsr->vsetptAddrESLO for MCOR VSETPT.ESLO PV access pMux->pPullUsr->vsetptAddrEOFF for MCOR VSETPT.EOFF PV access pMux->pPullUsr->vsetptAddrASLO for MCOR VSETPT.ASLO PV access pMux->pPullUsr->vsetptAddrAOFF for MCOR VSETPT.AOFF PV access pMux->pPullUsr->vsetptAddrLINR for MCOR VSETPT.LINR PV access pMux->pPullUsr->dacchan value of MCOR DACCHAN.VAL PV pMux->pPullUsr->daccard value of MCOR DACCARD.VAL PV (new, in mgnt_ip231_dac.template) Side: Depends on mux device name (name w attribute stripped off) to be stored in usr mem via mgntPauUsrGetMuxDeviceNameFromPV =============================================================================*/ static int mgntPauUsrGetFieldsFromPVsInit (mux_ts * pMux) { DBADDR pmcordevnameAddr; /* db addr for MCORDEVNAME PV */ DBADDR pdacchanAddr; /* db addr for MCOR DACCHAN PV */ DBADDR pdaccardAddr; /* db addr for MCOR DACCARD PV */ pullUsrData_ts *pData = (pullUsrData_ts*)pMux->pPullUsr; int32_t options = 0; int32_t nRequest = 1; /* these are for fetching Epics PV's */ /* create storage for returned parsed strings */ char mcorname_ca[PVNAME_MAX]; char isetpthopr_ca[PVNAME_MAX]; char vsetpthopr_ca[PVNAME_MAX]; char isetptlopr_ca[PVNAME_MAX]; char vsetptlopr_ca[PVNAME_MAX]; char vsetptESLO_ca[PVNAME_MAX]; char vsetptEOFF_ca[PVNAME_MAX]; char vsetptASLO_ca[PVNAME_MAX]; char vsetptAOFF_ca[PVNAME_MAX]; char vsetptLINR_ca[PVNAME_MAX]; char i2vslope_ca[PVNAME_MAX]; char dacchan_ca[PVNAME_MAX]; char daccard_ca[PVNAME_MAX]; DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs reached \n")); /* now format ISETPT, I2VSLOPE and VSETPT names */ if (pMux->device != NULL) { sprintf(mcorname_ca, "%s:MCORDEVNAME",pMux->device ); DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: MCORDEVNAME = %s\n", (char *)mcorname_ca)); } else { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetMDCORConfigsFromPVs: no mux dev name stored for %s failed\n", (char *)pMux->name)); return (-1); } if ( dbNameToAddr(mcorname_ca, &pmcordevnameAddr) ) { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs Unsuccessful dbNameToAddr of %s \n", (char *)mcorname_ca)); return (-1); } else { if (dbGet(&pmcordevnameAddr, DBR_STRING, (char *)(pData->mcorDevice_ca), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of MCORDEVNAME = %s", (char *)(mcorname_ca)); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %s\n", (char *)mcorname_ca, (char *)pData->mcorDevice_ca)); sprintf(isetpthopr_ca, "%sISETPT.DRVH",pData->mcorDevice_ca ); sprintf(vsetpthopr_ca, "%sVSETPT.DRVH",pData->mcorDevice_ca ); sprintf(isetptlopr_ca, "%sISETPT.DRVL",pData->mcorDevice_ca ); sprintf(vsetptlopr_ca, "%sVSETPT.DRVL",pData->mcorDevice_ca ); sprintf(vsetptESLO_ca, "%sVSETPT.ESLO",pData->mcorDevice_ca ); sprintf(vsetptEOFF_ca, "%sVSETPT.EOFF",pData->mcorDevice_ca ); sprintf(vsetptASLO_ca, "%sVSETPT.ASLO",pData->mcorDevice_ca ); sprintf(vsetptAOFF_ca, "%sVSETPT.AOFF",pData->mcorDevice_ca ); sprintf(vsetptLINR_ca, "%sVSETPT.LINR",pData->mcorDevice_ca ); sprintf(i2vslope_ca, "%sI2VSLOPE.VAL",pData->mcorDevice_ca ); sprintf(dacchan_ca, "%sDACCHAN" ,pData->mcorDevice_ca ); sprintf(daccard_ca, "%sDACCARDNAME" ,pData->mcorDevice_ca ); } } if ( dbNameToAddr(isetpthopr_ca, &(pData->isetptAddrHi)) ) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)isetpthopr_ca)); return (-1); } else { if (dbGet(&(pData->isetptAddrHi), DBR_DOUBLE, &(pData->isetptHi), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of %s", (char *)(isetpthopr_ca)); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %f\n", (char *)isetpthopr_ca, (double)pData->isetptHi)); } } if ( dbNameToAddr(isetptlopr_ca, &(pData->isetptAddrLo)) ) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)isetptlopr_ca)); return (-1); } else { if (dbGet(&(pData->isetptAddrLo), DBR_DOUBLE, &(pData->isetptLo), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of %s", (char *)(isetptlopr_ca)); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %f\n", (char *)isetptlopr_ca, (double)pData->isetptLo)); } } if ( dbNameToAddr(vsetpthopr_ca, &(pData->vsetptAddrHi)) ) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)vsetpthopr_ca)); return (-1); } else { if (dbGet(&(pData->vsetptAddrHi), DBR_DOUBLE, &(pData->vsetptHi), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of %s", (char *)(vsetpthopr_ca)); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %f\n", (char *)vsetpthopr_ca, (double)pData->vsetptHi)); } } if ( dbNameToAddr(vsetptlopr_ca, &(pData->vsetptAddrLo)) ) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)vsetptlopr_ca)); return (-1); } else { if (dbGet(&(pData->vsetptAddrLo), DBR_DOUBLE, &(pData->vsetptLo), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of %s", (char *)(vsetptlopr_ca)); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %f\n", (char *)vsetptlopr_ca, (double)pData->vsetptLo)); } } if ( dbNameToAddr(vsetptESLO_ca, &(pData->vsetptAddrESLO)) ) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)vsetptESLO_ca)); return (-1); } else { if (dbGet(&(pData->vsetptAddrESLO), DBR_DOUBLE, &(pData->vsetptESLO), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of %s", (char *)(vsetptESLO_ca)); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %f\n", (char *)vsetptESLO_ca, (double)pData->vsetptESLO)); } } if ( dbNameToAddr(vsetptEOFF_ca, &(pData->vsetptAddrEOFF)) ) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)vsetptEOFF_ca)); return (-1); } else { if (dbGet(&(pData->vsetptAddrEOFF), DBR_DOUBLE, &(pData->vsetptEOFF), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of %s", (char *)(vsetptEOFF_ca)); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %f\n", (char *)vsetptEOFF_ca, (double)pData->vsetptEOFF)); } } if ( dbNameToAddr(vsetptASLO_ca, &(pData->vsetptAddrASLO)) ) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)vsetptASLO_ca)); return(-1); }else if (dbGet(&(pData->vsetptAddrASLO), DBR_DOUBLE,&(pData->vsetptASLO), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of %s", (char *)(vsetptASLO_ca)); return (-1); } if ( dbNameToAddr(vsetptAOFF_ca, &(pData->vsetptAddrAOFF)) ) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)vsetptAOFF_ca)); return(-1); }else if (dbGet(&(pData->vsetptAddrAOFF), DBR_DOUBLE,&(pData->vsetptAOFF), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of %s", (char *)(vsetptAOFF_ca)); return (-1); } if ( dbNameToAddr(vsetptLINR_ca, &(pData->vsetptAddrLINR)) ) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)vsetptLINR_ca)); return(-1); }else if (dbGet(&(pData->vsetptAddrLINR), DBR_ENUM,&(pData->vsetptLINR), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of %s", (char *)(vsetptLINR_ca)); return (-1); } if (dbNameToAddr (dacchan_ca, &pdacchanAddr)) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)dacchan_ca)); return (-1); } else { if (dbGet(&pdacchanAddr, DBR_DOUBLE, &pData->dacchan, &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of DACCHAN = %s", (char *)(dacchan_ca)); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %f\n", (char *)dacchan_ca, pData->dacchan)); } } if (dbNameToAddr (daccard_ca, &pdaccardAddr)) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)daccard_ca)); /* debug - force a "ao0" for testing */ strcpy (pData->daccard_ca, "ao0"); /*return (-1); */ } else { if (dbGet(&pdaccardAddr, DBR_STRING, (char *)(pData->daccard_ca), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of DACCARD = %s", (char *)(daccard_ca)); /* debug - force a "ao0" for testing */ strcpy (pData->daccard_ca, "ao0"); /* debug then uncomment this return return (-1);*/ } else { /* contact ip231 driver to get card pointer from linked list */ pData->pcard = ip231GetByName((char *)pData->daccard_ca); DEBUGPRINT(DP_INFO, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %s AND IP231_ID!!! \n", (char *)daccard_ca, (char *)pData->daccard_ca)); } } if (dbNameToAddr (i2vslope_ca, &(pData->i2vslopeAddr))) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: dbNameToAddr of %s failed\n", (char *)i2vslope_ca)); return (-1); } else { if (dbGet(&(pData->i2vslopeAddr), DBR_DOUBLE, &(pData->i2vslope), &options, &nRequest, NULL)) { epicsPrintf ("mgntPau UsrGetFieldsFromPVs: Error for dbGet of I2VSLOPE = %s", (char *)(i2vslope_ca)); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetFieldsFromPVs Successful dbGet of %s = %f\n", (char *)i2vslope_ca, pData->i2vslope)); } } /* Note, the dbGet values in this Init routine are not accurate since the Pvs are uninitialized */ DEBUGPRINT(DP_INFO, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: i2vslope=%f; isetptHi=%f; isetptLo=%f; vsetptHi=%f; vsetptLo=%f;\n\t dacchan=%f; daccard=%s; \n\tvsetptESLO=%f; vsetptEOFF= %f;\n\t vsetptASLO= %f; vsetptAOFF= %f;\n\t vsetptLINR= %hd\n", pData->i2vslope, pData->isetptHi,pData->isetptLo, pData->vsetptHi,pData->vsetptLo, pData->dacchan,(char *)pData->daccard_ca, pData->vsetptESLO,pData->vsetptEOFF, pData->vsetptASLO,pData->vsetptAOFF, pData->vsetptLINR )); return 0; } /*============================================================================= Name: mgntPauUsrGetFieldsFromPVs Abs: read pertinent values configured in the MCOR EPICS DB every usrPull function Args: const char * pv name Rem: Stores, in UsrPull memory the following : pMux->pPullUsr->i2vslope from MCOR I2VSLOPE PV pMux->pPullUsr->isetptHi from MCOR ISETPT.HOPR PV pMux->pPullUsr->isetptLo from MCOR ISETPT.LOPR PV pMux->pPullUsr->vsetptHi from MCOR VSETPT.HOPR PV pMux->pPullUsr->vsetptLo from MCOR VSETPT.LOPR PV pMux->pPullUsr->vsetptESLO from MCOR VSETPT.ESLO PV pMux->pPullUsr->vsetptEOFF from MCOR VSETPT.EOFF PV pMux->pPullUsr->vsetptASLO from MCOR VSETPT.ASLO PV pMux->pPullUsr->vsetptAOFF from MCOR VSETPT.AOFF PV pMux->pPullUsr->vsetptLINR from MCOR VSETPT.LINR PV Side: Depends on mux device name (name w attribute stripped off) to be stored in usr mem via mgntPauUsrGetMuxDeviceNameFromPV =============================================================================*/ static int mgntPauUsrGetFieldsFromPVs (mux_ts * pMux) { pullUsrData_ts *pData = (pullUsrData_ts*)pMux->pPullUsr; int32_t options = 0; int32_t nRequest = 1; /* these are for fetching Epics PV's */ if (dbGet(&(pData->isetptAddrHi), DBR_DOUBLE, &(pData->isetptHi), &options, &nRequest, NULL)) { return (-1); } if (dbGet(&(pData->isetptAddrLo), DBR_DOUBLE, &(pData->isetptLo), &options, &nRequest, NULL)) { return (-1); } if (dbGet(&(pData->vsetptAddrHi), DBR_DOUBLE, &(pData->vsetptHi), &options, &nRequest, NULL)) { return (-1); } if (dbGet(&(pData->vsetptAddrLo), DBR_DOUBLE, &(pData->vsetptLo), &options, &nRequest, NULL)) { return (-1); } if (dbGet(&(pData->i2vslopeAddr), DBR_DOUBLE, &(pData->i2vslope), &options, &nRequest, NULL)) { return (-1); } if (dbGet(&(pData->vsetptAddrESLO), DBR_DOUBLE, &(pData->vsetptESLO), &options, &nRequest, NULL)) { return (-1); } if (dbGet(&(pData->vsetptAddrEOFF), DBR_DOUBLE, &(pData->vsetptEOFF), &options, &nRequest, NULL)) { return (-1); } if (dbGet(&(pData->vsetptAddrASLO), DBR_DOUBLE, &(pData->vsetptASLO), &options, &nRequest, NULL)) { return (-1); } if (dbGet(&(pData->vsetptAddrAOFF), DBR_DOUBLE, &(pData->vsetptAOFF), &options, &nRequest, NULL)) { return (-1); } if (dbGet(&(pData->vsetptAddrLINR), DBR_ENUM, &(pData->vsetptLINR), &options, &nRequest, NULL)) { return (-1); } /* Note, the dbGet values in corresponding Init routine are not accurate since the Pvs are uninitialized */ /*DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrGetFieldsFromPVs: i2vslope=%f;\n\t isetptHi=%f; isetptLo=%f; vsetptHi=%f; vsetptLo=%f;\n\t dacchan=%f; daccard=%s;\n\t vsetptESLO=%f; vsetptEOFF= %f;\n\t vsetptASLO= %f;\n\t vsetptAOFF= %f;\n\t vsetptLINR= %hd\n", pData->i2vslope, pData->isetptHi,pData->isetptLo,pData->vsetptHi,pData->vsetptLo, pData->dacchan,(char *)pData->daccard_ca, pData->vsetptESLO,pData->vsetptEOFF, pData->vsetptASLO,pData->vsetptAOFF, pData->vsetptLINR ));*/ return 0; } /*============================================================================= Name: mgntPauUsrGetPolysFromPV Abs: This function reads the associated MUX device's polynomial PV waveform addr and stores to memory so that the polys can be read from memory every usr Pull function. The polys are used in the B to I conversion algorithm The PV addr is read once upon init by mgntPauUsrPullInit function. Args: mux_ts * pointer to mux Rem: Stores, in Usr Pull memory: pData->pwfAddr from mux device's IVB waveform PV Side: Make sure this is called after PINI of record processing Ret: none =============================================================================*/ static int mgntPauUsrGetPolysFromPVInit (mux_ts * pMux) { pullUsrData_ts * pData =(pullUsrData_ts *)pMux->pPullUsr; char pvname_ca[PVNAME_MAX]; DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrGetPolysFromPV: device name = %s\n", (char *)pMux->device)); sprintf (pvname_ca, "%s:IVB",pMux->device ); DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrGetPolysFromPVInit: IVB name = %s\n", (char *)pvname_ca)); if ( dbNameToAddr(pvname_ca, &(pData->pwfAddr))) { pData->pwfAddr.precord =NULL; /* keeps us from doing dbGet */ DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrGetPolysFromPV: dbNameToAddr of %s failed\n", (char *)pvname_ca)); epicsPrintf ("mgntPauUsrGetPolysFromPV: dbNameToAddr of %s failed\n", (char *)pvname_ca); return (-1); } else { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrGetPolysFromPVInit: dbNameToAddr of %s successful; ptr= %p\n", (char *)pvname_ca, pData->pwfAddr.pfield)); } return (0); } /*============================================================================= Name: mgntPauUsrGetPolysFromPV Abs: This function reads the associated MUX device's polynomials, to be used in the B to I conversion algorithm, and stores in MUX usr memory. Called every mgntPauUsrPull function; polys are read only after POLYCOEF rec's UDF = TRUE Args: mux_ts * pointer to mux Rem: Stores, in Usr Pull memory: pData->polyCoef[] from mux device's IVB waveform PV Side: Make sure this is called after PINI of record processing Ret: none =============================================================================*/ static int mgntPauUsrGetPolysFromPV (mux_ts * pMux) { pullUsrData_ts * pData =(pullUsrData_ts *)pMux->pPullUsr; waveformRecord *pwf=0; /* pointer to $(DEV):IVB waveform record */ double *pwfData; /* ptr to waveform data */ uint32_t i; int status = 0; int32_t options = 0; int32_t nRequest = 1; /* these are for dbGet Epics PV's */ /* read the polynomials out of the waveform and put into memory */ pwf = (waveformRecord *)pData->pwfAddr.precord; if (pwf==NULL) { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetPolysFromPV: precord NULL!\n")); return -1; /* this means dbNameToAddr failure */ } pwfData = (double *)pwf->bptr; pData->nelm = pwf->nelm; /* max number of data elements in record */ /*DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetPolysFromPV: nelm = %lu\n",pData->nelm));*/ if (pData->nelm ==0) { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetPolysFromPV: No polys yet!\n")); status = -1; } else { /* store polycoefs in pullUsrData struct */ for ( i = 0; i< pData->nelm; i++) { pData->polycoef[i] = pwfData[i]; /*DEBUGPRINT(DP_INFO, mgntPauUsrFlag,("mgntPauUsrGetPolysFromPV: polycoef[%lu] = %f\n", i, pData->polycoef[i]));*/ } } if (pData->i2vslope ==0.0) { if (dbGet(&(pData->i2vslopeAddr), DBR_DOUBLE, &(pData->i2vslope), &options, &nRequest, NULL)) { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag,("mgntPauUsrGetPolysFromPV: i2vslope zero!\n")); return (-1); } } return status; } /*============================================================================= Name: mgntPauUsrPullInitFcom Abs: The function initializes FCOM processing for each MUX/device via iocInit Args: mux_ts * pointer to mux Rem: Called once, upon init, by the mgntPauUsrPullInit function registered for each MUX/device to set up fcom subscribtion Side: Ret: none =============================================================================*/ static void mgntPauUsrPullInitFcom (mux_ts * pMux) { int status = 0; /*FcomID fcomId = 0;*/ pullUsrData_ts * pData = (pullUsrData_ts*)pMux->pPullUsr; /*char muxPVname_ca[PVNAME_MAX];*/ unsigned int dataslot; DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPullInitFcom reached! \n")); /* fcomInit moved to st.cmd */ for (dataslot=0; dataslot<4; dataslot++) { sprintf(pData->dataSlot[dataslot].pvname_ca, "%s:GETFCOM_%u", (const char *) getPVNameFromMux(pMux),dataslot ); DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPullInitFcom subscribing for PVname = %s! \n", (char *)pData->dataSlot[dataslot].pvname_ca )); pData->dataSlot[dataslot].fcomId = fcomLCLSPV2FcomID ((const char *) pData->dataSlot[dataslot].pvname_ca ); status = fcomSubscribe(pData->dataSlot[dataslot].fcomId, FCOM_ASYNC_GET ); if ( status ) { errlogPrintf("ERROR: %s\n", fcomStrerror(status)); DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrPullInitFcom: ERROR: %s\n", fcomStrerror(status))); pData->initPullBad = 1; } else DEBUGPRINT(DP_INFO, mgntPauUsrFlag, ("mgntPauUsrPullInitFcom successfuly subscribed for %s\n",(const char *)pData->dataSlot[dataslot].pvname_ca )); } return; } /*============================================================================= Name: mgntPauUsrPullInitMemory Abs: The function initializes pPullUsr pointer and then sets contents to zero. Args: mux_ts * pointer to mux Rem: Called once, upon init, by the mgntPauUsrPullInit function registered for each MUX/device Side: Ret: none =============================================================================*/ static int mgntPauUsrPullInitMemory (mux_ts * pMux) { int i; pullUsrData_ts * pData; /*DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPullInitMemory reached\n!!!"));*/ /* create space for the pullUsrData */ pData = (pullUsrData_ts *)calloc(sizeof(pullUsrData_ts),1); pMux->pPullUsr = (void *) pData; /* store reference in global var to report diagnostics to ioc shell */ ppullUsrData = (void *) pData; DEBUGPRINT(DP_WARN, mgntPauUsrFlag, ("mgntPauUsrPullInitMemory pData = %p\n ", (void *)pData)); DEBUGPRINT(DP_WARN, mgntPauUsrFlag, ("mgntPauUsrPullInitMemory ppullUsrData = %p\n ", (void *)ppullUsrData)); if (pData) { /* init all fields to zero */ DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPullInitMemory start zeroing...\n ")); pData->initPullBad=0; pData->getPVsBadCnt=0; for (i=0; ipolycoef[i] =0; /* array of polynomials */ pData->nelm=0; /* number of polynomials */ pData->i2vslope=0.0; /* I2VSLOPE PV calc output */ pData->bctrlHi=0.0; /* high val for dev BCTRL - not used */ pData->bctrlLo=0.0; /* low val for mcor BCTRL - not used */ pData->isetptHi=0.0; /* high val for mcor ISETPT*/ pData->isetptLo=0.0; /* low val for mcor ISETPT */ pData->vsetptHi=0.0; /* high val for mcor VSETPT*/ pData->vsetptLo=0.0; /* low val for mcor VSETPT */ pData->dacchan=0.0; /* dac chan # from mcor DACCHAN PV */ for (i=0;idataSlot[i].fcomId = 0; /* fcom ID corresponding to index GETFCOM_i */ pData->dataSlot[i].Bval = 0; /* B field desired value */ pData->dataSlot[i].Ival = 0; /* I raw calculated des value */ pData->dataSlot[i].Vval = 0; /* V calculated dac VSETPT */ pData->dataSlot[i].dacval = 0; /* converted raw val sent to dac */ pData->dataSlot[i].calcBadCnt= 0; /* status of calc'ed value */ pData->dataSlot[i].fcomBadCnt= 0; /* when not matched (active, current) PULSEID */ pData->dataSlot[i].fcomCnt = 0; pData->dataSlot[i].fcomExc1Cnt = 0; pData->dataSlot[i].fcomExc2Cnt = 0; } } else { pMux->pPullUsr = 0; DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrPullInitMemroy error calloc memory space\n")); return (-1); } DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPullInitMemory pData = returning\n ")); return 0; } /*============================================================================= Name: mgntPauUsrPullInit Abs: The function initializes PAU and FCOM processing for each MUX/device via iocInit Args: void * parg == mux_ts * pointer to mux Rem: Called once, upon init, by the mgntPauUsrPull function registered for each MUX/device. Side: Ret: none =============================================================================*/ static void mgntPauUsrPullInit(mux_ts *pMux) { pullUsrData_ts * pData; int status; pau_ts * pPau = pMux->pPau; epicsPrintf("mgntPauUsrPullInit: pau: (%s), mux: (%s), pvName: (%s) , its fbckMode: (%d), device: (%s)\n", pPau->name, pMux->name, getPVNameFromMux(pMux), pMux->fbckMode, pMux->device ); /* init the pullUsrData */ status = mgntPauUsrPullInitMemory (pMux); if (status != 0) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrPullInit error getting/setting usr pull memory\n")); return; } /* init pData because mgntPauUsrPullInitMemory created it */ pData = (pullUsrData_ts*)pMux->pPullUsr; /* init fcom fcomid and subscription */ mgntPauUsrPullInitFcom (pMux); DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPullInit calling mgntPauUsrGetPolysFromPVInit \n!!!")); /* Now read poly coefs belonging to this device into our pull memory */ status = mgntPauUsrGetPolysFromPVInit (pMux); if (status) { errlogPrintf("mgntPauUsrPullInit error getting polys"); DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrPullInit error getting polys")); pData->initPullBad = 1; } else DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrPullInit finished setting up POLYCOEF dbaddr\n")); status = mgntPauUsrGetFieldsFromPVsInit (pMux); if (status) { pData->initPullBad = 1; errlogPrintf("mgntPauUsrPullInit error getting MCOR configs"); DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntPauUsrPullInit error getting MCOR configs")); } return; } /*============================================================================= Name: mgntPauUsrPull Abs: The function .. for each MUX/device Args: void * parg == mux_ts * pointer to mux unsigned char initFlag (set to true on first call from iocInit) Rem: Called once, upon init, by the mgntPauUsrPull function registered for each MUX/device. Side: Reference /afs/slac/g/lcls/epics/iocTop/llrfLab/FFTestStation/Llrf4-R1-2-0/llrf4App/src/l1sDataProc.c Note: the mux API of getDataFromDataSlot() returns either the PV value or FCOM value depending on the state of the MUX:*:FBCK PV. Ret: none =============================================================================*/ static void mgntPauUsrPull (void *parg, unsigned char initFlag) { mux_ts *pMux; muxDebugInfo_ts *pMuxDebugInfo; FcomBlob *pblob = 0; /* init to 0 in case this is not fcom; only patt aware */ pullUsrData_ts *pData; int status = 0; int slot = 0; pMux = (mux_ts *)parg; pMuxDebugInfo = pMux->pMuxDebugInfo; pau_ts *pPau = pMux->pPau; pData = (pullUsrData_ts*)pMux->pPullUsr; if(initFlag) return mgntPauUsrPullInit((void *) pMux); pMuxDebugInfo->usrPullCounter++; /* increase counter for debugging */ if (pPau->activateUsrPull ==0) { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPull exiting cuz activateUsrPull==0 !\n")); return; } if (pData->initPullBad){ DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPull exiting cuz initPullBad ==0 !\n")); return; } /* Now read poly coefs belonging to this device into our pull memory */ /* if POLYCOEF rec is UDF, just return until it is processed */ status = mgntPauUsrGetPolysFromPV (pMux); if (status != 0) { pData->getPVsBadCnt++; DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPull error in reading POLYCOEF fields !\n")); return; } /* Now read the drvl, drvh for I and V; also VSETPT ESLO,EOFF,ASLO,AOFF and LINR for calcs */ status = mgntPauUsrGetFieldsFromPVs(pMux); if (status != 0) { pData->getPVsBadCnt++; DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPull error in reading Fields from ISETPT, VSETPT PVs!\n")); return; } slot = pPau->current.matchedDataSlot; if(slot>=0 && slot <4) { /* added by Kukhee */ /* no need to check to see if fbck mode prior to contacting fcom */ /* if (pMux->fbckMode) { */ /* get data from cache, where pData = FcomID */ /* access the correct data slot for matched pattern */ status = fcomGetBlob(pData->dataSlot[slot].fcomId, &pblob,FCOM_ASYNC_GET ); /* if successful, or if fcom is running, verify header,etc */ if (!status && pblob) { status = pauVerifyPulseIdFcomBlob(pblob, pMux); /* update Fcom slot in PAU with the data received by Fcom */ if (status >=0) { /* not fatal */ /* will want to store into slot according to callback index */ /* release blob if valid pointer after setting value to fcom data slot */ setDataToFcomDataSlot(pMux, (double)*pblob->fc_mgnt_Bval); pData->dataSlot[slot].fcomCnt++; if (status) /* Pulse ID mismatch */ pData->dataSlot[slot].fcomBadCnt++; } else { /* exeption: not healthy - fcom communications error */ pData->dataSlot[slot].fcomExc1Cnt++; } fcomReleaseBlob(&pblob); } else {/* version mismatch; no blob returned */ pData->dataSlot[slot].fcomExc2Cnt++; } } /* added by Kukhee */ /* now process the data, whether retrieved from fcom or pv */ /* note, if fcom data was bad, it wasn't written */ slot = pPau->advance.matchedDataSlot; if(slot>=0 && slot<4) { /* added by Kukhee */ /* tests pMux->fbckMode to determine return of fcom value or static value */ pData->dataSlot[slot].Bval = getDataFromDataSlot_vMux(pMux); DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, (" getDataFromDataSlot=%f\n", pData->dataSlot[slot].Bval )); status = mgntCalcBtoI(pMux, slot); if (status==0){ status = mgntCalcItoV(pMux, slot); mgntsetDAC(pMux, slot); } else DEBUGPRINT(DP_INFO, mgntPauUsrFlag, ("didn't mgntCalcItoV\n" )); } /* added by Kukhee */ return; } /*============================================================================= Name: mgntCalcBtoI Abs: based on mux usr memory poly values and B val, calculates the voltage Args: mux_ts * pointer to mux Rem: Called to calculate I current, given B val either from fcom or PVs Side: used mgntDbPoly logic Output: ------- K = Value in Raw Units L = Slope of the polynomial at the DES value Input: B = Number of polynomial coefficients C = Polynomial Coeff A (offset if linear) D = Polynomial Coeff B (slope if linear) VAL = Value in B Ret: sets status = 0 success status = -1 error =============================================================================*/ static int mgntCalcBtoI(mux_ts * pMux, int slot) { int idx =0; double slope = 0.0; pullUsrData_ts *pData = (pullUsrData_ts*)pMux->pPullUsr; uint32_t nelm = pData->nelm; /* use polycoefs from pull usr data */ if (nelm ==LINEAR_COEF_NUM) { /* simple linear conversion */ /* val = offset,in poly[0] + (slope * Bval) */ pData->dataSlot[slot].Ival = pData->polycoef[0] + (pData->dataSlot[slot].Bval * pData->polycoef[1]); } else if ((pData->nelm < LINEAR_COEF_NUM) || (pData->nelm > MGNT_MAX_POLY_COEF)){ DEBUGPRINT(DP_INFO, mgntPauUsrFlag, ("mgntCalcBtoI for %s: Invalid poly coef.\n",pMux->name)); pData->dataSlot[slot].calcBadCnt++; return -1; } else { /* * Do polynomial conversion using algorithm from ref_rmx_dbs:dbpoly.a38. * which then got translated into mgntDbPoly * Find first derivative of the polynomial at the input value - * it'll be used to find reasonable alarm limits later. */ pData->dataSlot[slot].Ival = 0.0; slope = 0.0; for (idx = nelm-1; idx >=0; idx--) { slope = (slope * pData->dataSlot[slot].Bval) + pData->dataSlot[slot].Ival; pData->dataSlot[slot].Ival = ( pData->dataSlot[slot].Ival * pData->dataSlot[slot].Bval) + (pData->polycoef[idx]); } } /* check for upper and lower limits - clip if necessary */ if (pData->dataSlot[slot].Ival > pData->isetptHi) pData->dataSlot[slot].Ival = pData->isetptHi; if (pData->dataSlot[slot].Ival < pData->isetptLo) pData->dataSlot[slot].Ival = pData->isetptLo; return 0; } /*============================================================================= Name: mgntCalcItoV Abs: Given raw I current value, calculate the VSETPT, store in usr mux memory for output during the mgntPauUsrPush callback Args: vmux_ts * pointer to mux Rem: Side: Ret: sets status = 0 success status = -1 error =============================================================================*/ static int mgntCalcItoV(mux_ts * pMux, int slot) { int status = 0; pullUsrData_ts * pData = (pullUsrData_ts*)pMux->pPullUsr; /* Assume the offset value - PV VSETPTCALC INPB is 0 */ if ((pData->dataSlot[slot].Ival==0.0) || (pData->i2vslope==0.0) ) { status = -1; pData->dataSlot[slot].calcBadCnt++; } if (pData->i2vslope==0.0) { DEBUGPRINT(DP_ERROR, mgntPauUsrFlag, ("mgntCalcItoV for %s: Invalid Ival=%f or i2vslope=%f; Vval clipped\n", pMux->name, pData->dataSlot[slot].Ival, pData->i2vslope )); } pData->dataSlot[slot].Vval = pData->dataSlot[slot].Ival * pData->i2vslope; /* check for upper and lower limits - clip if necessary */ if (pData->vsetptHi > pData->vsetptLo) { if (pData->dataSlot[slot].Vval > pData->vsetptHi) pData->dataSlot[slot].Vval = pData->vsetptHi; else if (pData->dataSlot[slot].Vval < pData->vsetptLo) pData->dataSlot[slot].Vval = pData->vsetptLo; } /* do the aoRecord linear conversion from volts to dac counts */ if ((pData->vsetptLINR == menuConvertLINEAR) || (pData->vsetptLINR == menuConvertSLOPE)) { if (pData->vsetptESLO!=0.0) pData->dataSlot[slot].Vval = (pData->dataSlot[slot].Vval - pData->vsetptEOFF) / (pData->vsetptESLO); else pData->dataSlot[slot].Vval = 0.0; } pData->dataSlot[slot].Vval -= pData->vsetptAOFF; if (pData->vsetptASLO!=0.0) pData->dataSlot[slot].Vval /= pData->vsetptASLO; /* do the aoRecord value to raw value stuff */ if (pData->dataSlot[slot].Vval >=0.0) pData->dataSlot[slot].dacval = pData->dataSlot[slot].Vval + 0.5; else pData->dataSlot[slot].dacval = pData->dataSlot[slot].Vval - 0.5; return status; } /*============================================================================= Name: mgntsetDAC Abs: The function initializes PAU and FCOM processing for each MUX/device via iocInit Args: mux_ts * pointer to mux Rem: Writes DAC via ip231 API: ip231Write (IP231_ID pcard, UINT16 channel, signed int value) Side: Ret: from drvIP231Lib.h : #include "ptypes.h" typedef struct IP231_CARD * IP231_ID; int ip231Create (char *cardname, UINT16 carrier, UINT16 slot, char *dacmode); IP231_ID ip231GetByName(char * cardname); IP231_ID ip231GetByLocation(UINT16 carrier, UINT16 slot); int ip231Write(IP231_ID pcard, UINT16 channel, signed int value); int ip231Read(IP231_ID pcard, UINT16 channel, signed int * pvalue); void ip231SimulTrigger(IP231_ID pcard); void ip231SimulTriggerByName(char * cardname); =============================================================================*/ static int mgntsetDAC(mux_ts * pMux, int slot) { int status = 0; pullUsrData_ts * pData = (pullUsrData_ts*)pMux->pPullUsr; ip231Write ( pData->pcard, (UINT16)pData->dacchan, (signed int) pData->dataSlot[slot].dacval); DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntsetDac: Writing Vval=%f; dacval=%d, (Bval = %f; Ival=%f) to daccard=%s for MCOR dev=%s, device=%s\n", pData->dataSlot[slot].Vval, pData->dataSlot[slot].dacval, pData->dataSlot[slot].Bval, pData->dataSlot[slot].Ival, (char *)pData->daccard_ca, (char *)pData->mcorDevice_ca, (char *)pMux->device )); return status; } /*============================================================================= Name: mgntPauUsrPush Abs: The function .. for each MUX/device Args: void * parg == mux_ts * pointer to mux unsigned char initFlag (set to true on first call from iocInit) Since all init is done via mgntPauUsrPull routine, simply return if initFlag is set. Rem: Relies on mgntPauUsrPullInit routine to set up all needed fields in pMux->pPullUsr memory Side: Ret: none =============================================================================*/ static void mgntPauUsrPush(void *parg, unsigned char initFlag) { mux_ts *pMux = (mux_ts *)parg; muxDebugInfo_ts *pMuxDebugInfo = pMux->pMuxDebugInfo; /*pullUsrData_ts * pData = (pullUsrData_ts*)pMux->pPullUsr;*/ pau_ts *pPau = (pau_ts *) pMux->pPau; /* all initialization (fcomID) is done in the mgntPauUsrPullInit */ if(initFlag) { mgntPauUsrPushInit(pMux); return; } if (pPau->activateUsrPush ==0) { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPush exiting cuz activateUsrPush==0 !\n")); return; } pMuxDebugInfo->usrPushCounter++; /* increase counter for debugging */ /* read from MUX - this function tests whether in fbck mode or not */ /* in order to get the value from staticData or fcomData */ } /*============================================================================= Name: mgntPauUsrPushInit Abs: The function initializes PAU and FCOM processing for each MUX/device via iocInit Args: void * parg == mux_ts * pointer to mux mdefAddr_as[md].CTRL_ Rem: Called once, upon init, by the mgntPauUsrPull function registered for each MUX/device. Side: Ret: none =============================================================================*/ static void mgntPauUsrPushInit( mux_ts *pMux ) { pau_ts *pPau = pMux->pPau; pullUsrData_ts * pData = (pullUsrData_ts*)pMux->pPullUsr; if (pData) { DEBUGPRINT(DP_DEBUG, mgntPauUsrFlag, ("mgntPauUsrPushInit reached!!!")); epicsPrintf("mgntPauUsrPushInit: pau: (%s), mux: (%s), pvName: (%s) , fbckMode: (%d), device: (%s)\n", pPau->name, pMux->name, getPVNameFromMux(pMux), pPau->fbckMode, pMux->device ); } return; } epicsRegisterFunction(mgntPauUsrPull); epicsRegisterFunction(mgntPauUsrPush);