#==============================================================
#
#  Abs:  Load YAML files and configure
#
#  Name: init_cpsw.cmd 
#
#  Side: Upon entry to this script, the following macros
#        are expected:
#     BOARD_IP         - IP address for carrier board
#     FPGA_IP          - FPGA IP Address and Slot number
#     YAML_CONFIG_FILE - Yam configuration filename
#     TOP_YAML_FILE    - Top Yaml filename, ex)<ioc>.yaml
#     DICT_FILE        - Dictionary file for manual,
#                        string empty of none.
#     IOC_DATA         - data dir path, wwrite access
#     IOC              - IOC name (from envpath)
#
#  Facility: EED Motion Control
#
#  Auth: dd-mmm-2018, Author's Name   (USERNAME)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        27-Apr-2021, N. Balakrishnan (namrata):
#          extract from iocBoot/common/init_atca.cmd
#          This is such that lcls and lcls2 timing and bsa initialization can be separate
#
#==============================================================
epicsEnvSet("TOP_YAML_FILE"   , "000TopLevel.yaml")
epicsEnvSet("YAML_CONFIG_FILE", "defaultsFwsLcls1-7-23-19.yaml")
epicsEnvSet("DICT_FILE"       , "fwsLcls2.dict")

# Yaml Downloader
DownloadYamlFile("${FPGA_IP}", "${IOC_DATA}/${IOC}/yaml")

# Load FPGA hierarchy from YAML
# cpswLoadYamlFile ( YAML hierarchy descrtiption file,
#                    Root Device Name (optional; default = 'root'),
#                    directory where YAML includes can be found (optional),
#                    IP address for carrier board (override the IP address in YAML) )
cpswLoadYamlFile("${IOC_DATA}/${IOC}/yaml/${TOP_YAML_FILE}", "NetIODev", "", "${FPGA_IP}")

# Load FPGA configuration from YAML file
# cpswLoadConfigFile ( CONFIG YAML file (NOT hierarchy YAML!),
#                      Path prefix (if config YAML is not based of the root device; optional),
#                      directory where YAML includes can be found (optional) )
cpswLoadConfigFile("${IOC_DATA}/${IOC}/yaml/config/${YAML_CONFIG_FILE}", "mmio", "")

# Configure asyn port driver
# YCPSWASYNConfig(
#    Port Name,                 # the name given to this port driver
#    Root Path                  # OPTIONAL: Root path to start the generation. If empty, the Yaml root will be used
#    Record name Prefix,        # Record name prefix
#    Use DB Autogeneration,     # Set to 1 for autogeneration of records from the YAML definition. Set to 0 to disable it
#    Load dictionary,           # Dictionary file path with registers to load. An empty string will disable this function
# In Sector 0 L2KA00-05, the BCMs are in slots 6 and 7. Here, for testing purposes we are using slots 4 and 5.
YCPSWASYNConfig("cpsw", "", "", "0", "${TOP}/firmware/${DICT_FILE}")

# Load database for common CPSW registers
dbLoadRecords("db/cpsw_common.db","PORT=cpsw,P=${AMCC_NAME}")

# End of script

