#==============================================================
#
#  Abs:  Initialize VME IPAC hardware
#
#  Name: init_ipac.cmd
#
#  Facility:  SLAC PPS Controls
#
#  Auth: 29-Sep-2010, Arturo Alarcon  (ALARCON)
#  Rev:  dd-mmm-yyyy, Reviewer's Name (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        28-Oct-2019, K. Luchini      (LUCHINI):
#          add ipacLastCarrier()
#        14-Oct-2019, K. Luchini      (LUCHINI):
#          extract from st.cmd
#
#==============================================================
#

# Initialized ip carriers
# Input arguments are: card info, A16 address
bspExtVerbosity=0
ipacAddXy9660("0x0000,3")
carrier0 = ipacLatestCarrier()

ipacAddXy9660("0x0400,3")
carrier1 = ipacLatestCarrier()

# Initialized ip445
# Input arguments are:
#      name, card, slot
xy2445Create("DO-SYS0-1-PPS",carrier0,2)
xy2445Create("DO-SYS0-2-PPS",carrier1,2)

# Initialize DI ip440
# Input arguments are:
#   name, card, slot, modeName, intHandlerName, usrFunc, vector, event, debounce
xy2440Create("DI-SYS0-1-PPS", carrier0, 0, "STANDARD", "LEVEL", 0x0, 0x80, 0x0, 0x00)
xy2440Create("DI-SYS0-2-PPS", carrier0, 1, "STANDARD", "LEVEL", 0x0, 0x80, 0x0, 0x00)
xy2440Create("DI-SYS0-3-PPS", carrier1, 0, "STANDARD", "LEVEL", 0x0, 0x80, 0x0, 0x00)
xy2440Create("DI-SYS0-4-PPS", carrier1, 1, "STANDARD", "LEVEL", 0x0, 0x80, 0x0, 0x00)

# Initialize ip330 adcs
# Input arguments are:
IP330_DRV_DEBUG=0
#  SYNOPSIS: int ip330Create(
#                  char *cardname,  Unique Identifier "ip330-1"
#                  UINT16 carrier,  Ipac Driver carrier card number
#                  UINT16 slot,     Slot number on IP carrier
#                  char *adcrange   This must be "-5to5D","-10to10D","0to5D","0to10D","-5to5S","-10to10S","0to5S","0to10S"
#                  char *channels,  This must be "ch1-ch12" or "ch2-ch30", available range is 0 to 15/31 depends on Differential or Single End
#                  UINT32 gainL,    The lower two bits is gain for channel0, then channel 1 ... 15, b00=1, b01=2,b10=4,b11=8
#                  UINT32 gainH,    The lower two bits is gain for channel16, then channel 17 ... 31
#                  char *scanmode   Scan mode must be "mode-trgdir-AvgxR"
#                                   mode could be "uniformCont", "uniformSingle", "burstCont", "burstSingle", "cvtOnExt"
#                                   trgdir could be "Input", "Output" except for "cvtOnExt" which must come with "Input"
#                                   AvgxN could be Avg10 means average 10 times, R means reset after average and only applicable to Continuous mode
#                  char *timer,     "x*y@8MHz", x must be [64,255], y must be [1,65535]
#                  UINT8            vector)
ip330Create("AI1-SYS0-1-PPS", carrier0, 3, "0to10D", "ch0-ch11", 0x00FFF0FF, 0x00, "burstCont-Output-Avg5", "64*12000@8MHz", 0x66)

# End of script

