## EVG IOC RTEMS startup script

setenv("EPICS_CA_MAX_ARRAY_BYTES", "30000")
setenv("EPICS_CA_ADDR_LIST", "mccdev")
# For iocAdmin
setenv("ENGINEER","Stephanie Allison")
setenv("LOCATION","B34 Second Floor Timing Test Area")

# Set common environment variables. eg. EPICS_TS_NTP_INET and PORTs
< /boot/g/lcls/epics/iocCommon/All/Dev/pre_st.cmd

# by building one obj with everything in it, no lib/... link to ioc/lib/<target> is needed
chdir("../../")
ld("bin/RTEMS-beatnik/evg.obj")

dbLoadDatabase("dbd/evg.dbd")

evg_registerRecordDeviceDriver(pdbbase) 

# Allows gdb to attach to this target
#rtems_gdb_start(0,0)

## Load record instances
dbLoadRecords("db/evg.db","DEV=EVG:XL00:EV01,CARD=0,DISABLE=0")
dbLoadRecords("db/evgPatternXL00.db")
dbLoadRecords("db/iocAdminRTEMS.db","IOC=IOC:XL00:EV01")
dbLoadRecords("db/iocRelease.db","IOC=IOC:XL00:EV01")

bspExtVerbosity=0

EgConfigure(0,0x280000,1)
#ErConfigure(0,0x300000,0x60,4,0)

# From Till Straumann (for RTEMS 4.9.1 upgrade):
# This should set the VME chip into a mode where it 
# surrenders the VME bus after every transaction.
# This means that the master has to rearbitrate for the bus for every cycle 
# (which slows things down).
#
# The faster setting I had enabled would let the master hold on to the bus 
# until some other master requests it.
*(long*)(vmeTsi148RegBase + 0x234) &= ~ 0x18

# Set Cexp priority one lower than pnetTask.
Cexp_priority_orig = 100
rtems_task_set_priority(0, 101, &Cexp_priority_orig)

iocInit() # after h/w initialisations
bspExtVerbosity=1
dbpf("EVG:XL00:EV01:CTRL.DESC","Development")
dbpf("IOC:XL00:EV01:SEQSEND","On")
