#==============================================================
#
#  Abs:  Initialize IPAC hardware
#
#  Name: init_ipac.cmd
#
#  Facility:  LCLS Laser Controls
#
#  Auth: 02-Aug-2019, Shawn Alverson   (ALVERSON)
#  Rev:  dd-mmm-yyyy, Reviewer's Name  (USERNAME)
#--------------------------------------------------------------
#  Mod:
#        16-Apr-2022, K. Luchini       (LUCHINI):
#         extract from LaserEIC/iocBoot/sioc-lgun-ls01/st.cmd
#
#==============================================================
#

# Turn On/Off Debug message
# WARNING: set bspExtVerbosity to 3 to slow down processor because
# otherwise the IDprom name  of this modules is not returned correctly.
# This check is done in the function hytec_ipmValidate() which
# is in the source file hytecIpm.c
var("IP330_DRV_DEBUG", 0)
#var("IP231_DRV_DEBUG", 0)

# Create Acromag 8650 PCI card
ipApcie8650Add("0")
#carrier1 = ipacLatestCarrier()

# ====================================================
# Analog Input module [Acromag Industry Pack: IP330]
# ====================================================
# ip330Create(cardname, carrier, slot, adcrange, channels, gainL, gainH, scanmode, timer, vector)
#
# Input arguments:
#     card name = example "ai0"
#     carrier   = 0 = Ipac driver carrier card number
#     slot      = Slot or port number on IP carrier board ex) portA=0, portB=1, portC=2, portD=3
#     adcrange  = This must be "-5to5D","-10to10D","0to5D","0to10D","-5to5S","-10to10S","0to5S","0to10S"
#               = 0t10S
#     channels  = This must be "ch1-ch12" or "ch2-ch30", available range is
#                 0 to 15/31 depends on Differential or Single End
#               = ch0-ch31
#     gainL     = The lower two bits is gain for channel0, then channel 1 ... 15
#     gainH     = The lower two bits is gain for channel16, then channel 17 ... 31
#     scanmode  = 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
#     timer     = "x*y@8MHz", x must be [64,255], y must be [1,65535]
#                 8 MHz is 0.125 us. 64 * 12000 * 0.125 us = 96 ms timer
#     vector    = 0x66
#
# Single-ended, 32 channels,
# Differential, 16 channels,
# Each sample takes 40us * 8 channels * 5 times = 1.6ms
#
# ex)
# ip330Create("ai0", 1, 3, "-5to5D", "ch0-ch7", 0x00, 0x00, "uniformCont-Input-Avg5R", "64*5@8MHz", 0x66)
#
# Tips from Sheng: Specify only channels used to reduce mux time &
#                  not saturate ADC by unwired channel
#                  Use Double-Ended for noise rejection even if not a true differential signal
#                  Use averaging to reduce noise AvgXR, X=number of averages, R=Reset after average
#                  Try burstCont to see if I get pseudo-synchronous per Acromag manual
ip330Create("ai0", 0       , 0, "0to5D" , "ch0-ch15", 0x0, 0x0, "burstCont-Output-Avg5", "64*128@8MHz", 0x66)

# ====================================================
# Analog Output module [Acromag Industry Pack: IP231]
# ====================================================
# Input arguments are
#   1) general string for card name.
#   2) Ipac Driver carrier card number.
#   3) Slot number on IP carrier.
#   4) DAC Mode, either "transparent" or "simultaneous"
#       In transparent mode, outputs are updated when written
#       In simultaneous mode, multiple output values can be setup,
#        and all outputs update when ip231SimulTrigger(<cardNo>) is called
#ip231Create("ao0", carrier1, 1, "transparent") 

# ===============================================================
# Digital Input/Output TTL module [Acromag Industry Pack: IP470]
# ===============================================================
# avme470Create parameters:
#   1) general string for card name.
#   2) Ipac Driver carrier card number.
#   3) Slot number on IP carrier.
#   4) Mode name; must be one of: "STANDARD" or "ENHANCED"
#        In Standard Mode, each I/O line is configured as either an Input, Output, or Output w/ readback capability
#        Enhanced Mode includes same features as Standard, but adds 48 additional event sense inputs connected to each
#          I/O point of ports 0-5.  Allows event driven interrupts to be generated.
#   5) Interrupt Handler; must be either "COS" or "LEVEL"
#        COS (Change Of State) triggers on either low-high or high-low transitions
#        Not used in Standard Mode.
#   6) User Function
#   7) Interrupt Vector; must be between 0x0 and 0xFF
#   8) Event Register; must be between 0x0 and 0xFFF
#   9) Debounce Register; must be between 0x0 and 0xFF
#avme470Create("bio0", carrier1, 2, "STANDARD", "LEVEL", 0, 0, 0, 0)

# End of file
