#==============================================================
#
#  Abs:  Generic piece of startup script for LinuxRT IOCs
#
#  Name: st.cmd
#
#  Side: Upon entry to this script expect to be at the
#        iocBoot directory for the IOC. In addition the
#        following macros are expected:
#
#            IOC_NAME - IOC devices name (i.e. SIOC:LI20:KY01)
#            LOCA     - Machine area (i.e. LI26)
#            PLC_NODE - PLC Node name (i.e.  plc-li25-hprf03)
#            STN      - Klystron Station number (i.e. 1-8)
#            ACF_FILE - channel access initalization script,
#                       including path       
#
#        All other macros used within this script
#        are set from the file iocBoot/<ioc>/envPaths,
#        which is loaded from iocBoot/common/st.cmd.linuxRT 
#
#  Facility:  Klystron Controls
#
#  Auth: 25-Sep-2018, Thomas Kurty    (TKURTY)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        24-Apr-2019, K. Luchini      (LUCHIN):
#          load generic scripts from iocBoot/common
#
#==============================================================
#

# Load generic startup
< ../../common/st.cmd.linuxRT

dbLoadRecords("db/Klystron.db",         "PRIMARY=${DEVICE},MICRO=LI${SECTOR},UNIT=${STATION}1")
dbLoadRecords("db/kly_modulator_mr.db", "LOCA=LI${SECTOR},STN=${STATION},NODE=${PLC_NODE},V1=2,V2=0,V3=0" }
dbLoadRecords("db/tprTrg.db",           "DEV=${DEVICE}:LI${SECTOR}:${STATION}1, PORT=trig")
dbLoadRecords("db/tprPattern.db",       "DEV=${DEVICE}:LI${SECTOR}:${STATION}1, PORT=pattern")

# Initialize hardware and autosave
< iocBoot/common/init_yaml.cmd
< iocBoot/common/init_tpr.cmd
< iocBoot/common/init_plc.cmd
< iocBoot/common/init_restore.cmd

# Start EPICS 
iocInit()

# Generate autosave fiels and being monitoring PVs
< iocBoot/common/restore.cmd

# Setup crossbar timing
# FPGA and backplane get timing from RTM
crossbarControl FPGA RTM_IN0
crossbarControl BP RTM_IN0

# Start sequencees
< iocBoot/common/init_seq.cmd

# [eof iocBoot/common/st.cmd]

