## Example RTEMS startup script

## You may have to change pac to something else
## everywhere it appears in this file

#< envPaths

# Load Application Object File
chdir("../..")
ld("bin/RTEMS-uC5282/pac.obj")


## Register all support components
dbLoadDatabase("dbd/pac.dbd")
pac_registerRecordDeviceDriver(pdbbase) 


# ------------------------------------------------------------------------
## Set common environment variables
epicsEnvSet("IOC_NAME",  "LCLSDEV-03")
epicsEnvSet("LOCA_NAME", "RFLAB")

# Setup for iocAdmin:
epicsEnvSet("ENGINEER","Ron Akre")
epicsEnvSet("LOCATION","RF Test Facility")
# ------------------------------------------------------------------------

# Adding to the useful abbreviations. NB: no () here (that executes the cmd!)
rr = bsp_reset




## Load record instances
## Load iocAdmin database which reports on ioc health
dbLoadRecords( "db/iocAdmin.db", "IOC=LCLSDEV_03")

## Load database for autosave/restore status pv's
dbLoadRecords("db/save_restoreStatus.db","P=LCLSDEV_03:")

# New database from Steph
dbLoadRecords("db/accl_llrf.db")

# Hey, don't forget the PAC PVs
dbLoadRecords("db/pacApp.db","dev=pactest")

## ==============================================
## Begin Part 1. New method for autosave and restore
## ==============================================
save_restoreSet_status_prefix("LCLSDEV_03:")
save_restoreSet_IncompleteSetsOk(1)
save_restoreSet_DatedBackupFiles(1)
## ========================================================================
## From pre_st.cmd, /data gets mapped to /u1/lcls/epics/ioc/data/<hostname>
## ========================================================================
# Where the save request files will live.
set_requestfile_path("/data/autosave-req")

## ==============================================
# Where the data will be saved.
## ==============================================
set_savefile_path("/data","autosave")
## ==============================================


## =============================================================
## Decide what is saved by specifying it in the EPICS databases
## =============================================================
set_pass0_restoreFile("info_positions.sav")
set_pass1_restoreFile("info_positions.sav")


## =============================================
## Load Access Security File
## caPutLog now depends on this running.
## =============================================
asSetFilename("db/llrfPAC.acf")




# Go EPICS (Start the EPICS Kernel)
iocInit()



## ==============================================
## Begin Part 2. New method for autosave and restore
## ==============================================
## Turn on caPutLogging:
## Log values only on change to the iocLogServer:
## =====================================================
caPutLogInit("134.79.219.12:7004")
caPutLogShow(2)
## ===========================================================
## Start autosave routines to save our data
## ===========================================================
## optional, needed if the IOC takes a very long time to boot.
## ===========================================================
epicsThreadSleep( 1.0)
## ===========================================================
## Handle autosave 'commands' contained in loaded databases.
## change directory to ioc startup area to run makeAutosaveFiles()
## ===========================================================
printf("making autosave files in: /data/autosave-req\n")
chdir("/data/autosave-req")
iocshCmd("makeAutosaveFiles()")
## ===========================================================

## Explaining the args:
## you save the the settings every 30 sec
## to a file (if they change more freq, the values are kept in RAM
## and so if IOC reboots, you risk restoring data stale by up to 30 sec
#create_monitor_set("info_settings.req", 30, "U=")
create_monitor_set("info_positions.req", 10, "U=")

### Let's do some spying on this CPU:
#iocshCmd("spy(2)")
