## PAD RTEMS startup script for Laser PAD in RF Hut PADLAN9118_LSR app

setenv("PADMCGRP", "239.219.0.2")   # PAD multicasting group / ioc-in20-rf01-padg
setenv("IPADDR1","172.27.28.52",1)
setenv("NETMASK1","255.255.255.0",1)
setenv("PADSLOT","1",1) # Must match llrf*.*_substitutions
setenv("LOCAs","IN20",1)
setenv("UNITs","1",1)
#addpath("/boot/g/lcls/users/strauman/epics/dev/app/bin/RTEMS-uC5282/:",1)

wdStart(20)

# Debugger stub daemon
ld("rtems-gdb-stub.obj")

# Dedicated ethernet + network stack driver
ld("lanIpBasic_ln9.obj")  #check that it finds this 

# turning on lanIpDebug shows you all the ARP requests on the console
lanIpDebug    = 0  
lanIpSetup(getenv("IPADDR1"),getenv("NETMASK1"),0,0)

chdir("../..")
ld("bin/RTEMS-uC5282/padLan9118LsrApp.obj")

epicsEnvSet("EPICS_CA_MAX_ARRAY_BYTES","1000000")

lsmod()

dbLoadDatabase("dbd/pad4App.dbd")

pad4App_registerRecordDeviceDriver(pdbbase)

drvPadScalFlag=4
drvPadLan9118DacqFlag=2

## Load record instances
dbLoadTemplate("db/padLSR.lsr_template")
dbLoadRecords("db/iocAdmin.db","IOC=EIOC:IN20:RD02")


# New: pre maps /data to /u1/lcls/epics/ioc/data/<hostname>
dbRestore("/data/EIOC-IN20-RD02.sav")

iocInit()

# force scalar waveforms to read (once)
dbpf("LASR:IN20:1:LSR_0_SCL_WF.PROC","1")
dbpf("LASR:IN20:1:LSR_1_SCL_WF.PROC","1")
dbpf("LASR:IN20:1:LSR_2_SLI_WF.PROC","1")
dbpf("LASR:IN20:1:LSR_2_SLQ_WF.PROC","1")
dbpf("LASR:IN20:1:LSR_3_SLI_WF.PROC","1")
dbpf("LASR:IN20:1:LSR_3_SLQ_WF.PROC","1")

#override what's set for the offset to the start of the data here
#padSetSampleOffset(channel, sample, n) usage: sample is the sample number (0 for most, can be 1 if BPH)
#                                     n is the number of 16 bit words to read
#                                     after first 3 clock cycless.
dbpf("LASR:IN20:1:LSR_4_OFST","0")
dbpf("LASR:IN20:1:LSR_5_OFST","0")
dbpf("LASR:IN20:1:LSR_6_OFST","0")
dbpf("LASR:IN20:1:LSR_7_OFST","0")

#override what's set for the size of the data here
#padSetSampleSize(channel, sample, n) usage: sample is the sample number (0 for most, can be 1 if BPH)
#                                   n must be a multiple of 4 since
#                                   data in quadruples of (Q1,I2,Q3,I4) read
#                                   (see comments in drvPad.c for more info)
dbpf("LASR:IN20:1:LSR_4_SIZE","65536")
dbpf("LASR:IN20:1:LSR_5_SIZE","65536")
dbpf("LASR:IN20:1:LSR_6_SIZE","65536")
dbpf("LASR:IN20:1:LSR_7_SIZE","65536")

dbpf("LASR:IN20:1:LSR_0_OFST.PROC","1")
dbpf("LASR:IN20:1:LSR_1_OFST.PROC","1")
dbpf("LASR:IN20:1:LSR_2_OFST.PROC","1")
dbpf("LASR:IN20:1:LSR_3_OFST.PROC","1")
dbpf("LASR:IN20:1:LSR_0_SIZE.PROC","1")
dbpf("LASR:IN20:1:LSR_1_SIZE.PROC","1")
dbpf("LASR:IN20:1:LSR_2_SIZE.PROC","1")
dbpf("LASR:IN20:1:LSR_3_SIZE.PROC","1")

## Start any sequence programs. Note: RTEMS Cexp syntax
# Skip state machine for nonlin test
################ 5/12/8: MOST IMPORTANT TODAY: This can't run for IOC
# to see padProtoHost cmds
#seq(&sncpadlan9118,"PRIM=LASR,LOCA=IN20,UNIT=1,PAD=LSR")
seq(&trgDetector, "PRIM=LASR,LOCA=IN20,UNIT=1,PAD=LSR")

padProtoDebug=0
padStreamFlag=2
drvPadLan9118Flag=2
drvPadLan9118GetdataFlag=2
drvPadGenFlag=2
drvPadCbFlag=2
