#==============================================================
#
#  Abs:  Load YAML files and configure SLAC PCIe TPR
#
#  Name: init_pcie_tpr.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
#            BOARD_IP  - IP address for carrier board (ATCA only)
#
#        Upon leaving this script leaves the users in 
#        the TOP directory of the IOC application.
#
#  Facility: Laser Controls
#
#  Auth: 1w-Aug-2022, K. Luchini      (LUCHINI)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        dd-mmm-yyyy, First Lastname  (USERNAME):
#          comment
#
#==============================================================
#

# Change directory to YAML directory
cd ${YAML_DIR}
pwd()

# 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("000TopLevel.yaml", "MemDev", "", "/dev/tpra", "root0")

# Load FPGA configuration from YAML file
crossbarControlAsynDriverConfigure("crossbar0", "PCIe:/mmio/SfpXbar", "root0")

# Setup TPG Driver
tprTriggerAsynDriverConfigure("trig0", "PCIe:/mmio", "root0")

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

# End of script

