## EVR RTEMS startup script

## Set common environment variables. eg. EPICS_TS_NTP_INET and PORTs
setenv("EPICS_CA_MAX_ARRAY_BYTES","30000")
# by building one obj with everything in it, no lib/... link to ioc/lib/<target> is needed
chdir("../../")
# NOTE: The next 3 prefixes must be the same!
ld("bin/RTEMS-beatnik/evrLab.obj") 

dbLoadDatabase("dbd/evrLab.dbd")

evrLab_registerRecordDeviceDriver(pdbbase)

# Setup environment variables
epicsEnvSet("ENGINEER","Ernest Williams")
epicsEnvSet("LOCATION","B034-201")

## Load record instances
#dbLoadRecords("db/IOC-B34-EV04-evr.db")
#dbLoadRecords("db/IOC-B34-EV04-pattern.db")
#dbLoadRecords("db/IOC-B34-EV04-trig.db")

dbLoadRecords("db/Pattern.db","IOC=IOC:B34:EV04,SYS=SYS0")

## Load EVR record instances
# PMC-Carrier on VME: MRF EVR230
dbLoadRecords("db/EvrPmc.db","EVR=EVR:B34:EV04,CRD=0,SYS=SYS0")
dbLoadRecords("db/PMC-trig.db","IOC=IOC:B34:EV04,LOCA=B84,UNIT=04,SYS=SYS0")


###########################
## Setup autosave ##
###########################
## Setup autosave/restore will write to ioc-b34-ev04 directory
save_restoreSet_status_prefix("IOC:B34:EV04:")
dbLoadRecords("db/save_restoreStatus.db","P=IOC:B34:EV04:")
save_restoreSet_IncompleteSetsOk(1)
save_restoreSet_DatedBackupFiles(1)

set_requestfile_path("/data/autosave-req")
set_requestfile_path("./")
set_savefile_path("/data","autosave")

## Restore datasets
set_pass0_restoreFile("info_settings.sav")
set_pass1_restoreFile("info_settings.sav")
set_pass0_restoreFile("info_positions.sav")
set_pass1_restoreFile("info_positions.sav")


# =========================================================
# iocAdmin Package 
# =========================================================
dbLoadRecords("db/iocAdminRTEMS.db","IOC=IOC:B34:EV04")
dbLoadRecords("db/iocAdminScanMon.db","IOC=IOC:B34:EV04")

# The following database is a result of a python parser
# which looks at RELEASE_SITE and RELEASE to discover
# versions of software your IOC is referencing
# The python parser is part of iocAdmin
#dbLoadRecords("db/iocRelease.db","IOC=${IOC})
dbLoadRecords("db/iocRelease.db","IOC=IOC:B34:EV04")
# ==========================================================


# 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
bspExtVerbosity=0

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

evrTimeFlag=0

iocInit() # after h/w initialisations

## Start autosaving datasets
cd("/data/autosave-req")
makeAutosaveFiles()
create_monitor_set("info_settings.req", 30)
create_monitor_set("info_positions.req", 30)

bspExtVerbosity=1




