/** *----------------------------------------------------------------------------- * Title : LCLS-II MPS EPICS Module * ---------------------------------------------------------------------------- * File : drvL2MPSASYN.h * Author : Jesus Vasquez, jvasquez@slac.stanford.edu * Created : 2017-10-20 * ---------------------------------------------------------------------------- * Description: * EPICS Module for interfacing the LCLS-II MPS. * ---------------------------------------------------------------------------- * This file is part of l2MpsAsyn. It is subject to * the license terms in the LICENSE.txt file found in the top-level directory * of this distribution and at: * https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. * No part of l2MpsAsyn, including this file, may be * copied, modified, propagated, or distributed except according to the terms * contained in the LICENSE.txt file. * ---------------------------------------------------------------------------- **/ #include #include #include #include #include #include "asynPortDriver.h" #include #include #include #include "l2Mps_mps.h" #include "l2Mps_thr.h" #include "l2Mps_bpm.h" #include "l2Mps_blen.h" #include "l2Mps_bcm.h" #include "l2Mps_blm.h" extern "C" { #include "mpsManagerInfo.h" } #define DRIVER_NAME "L2MPS" #define MAX_SIGNALS (3) // Max number of parameter list (number of bays) #define NUM_PARAMS (1500) // Max number of paramters // Number of AMC bays on a carrier const uint8_t numberOfBays = 2; // Asyn parameter list numbers const int paramListAppBay0 = 0; // Bay 0 application const int paramListAppBay1 = 1; // Bay 1 application const int paramListMpsBase = 2; // MPS base // Number of RX Links const std::size_t numberOfRxLinks = 14; // Default MPS Root Path const std::string defaultMpsRootPath("mmio/AmcCarrierCore/AppMps"); // BPM data types typedef bool (IMpsBpm::*BpmW32_t)(const bpmThr_channel_t&, const float) const; typedef bool (IMpsBpm::*BpmW1_t)(const bpmThr_channel_t&, const bool) const; typedef bool (IMpsBpm::*bpm_setScaleSlope_func_t)(const bpm_channel_t&, const float) const; typedef bool (IMpsBpm::*bpm_setScaleOffset_func_t)(const bpm_channel_t&, const float) const; typedef bool (IMpsBpm::*bpm_setIdleEn_funct_t)(const bpm_channel_t&, const bool) const; typedef std::map> bpm_fmap_w32_t; typedef std::map> bpm_fmap_w1_t; typedef std::map> bpm_scaleSlopeFuncMap_t; typedef std::map> bpm_scaleOffsetFuncMap_t; typedef std::map> bpm_setIdleEnMap_t; // BLEN data types typedef bool (IMpsBlen::*BlenW32_t)(const blenThr_channel_t&, const float) const; typedef bool (IMpsBlen::*BlenW1_t)(const blenThr_channel_t&, const bool) const; typedef bool (IMpsBlen::*blen_setScaleSlope_func_t)(const blen_channel_t&, const float) const; typedef bool (IMpsBlen::*blen_setScaleOffset_func_t)(const blen_channel_t&, const float) const; typedef bool (IMpsBlen::*blen_setIdleEn_funct_t)(const blen_channel_t&, const bool) const; typedef std::map> blen_fmap_w32_t; typedef std::map> blen_fmap_w1_t; typedef std::map> blen_scaleSlopeFuncMap_t; typedef std::map> blen_scaleOffsetFuncMap_t; typedef std::map> blen_setIdleEnMap_t; // BCM data types typedef bool (IMpsBcm::*BcmW32_t)(const bcmThr_channel_t&, const float) const; typedef bool (IMpsBcm::*BcmW1_t)(const bcmThr_channel_t&, const bool) const; typedef bool (IMpsBcm::*bcm_setScaleSlope_func_t)(const bcm_channel_t&, const float) const; typedef bool (IMpsBcm::*bcm_setScaleOffset_func_t)(const bcm_channel_t&, const float) const; typedef bool (IMpsBcm::*bcm_setIdleEn_funct_t)(const bcm_channel_t&, const bool) const; typedef std::map> bcm_fmap_w32_t; typedef std::map> bcm_fmap_w1_t; typedef std::map> bcm_scaleSlopeFuncMap_t; typedef std::map> bcm_scaleOffsetFuncMap_t; typedef std::map> bcm_setIdleEnMap_t; // BLM data types typedef bool (IMpsBlm::*BlmW32_t)(const blmThr_channel_t&, const float) const; typedef bool (IMpsBlm::*BlmW1_t)(const blmThr_channel_t&, const bool) const; typedef bool (IMpsBlm::*blm_setScaleSlope_func_t)(const blm_channel_t&, const float) const; typedef bool (IMpsBlm::*blm_setScaleOffset_func_t)(const blm_channel_t&, const float) const; typedef bool (IMpsBlm::*blm_setIdleEn_funct_t)(const blm_channel_t&, const bool) const; typedef std::map> blm_fmap_w32_t; typedef std::map> blm_fmap_w1_t; typedef std::map> blm_scaleSlopeFuncMap_t; typedef std::map> blm_scaleOffsetFuncMap_t; typedef std::map> blm_setIdleEnMap_t; // Types of register interfaces enum paramTypeList { PARAM_TYPE_INT, PARAM_TYPE_DIG, PARAM_TYPE_STR, PARAM_TYPE_SIZE }; // MPS base parameter data type struct mps_infoParam_t { int appId; int version; int enable; int lcls1Mode; int byteCount; int digitalEn; int beamDestMask; int altDestMask; int msgCnt; int lastMsgAppId; int lastMsgLcls; int lastMsgTimestamp; std::vector lastMsgByte; int txLinkUp; int txLinkUpCnt; std::vector rxLinkUp; std::vector rxLinkUpCnt; int mpsSlot; int appType; int pllLocked; int rollOverEn; int txPktSentCnt; std::vector rxPktRcvdCnt; int rstCnt; int rstPll; }; // Threshold table parameters data type struct thr_tableParam_t { int minEn; int maxEn; int min; int max; }; // Threshold table parameter map data type typedef std::map thr_chParam_t; struct thr_chInfoParam_t { int ch; int count; int byteMap; int idleEn; int altEn; int lcls1En; int scaleSlope; int scaleOffset; }; // Threhold parameter (information + table data) data type struct thr_param_t { thr_chInfoParam_t info; thr_chParam_t data; }; // Application paramater map data type struct cmp { bool operator()(const boost::any& l, const boost::any& r) { try { blm_channel_t left = boost::any_cast(l); blm_channel_t right = boost::any_cast(r); return left < right; } catch(const boost::bad_any_cast &) { } try { bcm_channel_t left = boost::any_cast(l); bcm_channel_t right = boost::any_cast(r); return left < right; } catch(const boost::bad_any_cast &) { } try { bpm_channel_t left = boost::any_cast(l); bpm_channel_t right = boost::any_cast(r); return left < right; } catch(const boost::bad_any_cast &) { } try { blen_channel_t left = boost::any_cast(l); blen_channel_t right = boost::any_cast(r); return left < right; } catch(const boost::bad_any_cast &) { } std::cout << "paramMap_t error: not comparison found!" << std::endl; return false; } }; typedef std::map paramMap_t; class L2MPS : public asynPortDriver { public: // Constructor L2MPS(const char *portName, const uint16_t appId, const std::string recordPrefixMps, const std::array recordPrefixBay, std::string mpsRootPath); // Methods that we override from asynPortDriver virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); virtual asynStatus writeUInt32Digital(asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask); virtual asynStatus writeFloat64 (asynUser *pasynUser, epicsFloat64 value); // Update singel parametr value, status and severity void updateAlarmParam(int list, int index, bool valid); template void updateIntegerParam(int list, int index, std::pair p); template void updateStringParam(int list, int index, std::pair p); template void updateUIntDigitalParam(int list, int index, std::pair p); template void updateParamArray(int type, int list, const std::vector& index, const std::pair< bool, std::vector > p); template void updateDoubleParam(int list, int index, std::pair p); // MPS base info callback function void updateMpsParametrs(mps_infoData_t info); // App callback function template void updateAppParameters(int bay, T data); private: const char *driverName_; // Name of the driver (passed from st.cmd) const char *portName_; std::string recordPrefixMps_; std::array recordPrefixBay_; std::array amcType_; MpsNode node_; boost::any amc[numberOfBays]; // BPM application fuction maps bpm_fmap_w32_t fMapBpmW32; bpm_fmap_w1_t fMapBpmW1; bpm_scaleSlopeFuncMap_t fMapBpmWScaleSlope; bpm_scaleOffsetFuncMap_t fMapBpmWScaleOffset; bpm_setIdleEnMap_t fMapBpmSetIdleEn; // BLEN application fuction maps blen_fmap_w32_t fMapBlenW32; blen_fmap_w1_t fMapBlenW1; blen_scaleSlopeFuncMap_t fMapBlenWScaleSlope; blen_scaleOffsetFuncMap_t fMapBlenWScaleOffset; blen_setIdleEnMap_t fMapBlenSetIdleEn; // BCM application fuction maps bcm_fmap_w32_t fMapBcmW32; bcm_fmap_w1_t fMapBcmW1; bcm_scaleSlopeFuncMap_t fMapBcmWScaleSlope; bcm_scaleOffsetFuncMap_t fMapBcmWScaleOffset; bcm_setIdleEnMap_t fMapBcmSetIdleEn; // BLM application fuction maps blm_fmap_w32_t fMapBlmW32; blm_fmap_w1_t fMapBlmW1; blm_scaleSlopeFuncMap_t fMapBlmWScaleSlope; blm_scaleOffsetFuncMap_t fMapBlmWScaleOffset; blm_setIdleEnMap_t fMapBlmSetIdleEn; // MPS base parameters mps_infoParam_t mpsInfoParams; // Application parameters paramMap_t paramMap; // BPM application init void InitBpmMaps(const int bay); void InitBlenMaps(const int bay); void InitBcmMaps(const int bay); void InitBlmMaps(const int bay); };