# Startup commands for ATCA Common Platform BPM IOC 

chdir(getenv("TOP"))

## Register all support components
dbLoadDatabase("dbd/bpmAppTpr.dbd",0,0)
bpmAppTpr_registerRecordDeviceDriver(pdbbase)

# Pause before attempting communication with FPGA 
# to prevent timeouts
epicsThreadSleep(10.0)

## yamlDownloader
DownloadYamlFile(getenv("FPGA_IP"), getenv("YAML_DIR"))

# If NO_ARCHIVE not defined, copy latest archive file to data area
(getenv("NO_ARCHIVE") || system("cp ${TOP}/archive/${IOC}.archive /data/${IOC}/archive/."))

## yamlLoader
chdir(getenv("YAML_DIR"))
cpswLoadYamlFile(getenv("YAML"), "NetIODev", 0, getenv("FPGA_IP"))

chdir(getenv("TOP"))

# Disable triggers before init
cpswLoadConfigFile("iocBoot/common/cp/cp_disable_trig.yaml", "mmio")
epicsThreadSleep(2.0)

#According to Larry we sometimes have to load twice in order
#to get JESD to initialize correctly...
cpswLoadConfigFile(getenv("DEFAULTS_FILE"), "mmio")
cpswLoadConfigFile(getenv("DEFAULTS_FILE"), "mmio")

# Initialize Carrier/EVR FW interface. One per carrier, starting at instance of 0
# usage: bpmCommonPlatformCarrierConfig(int instance)
bpmCommonPlatformCarrierConfig(0)

iocsh("iocBoot/common/cp/tpr/tpr.cmd")
