#==============================================================
#
#  Abs:  Load YAML files and configure
#
#  Name: init_yaml.cmd
#
#  Side: Upon entry to this script, the following macros
#        are expected:
#            YAML_DIR  - The directory where yaml files reside.
#            YAML_PATH - DO NOT USE --- special meaning to cpsw
#            FPGA_IP  - IP address for carrier board
#
#        Upon leaving this script leaves the users in 
#        the TOP directory of the IOC application.
#
#  Facility:  Klystron Controls
#
#  Auth: dd-mmm-2018, Thomas Kurty    (TKRUTY)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        27-Nov-2018, K. Luchini      (LUCHINI):
#          extract from iocBoot/common/st.cmd
#
#==============================================================
#
# Change directory to YAML directory
cd ${YAML_DIR}
pwd()

# Download the YAML files from the FPGA
# DownloadYamlFile ( IP address for carrier board
#                    Output directory for the YAML files)
#
#
 DownloadYamlFile("${FPGA_IP}", "${YAML_DIR}")


# 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) )
#
# Note: the format of the ip address for the carrier board is auto-generated from the
# ATCA Shelf Manager local address: 4-digits hex number. The default address is set to
#     0A<crate #>, where the crate number ranges from 01-ff.
# The crates referred to are the crates that are connected to the industrial PC (IPC). So if there
# are 4 crates connected to one IPC, the crate numbers would be 01-04. If another IPC exists in the same area
# that is phisically connected to 2 other crates, those crates would be defined as 01-02.
# The Shelf Manager local address generates the board locat address, where the bpard adress
# has the following format: 10:<2nd field>:<3rd field>:<4th field>
#
# So the two left most digits of shelf manager address, 0A hex, which is 10 decimal, 
# defines the 2nd field of the board address.  decimal The 2-rightmost digits.
#
# The two right most digits of the shelf manager address <crate #>, 01, produces the
# 3rd field of the boar address.. 
# board ip address format: 10.<2nd field>.<3rd field>.<4th field>
#
# ATCA AMC board local address:  10.10.01.<100+slot#>. The MPS module is located in slot #, so the
# board adress is:  10:10:01:102  (crate 1), 10.10.02.102 (crate 2), etc..
# Low-level RF only has 1 ATCA crate and shelf manager per station, so the first 3 fields
# should be the same, the only difference is the slot number of the IP Carrier for the
# AMC boards
cpswLoadYamlFile("${YAML_FILE}", "NetIODev", "", "${FPGA_IP}", "MyRoot0")

# 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("${YAML_DEFAULTS_FILE}", "mmio", "",  "MyRoot0")


# ======================================================
# disable BLD/BSSS/BSAS temporally
# until the iocInit process is completed
# the services will be restored back by its control PVs
# =======================================================
cd ("${IOC_DATA}/${IOC}/yamlConfig")
cpswLoadConfigFile("./disable_bld_bsss_bsas.yaml", "mmio/AmcCarrierCore/AmcCarrierBsa")



# Change directory to top of application
cd ${TOP}

# End of script

