#include #include #include #include #include #include #include #include "drvPadDataProc.h" #include "devPadDataProc.h" #include "drvLlrf.h" #include "drvPacComm.h" #define PHASE_DONE 0x01 #define AMPL_DONE 0x10 #define S30 "S30" #define MUXNAME_S30_PDES "ACCL:LI30:0:KLY_PDES" #define MUXNAME_S30_ADES "ACCL:LI30:0:KLY_ADES" typedef struct { char fcomPVName_pdes[40]; FcomID fcomId_pdes; int f_fcomSubs_pdes; unsigned int fcomCnt_pdes; unsigned int fcomBadCnt_pdes; unsigned int fcomExc1Cnt_pdes; unsigned int fcomExc2Cnt_pdes; double prev_pdes; double pdes; double pset2856; double pset; short iset; short qset; double phase_offset; } pullPhaseUsrData_t, pushPhaseUsrData_t; typedef struct { void *pStation; void *pData; unsigned char done; double phase_offset; double i_scale, q_scale; unsigned short iq_send; } pullPhaseUsr_t, pushPhaseUsr_t; typedef struct { char fcomPVName_ades[40]; FcomID fcomId_ades; int f_fcomSubs_ades; unsigned int fcomCnt_ades; unsigned int fcomBadCnt_ades; unsigned int fcomExc1Cnt_ades; unsigned int fcomExc2Cnt_ades; double prev_ades; double ades; double aset; } pullAmplUsrData_t, pushAmplUsrData_t; typedef struct { void *pStation; void *pData; unsigned char done; } pullAmplUsr_t, pushAmplUsr_t; static void devAddPhaseParam(pushPhaseUsr_t *pUsr) { pushPhaseUsrData_t *pData = pUsr->pData; int i; char str[16]; for(i=0; i<4; i++){ sprintf(str, "FCOMPV_PDES_DS%d", i); addDevParam(S30, str, (pData+i)->fcomPVName_pdes, STRING); /* don't init. here */ sprintf(str, "FCOMID_PDES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomId_pdes, HEX32); /* don't init. here */ sprintf(str, "FCOMST_PDES_DS%d", i); addDevParam(S30, str, &(pData+i)->f_fcomSubs_pdes, HEX32); /* don't init. here */ sprintf(str, "FCOMC_PDES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomCnt_pdes, UINT); (pData+i)->fcomCnt_pdes = 0; sprintf(str, "FCOMBC_PDES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomBadCnt_pdes, UINT); (pData+i)->fcomBadCnt_pdes = 0; sprintf(str, "FCOME1_PDES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomExc1Cnt_pdes, UINT); (pData+i)->fcomExc1Cnt_pdes = 0; sprintf(str, "FCOME2_PDES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomExc2Cnt_pdes, UINT); (pData+i)->fcomExc2Cnt_pdes = 0; sprintf(str, "PREV_PDES_DS%d", i); addDevParam(S30, str, &(pData+i)->prev_pdes, DOUBLE); (pData+i)->prev_pdes = 0.; sprintf(str, "PDES_DS%d", i); addDevParam(S30, str, &(pData+i)->pdes, DOUBLE); (pData+i)->pdes = 0.; sprintf(str, "PSET2856_DS%d", i); addDevParam(S30, str, &(pData+i)->pset2856, DOUBLE); (pData+i)->pset2856 = 0.; sprintf(str, "PSET_DS%d", i); addDevParam(S30, str, &(pData+i)->pset, DOUBLE); (pData+i)->pset = 0.; sprintf(str, "ISET_DS%d", i); addDevParam(S30, str, &(pData+i)->iset, SHORT); (pData+i)->iset = 0; sprintf(str, "QSET_DS%d", i); addDevParam(S30, str, &(pData+i)->qset, SHORT); (pData+i)->qset = 0; sprintf(str, "POFFSET_DS%d", i); addDevParam(S30, str, &(pData+i)->phase_offset, DOUBLE); (pData+i)->phase_offset = 0.; } addDevParam(S30, POFFSET, &pUsr->phase_offset, DOUBLE); pUsr->phase_offset = 0.; addDevParam(S30, ISCALE, &pUsr->i_scale, DOUBLE); pUsr->i_scale = 0.; addDevParam(S30, QSCALE, &pUsr->q_scale, DOUBLE); pUsr->q_scale = 0.; addDevParam(S30, IQ_SEND, &pUsr->iq_send, USHORT); pUsr->iq_send = 1; } static void devAddAmplParam(pushAmplUsr_t *pUsr) { pushAmplUsrData_t *pData = pUsr->pData; int i; char str[16]; for(i=0; i<4; i++) { sprintf(str, "FCOMPV_ADES_DS%d", i); addDevParam(S30, str, (pData+i)->fcomPVName_ades, STRING); /* don't init. here */ sprintf(str, "FCOMID_ADES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomId_ades, HEX32); /* don't init. here */ sprintf(str, "FCOMST_ADES_DS%d", i); addDevParam(S30, str, &(pData+i)->f_fcomSubs_ades, HEX32); /* don't init. here */ sprintf(str, "FCOMC_ADES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomCnt_ades, UINT); (pData+i)->fcomCnt_ades = 0; sprintf(str, "FCOMBC_ADES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomBadCnt_ades, UINT); (pData+i)->fcomBadCnt_ades = 0; sprintf(str, "FCOME1_ADES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomExc1Cnt_ades, UINT); (pData+i)->fcomExc1Cnt_ades = 0; sprintf(str, "FCOME2_ADES_DS%d", i); addDevParam(S30, str, &(pData+i)->fcomExc2Cnt_ades, UINT); (pData+i)->fcomExc2Cnt_ades = 0; sprintf(str, "PREV_ADES_DS%d", i); addDevParam(S30, str, &(pData+i)->prev_ades, DOUBLE); (pData+i)->prev_ades = 0.; sprintf(str, "ADES_DS%d", i); addDevParam(S30, str, &(pData+i)->ades, DOUBLE); (pData+i)->ades = 0.; sprintf(str, "ASET_DS%d", i); addDevParam(S30, str, &(pData+i)->aset, DOUBLE); (pData+i)->aset = 0.; } } #include "ap2iqConversion.c" static void s30PhasePullInit(void *parg) { mux_ts *pMux = (mux_ts *) parg; mux_ts *pAssociation = (mux_ts *) pMux->pAssociation; pau_ts *pPau = pMux->pPau; int i; if(pMux->pPushUsr) { pMux->pPullUsr = pMux->pPushUsr; return; } pullPhaseUsr_t *pPullPhaseUsr = mallocMustSucceed(sizeof(pullPhaseUsr_t), "s30PhasePull"); pullPhaseUsrData_t *pPullPhaseUsrData = mallocMustSucceed(sizeof(pullPhaseUsrData_t)*MAXNUM_DATASLOTS, "s30PhasePull"); for(i=0; i<4; i++) { makeFcomPVNamewithSlotNumber(/* pMux->name */ MUXNAME_S30_PDES, (pPullPhaseUsrData+i)->fcomPVName_pdes, i); (pPullPhaseUsrData+i)->fcomId_pdes = fcomLCLSPV2FcomID((pPullPhaseUsrData+i)->fcomPVName_pdes); if((pPullPhaseUsrData+i)->fcomId_pdes) (pPullPhaseUsrData+i)->f_fcomSubs_pdes = fcomSubscribe((pPullPhaseUsrData+i)->fcomId_pdes, FCOM_ASYNC_GET); else (pPullPhaseUsrData+i)->f_fcomSubs_pdes = -1; } pPullPhaseUsr->pStation = (void*) NULL; pPullPhaseUsr->pData = (void*) pPullPhaseUsrData; pPullPhaseUsr->done = 0x00; pMux->pPullUsr = pPullPhaseUsr; devAddPhaseParam(pPullPhaseUsr); } static void s30PhasePull(void *parg, unsigned initFlag) { unsigned int dataSlot; mux_ts *pMux = (mux_ts *) parg; muxDebugInfo_ts *pMuxDebugInfo = pMux->pMuxDebugInfo; mux_ts *pAssociation = (mux_ts *) pMux->pAssociation; pau_ts *pPau = pMux->pPau; FcomBlob *pBlob; int status; pullPhaseUsr_t *pPullPhaseUsr; pullPhaseUsrData_t *pPullPhaseUsrData; if(initFlag) return s30PhasePullInit((void *) pMux); pMuxDebugInfo->usrPullCounter++; if(!pMux->pPullUsr) return; /* nothing to do */ pPullPhaseUsr = pMux->pPullUsr; pPullPhaseUsrData = pPullPhaseUsr->pData; dataSlot = pPau->current.matchedDataSlot; if((pPullPhaseUsrData+dataSlot)->fcomId_pdes && !(pPullPhaseUsrData+dataSlot)->f_fcomSubs_pdes) { status = fcomGetBlob((pPullPhaseUsrData+dataSlot)->fcomId_pdes, &pBlob, FCOM_ASYNC_GET); if(!status && pBlob) { status = pauVerifyPulseIdFcomBlob(pBlob, pMux); if(status>=0) { /* not fatal */ setDataToFcomDataSlot(pMux, *(pBlob->fc_dbl)); (pPullPhaseUsrData+dataSlot)->fcomCnt_pdes++; if(status) (pPullPhaseUsrData+dataSlot)->fcomBadCnt_pdes++; } else { /* exception: not healthy */ (pPullPhaseUsrData+dataSlot)->fcomExc1Cnt_pdes++; } fcomReleaseBlob(&pBlob); } else { /* exception: no blop */ (pPullPhaseUsrData+dataSlot)->fcomExc2Cnt_pdes++; } } /* actually nothing todo */ } static void s30PhasePushInit(void *parg) { mux_ts *pMux = (mux_ts*) parg; mux_ts *pAssociation = (mux_ts*) pMux->pAssociation; pau_ts *pPau = pMux->pPau; int i; if(pMux->pPullUsr) { pMux->pPushUsr = pMux->pPullUsr; return; } pushPhaseUsr_t *pPushPhaseUsr = mallocMustSucceed(sizeof(pushPhaseUsr_t), "s30PhasePush"); pushPhaseUsrData_t *pPushPhaseUsrData = mallocMustSucceed(sizeof(pushPhaseUsrData_t)*MAXNUM_DATASLOTS, "s30PhasePush"); for(i=0; i<4; i++) { makeFcomPVNamewithSlotNumber(/*pMux->name */ MUXNAME_S30_PDES, (pPushPhaseUsrData+i)->fcomPVName_pdes, i); (pPushPhaseUsrData+i)->fcomId_pdes = fcomLCLSPV2FcomID((pPushPhaseUsrData+i)->fcomPVName_pdes); if((pPushPhaseUsrData+i)->fcomId_pdes) (pPushPhaseUsrData+i)->f_fcomSubs_pdes = fcomSubscribe((pPushPhaseUsrData+i)->fcomId_pdes, FCOM_ASYNC_GET); else (pPushPhaseUsrData+i)->f_fcomSubs_pdes = -1; } pPushPhaseUsr->pStation = (void*) NULL; pPushPhaseUsr->pData = (void*) pPushPhaseUsrData; pPushPhaseUsr->done = 0x00; pMux->pPushUsr = pPushPhaseUsr; devAddPhaseParam(pPushPhaseUsr); } static void s30PhasePush(void *parg, unsigned initFlag) { unsigned int dataSlot; mux_ts *pMux = (mux_ts *) parg; muxDebugInfo_ts *pMuxDebugInfo = pMux->pMuxDebugInfo; mux_ts *pAssociation = (mux_ts *) pMux->pAssociation; pau_ts *pPau = pMux->pPau; pushPhaseUsr_t *pPushPhaseUsr; pushPhaseUsrData_t *pPushPhaseUsrData; if(initFlag) return s30PhasePushInit((void*) pMux); pMuxDebugInfo->usrPushCounter++; if(!pMux->pPushUsr) return; /* nothing to do */ pPushPhaseUsr = pMux->pPushUsr; pPushPhaseUsrData = pPushPhaseUsr->pData; dataSlot = pPau->advance.matchedDataSlot; (pPushPhaseUsrData+dataSlot)->pdes = getDataFromDataSlot_vMux(pMux); if(!pMux->fbckMode) (pPushPhaseUsrData+dataSlot)->pset2856 = (pPushPhaseUsrData+dataSlot)->pdes + pPushPhaseUsr->phase_offset; else (pPushPhaseUsrData+dataSlot)->pset2856 = (pPushPhaseUsrData+dataSlot)->pdes + (pPushPhaseUsrData+dataSlot)->phase_offset; (pPushPhaseUsrData+dataSlot)->pset = (pPushPhaseUsrData+dataSlot)->pset2856 / 6.; pPushPhaseUsr->done |= PHASE_DONE; if(pPushPhaseUsr->done && ((pushAmplUsr_t*)pAssociation->pPushUsr)->done) { pPushPhaseUsr->done = 0; ((pushAmplUsr_t*)pAssociation->pPushUsr)->done = 0; ap2iqConversion(dataSlot, pPushPhaseUsr, (pushAmplUsr_t*) pAssociation->pPushUsr); setIQ(LLRF_S30, dataSlot, pPushPhaseUsr, (pushAmplUsr_t*) pAssociation->pPushUsr); if(!ellNext(&pMux->node)) pacCommSendPacket(); } } static void s30AmplPullInit(void *parg) { mux_ts *pMux = (mux_ts *)parg; mux_ts *pAssociation = (mux_ts *) pMux->pAssociation; pau_ts *pPau = pMux->pPau; int i; if(pMux->pPushUsr) { pMux->pPullUsr = pMux->pPushUsr; return; } pullAmplUsr_t *pPullAmplUsr = mallocMustSucceed(sizeof(pullAmplUsr_t), "s30AmplPull"); pullAmplUsrData_t *pPullAmplUsrData = mallocMustSucceed(sizeof(pullAmplUsrData_t)*MAXNUM_DATASLOTS, "s30AmplPull"); for(i=0; i<4; i++) { makeFcomPVNamewithSlotNumber(/* pMux->name */ MUXNAME_S30_ADES, (pPullAmplUsrData+i)->fcomPVName_ades, i); (pPullAmplUsrData+i)->fcomId_ades = fcomLCLSPV2FcomID((pPullAmplUsrData+i)->fcomPVName_ades); if((pPullAmplUsrData+i)->fcomId_ades) (pPullAmplUsrData+i)->f_fcomSubs_ades = fcomSubscribe((pPullAmplUsrData+i)->fcomId_ades, FCOM_ASYNC_GET); else (pPullAmplUsrData+i)->f_fcomSubs_ades = -1; } pPullAmplUsr->pStation = (void *) NULL; pPullAmplUsr->pData = (void *) pPullAmplUsrData; pPullAmplUsr->done = 0x00; pMux->pPullUsr = pPullAmplUsr; devAddAmplParam(pPullAmplUsr); } static void s30AmplPull(void *parg, unsigned initFlag) { unsigned int dataSlot; mux_ts *pMux = (mux_ts *) parg; muxDebugInfo_ts *pMuxDebugInfo = pMux->pMuxDebugInfo; mux_ts *pAssociation = (mux_ts *)pMux->pAssociation; pau_ts *pPau = pMux->pPau; FcomBlob *pBlob; int status; pullAmplUsr_t *pPullAmplUsr; pullAmplUsrData_t *pPullAmplUsrData; if(initFlag) return s30AmplPullInit((void*) pMux); pMuxDebugInfo->usrPullCounter++; if(!pMux->pPullUsr) return; /* nothing to do */ pPullAmplUsr = pMux->pPullUsr; pPullAmplUsrData = pPullAmplUsr->pData; dataSlot = pPau->current.matchedDataSlot; if((pPullAmplUsrData+dataSlot)->fcomId_ades && !(pPullAmplUsrData+dataSlot)->f_fcomSubs_ades) { status = fcomGetBlob((pPullAmplUsrData+dataSlot)->fcomId_ades, &pBlob, FCOM_ASYNC_GET); if(!status && pBlob) { status = pauVerifyPulseIdFcomBlob(pBlob, pMux); if(status>=0) { /* not fatal */ setDataToFcomDataSlot(pMux, *(pBlob->fc_dbl)); (pPullAmplUsrData+dataSlot)->fcomCnt_ades++; if(status) (pPullAmplUsrData+dataSlot)->fcomBadCnt_ades++; } else { /* exception: not healthy */ (pPullAmplUsrData+dataSlot)->fcomExc1Cnt_ades++; } fcomReleaseBlob(&pBlob); } else { /* exception: no blop */ (pPullAmplUsrData+dataSlot)->fcomExc2Cnt_ades++; } } /* Actually, nothing to do */ } static void s30AmplPushInit(void *parg) { mux_ts *pMux = (mux_ts *) parg; mux_ts *pAssociation = (mux_ts *) pMux->pAssociation; pau_ts *pPau = pMux->pPau; int i; if(pMux->pPullUsr) { pMux->pPushUsr = pMux->pPullUsr; return; } pushAmplUsr_t *pPushAmplUsr = mallocMustSucceed(sizeof(pushAmplUsr_t), "s30AmplPush"); pushAmplUsrData_t *pPushAmplUsrData = mallocMustSucceed(sizeof(pushAmplUsrData_t)*MAXNUM_DATASLOTS, "s30AmplPush"); for(i=0; i<4; i++) { makeFcomPVNamewithSlotNumber(/* pMux->name */ MUXNAME_S30_ADES, (pPushAmplUsrData+i)->fcomPVName_ades, i); (pPushAmplUsrData+i)->fcomId_ades = fcomLCLSPV2FcomID((pPushAmplUsrData+i)->fcomPVName_ades); if((pPushAmplUsrData+i)->fcomId_ades) (pPushAmplUsrData+i)->f_fcomSubs_ades = fcomSubscribe((pPushAmplUsrData+i)->fcomId_ades, FCOM_ASYNC_GET); else (pPushAmplUsrData+i)->f_fcomSubs_ades = -1; } pPushAmplUsr->pStation = (void *) NULL; pPushAmplUsr->pData = (void*) pPushAmplUsrData; pPushAmplUsr->done = 0x00; pMux->pPushUsr = pPushAmplUsr; devAddAmplParam(pPushAmplUsr); } static void s30AmplPush(void *parg, unsigned initFlag) { unsigned int dataSlot; mux_ts *pMux = (mux_ts *) parg; muxDebugInfo_ts *pMuxDebugInfo = pMux->pMuxDebugInfo; mux_ts *pAssociation = (mux_ts*) pMux->pAssociation; pau_ts *pPau = pMux->pPau; pushAmplUsr_t *pPushAmplUsr; pushAmplUsrData_t *pPushAmplUsrData; if(initFlag) return s30AmplPushInit((void*) pMux); pMuxDebugInfo->usrPushCounter++; if(!pMux->pPushUsr) return; /* nothing to do */ pPushAmplUsr = pMux->pPushUsr; pPushAmplUsrData = pPushAmplUsr->pData; dataSlot = pPau->advance.matchedDataSlot; (pPushAmplUsrData+dataSlot)->ades = getDataFromDataSlot_vMux(pMux); (pPushAmplUsrData+dataSlot)->aset = (pPushAmplUsrData+dataSlot)->ades; pPushAmplUsr->done |= AMPL_DONE; if(((pushPhaseUsr_t*)pAssociation->pPushUsr)->done && pPushAmplUsr->done) { ((pushPhaseUsr_t*)pAssociation->pPushUsr)->done = 0; pPushAmplUsr->done = 0; ap2iqConversion(dataSlot, (pushPhaseUsr_t*) pAssociation->pPushUsr, pPushAmplUsr); setIQ(LLRF_S30, dataSlot, (pushPhaseUsr_t*) pAssociation->pPushUsr, pPushAmplUsr); if(!ellNext(&pMux->node)) pacCommSendPacket(); } } void s30PhaseResync(char *muxName) { pau_ts *pPau; mux_ts *pMux; dataSlot_ts *pdataSlot; pushPhaseUsr_t *pUsr; pushPhaseUsrData_t *pData; int i; pMux = findMuxwithOnlyName(muxName); if(!pMux) { printf("Could not find the mux (%s)\n", muxName); return; } pPau = pMux->pPau; pUsr = pMux->pPushUsr; pData = pUsr->pData; pdataSlot = pMux->dataSlot; for(i=0; i<4 ;i++) { (pData+i)->phase_offset = pUsr->phase_offset; (pdataSlot+i)->fcomData = (pdataSlot+i)->staticData; } } void s30AmplitudeResync(char *muxName) { pau_ts *pPau; mux_ts *pMux; dataSlot_ts *pdataSlot; pushAmplUsr_t *pUsr; pushAmplUsrData_t *pData; int i; pMux = findMuxwithOnlyName(muxName); if(!pMux) { printf("Could not find the mux (%s)\n", muxName); return; } pPau = pMux->pPau; pUsr = pMux->pPushUsr; pData = pUsr->pData; pdataSlot = pMux->dataSlot; for(i=0; i<4; i++) { (pdataSlot+i)->fcomData = (pdataSlot+i)->staticData; } } epicsRegisterFunction(s30PhasePull); epicsRegisterFunction(s30PhasePush); epicsRegisterFunction(s30AmplPull); epicsRegisterFunction(s30AmplPush);