iocInit() for For advanced or challenge users
The iocInit() command is the critical point in the startup script. While you typically just call iocInit, it’s actually implemented as two distinct phases internally: iocBuild and iocRun. The iocInit command executes both of these phases sequentially to bring the IOC fully online. Understanding these phases provides a deeper insight into the startup sequence.
The initialization process, as performed by iocInit (which encompasses iocBuild followed by iocRun), consists of the following detailed steps:
Phase 1: iocBuild (Building the IOC’s Structure - Still Quiescent)
This phase sets up the core environment and loads/initializes the static configuration but does not yet start the main processing or I/O threads.
-
Configure Main Thread:
- The main thread’s execution environment is prepared.
initHookAtIocBuildis announced (allowing registered functions to run at this specific point).- The message “Starting iocInit” is logged.
- On Unix, signals like
SIGHUPare configured to be ignored, preventing unexpected shutdown. initHookAtBeginningis announced.
-
General Purpose Modules:
coreReleaseis called, typically printing the EPICS Base version.taskwdInitis called to start the task watchdog system, which monitors other tasks.callbackInitis called to start the general-purpose callback tasks.initHookAfterCallbackInitis announced.
-
Channel Access Links:
dbCaLinkInitinitializes the module for handling database channel access links. Its task is not started yet.initHookAfterCaLinkInitis announced.
-
Driver Support:
initDrvSupis called. This routine find all the hardware drivers so they are ready to use. The initDrvSup function finds each driver’s info and runs its setup code.initHookAfterInitDrvSupis announced.
-
Record Support:
initRecSupis called. This routine finds each record support entry table and calls the init routine for each record type.initHookAfterInitRecSupis announced.
-
Device Support (Initial Call):
initDevSupis called for the first time. This routine looks up each device support entry table and calls their init routine, indicating this is the initial call.initHookAfterInitDevSupis announced.
-
Database Records:
initDatabaseis called, making three passes over the database performing the following:- Pass 1: Initializes record fields (like
RSET,RDES,MLOK,MLIS,PACT,DSET) for each record and calls record support’sinit_record. - Pass 2: Converts
PV_LINKinto eitherDB_LINK(if the target PV is in the same IOC) orCA_LINK(if the target is remote) and call any extended device support’sadd_recordroutine. - Pass 3: Calls record support’s
init_recordfunction again (second pass).
- Pass 1: Initializes record fields (like
- An exit routine
epicsAtExitis registered to handle database shutdown when the IOC exits. dbLockInitRecordsis called to set up the database lock sets.dbBkptInitinitializes the database debugging module.initHookAfterInitDatabaseis announced.
-
Device Support (Final Call):
initDevSupis called for a second and final time. This allows device support to perform any final setup that requires the database records to be fully initialized and linked.initHookAfterFinishDevSupis announced.
-
Scanning and Access Security:
scanInitinitializes the periodic, event, and I/O event scanners, but the scan threads are created in a state where they cannot process records yet.asInitinitializes the access security. If this fails, IOC initialization is aborted.dbProcessNotifyInitinitializes support for process notification.- After a short delay,
initHookAfterScanInitis announced.
-
Initial Processing:
initialProcessprocesses all reacords that havePINIset toYESinitHookAfterInitialProcessis announced.
-
Channel Access Server (Initial Setup):
rsrv_initis called to start the Channel Access server, but its tasks are not yet allowed to run, so it doesn’t announce its presence on the network.initHookAfterCaServerInitis announced.
At this point, the iocBuild phase is complete. So, the IOC has been fully initialized, but it is still in a quiescent state. initHookAfterIocBuilt is announced. If you had started with iocBuild, the command would finish here.
Phase 2: iocRun (Bringing the IOC Online)
This phase activates the threads and processes that allow the IOC to actively monitor hardware, process records, and communicate via Channel Access.
-
Enable Record Processing:
initHookAtIocRunis announced.scanRunis called, which starts the scan threads and sets the global variableinterruptAccepttoTRUE. This variable acts as a flag indicating that the IOC is ready to handle I/O interrupts.dbCaRunis called, which enables the Channel Access link processing task.initHookAfterDatabaseRunningis announced.- If this is the first time
iocRun(oriocInit) is executed,initHookAfterInterruptAcceptis announced.
-
Enable CA Server:
rsrv_runis called. This allows the Channel Access server tasks to begin running and announce the IOC’s presence to the network.initHookAfterCaServerRunningis announced.- If this is the first time,
initHookAtEndis announced. - A command completion message is logged, and
initHookAfterIocRunningis announced.
Once iocInit() (completing both iocBuild and iocRun) finishes, the IOC is “live.” Records configured for scanning will begin processing, Channel Access clients can connect and interact with the PVs, and the IOC is actively monitoring and controlling the connected hardware.