#ifndef CP_BPM_H #define CP_BPM_H #include #include #define CAV_NUM_DETS 6 #undef CPDEBUG class CPDigiBpm { private: CPUtil util_; void mapArrayLimHelper_(StringRegMap *map, Path path, char *parmstr, char *prefstr, int i, double scale, int size) { char pathstr[MAX_KEY_LENGTH]; char keystr[MAX_KEY_LENGTH]; sprintf( keystr, "%s[%d]", parmstr, i ); sprintf( pathstr, "%s[%d]/%s", prefstr, i, parmstr ); // Restrict register values to range: -2^size to (2^size)-1 (*map).insert( StringRegPair( std::string(keystr), EmuVal( util_.mkSV( path, pathstr ), scale, 1, 1, (uint32_t)(pow(2,size)-1), (uint32_t)(int)(-pow(2,size))) ) ); } void mapArrayROHelper_(StringRegMapRO *map, Path path, char *parmstr, char *prefstr, int index, double scale) { char pathstr[MAX_KEY_LENGTH]; char keystr[MAX_KEY_LENGTH]; sprintf( keystr, "%s[%d]", parmstr, index ); sprintf( pathstr, "%s[%d]/%s", prefstr, index, parmstr ); (*map).insert( StringRegPairRO( std::string(keystr), EmuValRO(util_.mkSVRO( path, pathstr ), scale) ) ); } public: CPDigiFERegs defineRegs(PathFinder finder, unsigned bay, bool *haveStriplAfe) { bool isStriplFw = false; bool isCavityFw = false; CPDigiFERegs regs; StringRegMap *bpmMap = ®s.bpmMap; StringRegMapRO *bpmMapRO = ®s.bpmMapRO; IntRegMap *qspiMap = ®s.qspiMap; // Define Control and Status Register access Path csrPath; try { csrPath = finder.find( "AppCore/MiscCSR" ); } catch ( NotFoundError &e ) { printf("commonPlatformDigiFE: Failed to find MiscCSR common registers at AppCore/MiscCSR\n" ); } if ( csrPath ) { char parmstr[50]; sprintf( parmstr, "FirmwareConfigurationAMC%d", bay ); ScalVal_RO fwConfig = util_.mkSVRO( csrPath, parmstr ); unsigned fwType; fwConfig->getVal( &fwType, 1 ); if ( fwType ) isCavityFw = true; else isStriplFw = true; regs.bpmMapRO.insert( StringRegPairRO( "FirmwareConfiguration", EmuValRO( util_.mkSVRO( csrPath, parmstr ), 1. ) ) ); // For simplicity, software for both bays read FirmwareConfigurationRTM. Could be moved to carrier-level software util_.strMapInsertRO( bpmMapRO, csrPath, (char *)"FirmwareConfigurationRTM", 1. ); } else { printf("WARNING: Failed to read if FW is stripl or cavity. BPM-type-specific functionality disabled.\n"); } // Define BPM register access Path bpmRegPath; try { bpmRegPath = finder.find( "AppCore/AmcBay%d/Bpm", bay ); } catch ( NotFoundError &e ) { printf("commonPlatformDigiFE: Failed to find BPM common registers at AppCore/AmcBay%d/Bpm\n", bay ); } if ( bpmRegPath ) { // For X, Y, perform scaling to 2^17 in EPICS records/device support (instead of here ) // because those scale factors also used by client applications. (less duplication) util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"X", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"Y", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"Tmit", pow(2,17) ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"Status", pow(2,17) ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"A11", pow(2,23) ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"A12", pow(2,23) ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"A21", pow(2,23) ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"A22", pow(2,23) ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"O_1", pow(2,23) ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"O_2", pow(2,23) ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"TmitScl", pow(2,16) ); try { printf("Temporary try/catch around TmitThreshold until stripline FW updated. Try/catch to be removed\n"); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"TmitThreshold", pow(2,17) ); } catch ( NotFoundError &e ) { } util_.strMapInsert( bpmMap, bpmRegPath, (char *)"MuxGRN", 1. ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"MuxBLU", 1. ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"MuxYLO", 1. ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"MuxRED", 1. ); } if ( isStriplFw ) { // QSPI emulation Path afePath; try { afePath = finder.find( "AppCore/AmcBay%d/StriplCalCtrl", bay ); } catch ( NotFoundError &e ) { } if ( afePath ) { // FIXME -- will disappear // These need to be handled specially // #define AFE_REG_CSR 0 // #define AFE_REG_VER 5 // delays are assumed 33ns ticks: desired * 33ns = 1/fclk * cal_ticks // calibrator clock is 156.25MHz (AXIL clock) const double dlyScale = 5.156; util_.intMapInsert( qspiMap, afePath, AFE_REG_ATT1, (char *)"AttnA", 1. ); util_.intMapInsert( qspiMap, afePath, AFE_REG_ATT2, (char *)"AttnB", 1. ); util_.intMapInsert( qspiMap, afePath, AFE_REG_CALA, (char *)"AttnCal", 1. ); util_.intMapInsert( qspiMap, afePath, AFE_REG_T2AMP, (char *)"Delay_TRIG2AMP", dlyScale ); util_.intMapInsert( qspiMap, afePath, AFE_REG_AMP2RF1, (char *)"Delay_AMP2RF1", dlyScale ); util_.intMapInsert( qspiMap, afePath, AFE_REG_RF12RF2, (char *)"Delay_RF12RF2", dlyScale ); util_.intMapInsert( qspiMap, afePath, AFE_REG_RFWIDTH, (char *)"Delay_RFWIDTH", dlyScale ); util_.intMapInsert( qspiMap, afePath, AFE_REG_OFFTIME, (char *)"Delay_OFFTIME", dlyScale ); util_.intMapInsert( qspiMap, afePath, AFE_REG_TRIG2BEAM, (char *)"Delay_Trig2Beam", dlyScale ); util_.intMapInsert( qspiMap, afePath, AFE_REG_RF2RED, (char *)"Delay_RF2Red", dlyScale ); util_.intMapInsert( qspiMap, afePath, AFE_REG_RF2GRN, (char *)"Delay_RF2Green", dlyScale ); // Additional entry for regs.bpmMap so can access via same routines util_.strMapInsert( bpmMap, bpmRegPath, (char *)"SoftTrig", 1. ); regs.calMode = util_.mkSV( afePath, "Cal_CALMode" ); regs.calSoftTrig = util_.mkSV( afePath, "SoftTrig" ); regs.initFlag = util_.mkSV( afePath, "InitFlag" ); regs.calEnaTrig = util_.mkSV( afePath, "Cal_EnaTrig" ); regs.calContTrig = util_.mkSV( afePath, "Cal_ContTrig" ); // Initialize cal mode to green cycle to match genDigiCommConfig regs.calMode->setVal( "Green" ); // Activate cal trigger and set to auto-reset regs.calEnaTrig->setVal( 1 ); regs.calContTrig->setVal( 1 ); *haveStriplAfe = true; if ( bpmRegPath ) { util_.strMapInsert( bpmMap, bpmRegPath, (char *)"DeltaCal_GRN", pow(2,17) ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"DeltaCal_RED", pow(2,17) ); } #ifdef CPDEBUG printf("print out qspi emul map info\n"); std::cout << "regs.qspiMap.size() is " << regs.qspiMap.size() << '\n'; printf("print regs.qspiMap values\n"); IntRegMap::iterator iter; for ( iter = regs.qspiMap.begin(); iter != regs.qspiMap.end(); ++iter ) { int nelms = iter->second.sv_->getNelms(); uint32_t val[ nelms ]; iter->second.sv_->getVal(val, nelms); for ( int j = 0; j < nelms ; j++ ) std::cout << iter->first << ", " << val[j] << '\n'; } uint32_t val; regs.calMode->getVal(&val, 1); std::cout << "print calmode: " << val << '\n'; regs.calEnaTrig->getVal(&val, 1); std::cout << "print enatrig: " << val << '\n'; regs.calContTrig->getVal(&val, 1); std::cout << "print conttrig: " << val << '\n'; std::cout << "-------------"; #endif } } else if ( isCavityFw ) { // Define Cavity BPM register access if ( bpmRegPath ) { char prefstr[MAX_KEY_LENGTH]; sprintf( prefstr, "DFTChannels"); for ( unsigned i = 0; i < CAV_NUM_DETS; i++ ) { mapArrayLimHelper_( bpmMap, bpmRegPath, (char *)"Coeff2C4", prefstr, i, pow(2,16), 17); mapArrayLimHelper_( bpmMap, bpmRegPath, (char *)"Coeff2C2", prefstr, i, pow(2,16), 17); mapArrayLimHelper_( bpmMap, bpmRegPath, (char *)"Coeff2C1", prefstr, i, pow(2,16), 17); mapArrayLimHelper_( bpmMap, bpmRegPath, (char *)"Coeff2S1", prefstr, i, pow(2,16), 17); mapArrayLimHelper_( bpmMap, bpmRegPath, (char *)"CoeffHU_Re", prefstr, i, pow(2,17), 17); mapArrayLimHelper_( bpmMap, bpmRegPath, (char *)"CoeffHU_Im", prefstr, i, pow(2,17), 17); mapArrayLimHelper_( bpmMap, bpmRegPath, (char *)"CoeffHV_Re", prefstr, i, pow(2,17), 17); mapArrayLimHelper_( bpmMap, bpmRegPath, (char *)"CoeffHV_Im", prefstr, i, pow(2,17), 17); } sprintf( prefstr, "DFTDiagChannels"); for ( unsigned i = 0; i < CAV_NUM_DETS; i++ ) { mapArrayROHelper_( bpmMapRO, bpmRegPath, (char *)"DFT_U", prefstr, i, 1. ); mapArrayROHelper_( bpmMapRO, bpmRegPath, (char *)"DFT_V", prefstr, i, 1. ); mapArrayROHelper_( bpmMapRO, bpmRegPath, (char *)"DFT_R", prefstr, i, 1. ); mapArrayROHelper_( bpmMapRO, bpmRegPath, (char *)"ReDFT_U", prefstr, i, pow(2,15) ); mapArrayROHelper_( bpmMapRO, bpmRegPath, (char *)"ImDFT_U", prefstr, i, pow(2,15) ); mapArrayROHelper_( bpmMapRO, bpmRegPath, (char *)"ReDFT_V", prefstr, i, pow(2,15) ); mapArrayROHelper_( bpmMapRO, bpmRegPath, (char *)"ImDFT_V", prefstr, i, pow(2,15) ); mapArrayROHelper_( bpmMapRO, bpmRegPath, (char *)"ReDFT_R", prefstr, i, pow(2,15) ); mapArrayROHelper_( bpmMapRO, bpmRegPath, (char *)"ImDFT_R", prefstr, i, pow(2,15) ); } util_.strMapInsert( bpmMap, bpmRegPath, (char *)"DFTScaleR", 1. ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"DFTScaleU", 1. ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"DFTScaleV", 1. ); util_.strMapInsert( bpmMap, bpmRegPath, (char *)"StatusClear", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusRaw", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusRawLatched", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusInputUInvalid", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusInputVInvalid", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusInputRInvalid", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusDFTOvflU", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusDFTOvflV", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusDFTOvflR", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusDFTOvfl", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusDivOvflReU", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusDivOvflImU", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusDivOvflReV", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusDivOvflImV", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedInputUInvalid", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedInputVInvalid", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedInputRInvalid", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedDFTOvflU", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedDFTOvflV", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedDFTOvflR", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedDivOvflReU", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedDivOvflImU", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedDivOvflReV", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedDivOvflImV", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"StatusLatchedDFTOvfl", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"ComplexU", 1. ); util_.strMapInsertRO( bpmMapRO, bpmRegPath, (char *)"ComplexV", 1. ); } } #ifdef CPDEBUG { printf("BPM reg map info:\n"); std::cout << "regs.bpmMap.size() is " << regs.bpmMap.size() << '\n'; StringRegMap::iterator iter; uint32_t val; for ( iter = regs.bpmMap.begin(); iter != regs.bpmMap.end(); ++iter ) { iter->second.sv_->getVal(&val, 1); std::cout << iter->first << ", " << val << '\n'; } std::cout << "-------------\n"; } { std::cout << "regs.bpmMapRO.size() is " << regs.bpmMapRO.size() << '\n'; StringRegMapRO::iterator iter; unsigned nelms; for ( iter = regs.bpmMapRO.begin(); iter != regs.bpmMapRO.end(); ++iter ) { nelms = iter->second.sv_->getNelms(); uint32_t val[nelms]; iter->second.sv_->getVal( val, nelms); for ( unsigned i = 0; i < nelms; i++ ) std::cout << iter->first << ", " << val[i] << '\n'; } std::cout << "-------------"; } #endif return regs; } }; #endif