Startup and IOC configuration

How the layers fit together

ECMC runs inside an EPICS IOC process. EPICS records expose commands and readbacks to clients; the ECMC realtime thread executes motion and logic at the configured EC_RATE. ecmccfg supplies the scripts, templates and YAML loading that build this configuration during startup.

graph TD CLIENT["Operator panels and clients
caQtDM, Python, scans"] CONFIG["Startup configuration: ecmccfg
IOC-shell scripts, hardware snippets, axis and PLC YAML"] subgraph EPICS_IOC RECORDS["EPICS records and PVs
Motor records, axis records, I/O and diagnostics"] BRIDGE["EPICS device support and asyn
ecmcMotorRecord and the ECMC asyn port"] RT["ECMC realtime engine in C++
Trajectory, encoders, control, drive state and monitoring
PLCs, plugins and buffered data"] IO["I/O mapping and selected backend
EtherCAT process image and userspace API, or memory I/O"] end MASTER["Linux kernel
IgH EtherCAT master and Ethernet driver"] HARDWARE["EtherCAT terminals and connected hardware
Drives, encoders, digital and analog I/O"] SIM["SIM=1: simulated I/O
External models or injected feedback"] CLIENT -->|CA / PVA commands and subscriptions| RECORDS RECORDS --> BRIDGE BRIDGE -->|Requests and readbacks| RT RT -->|Cyclic inputs and outputs| IO IO -->|Physical EtherCAT| MASTER MASTER --> HARDWARE IO -->|Memory backend| SIM CONFIG -.->|Loads record definitions| RECORDS CONFIG -.->|Cfg commands create and link objects| RT

Solid connections show the runtime layers; commands travel toward the hardware and state/feedback returns toward the clients. Dashed arrows show startup configuration. The diagram groups responsibilities rather than showing the execution order of every function.

The motor record and normal EPICS record processing run outside the ECMC realtime cycle. Requests pass into the engine, and state is published back to EPICS. PV update rates can therefore differ from EC_RATE. Encoder filters, trajectory generation, monitoring and the configured cyclic logic execute in the engine; the position-control loop can run in ECMC or in the drive, depending on drive mode.

With SIM=1, memory I/O replaces the physical EtherCAT path. A separate model or injected values supply feedback; the motor dynamics are not generated by the backend itself. With MASTER_ID=-1, no EtherCAT master is claimed, which is useful for virtual axes and logic without bus hardware.

What startup builds

  1. require ecmccfg loads ECMC and prepares the asyn port, selected I/O backend and cycle rate.
  2. addSlave.cmd declares hardware and process-data mappings and loads slave PVs. applyComponent.cmd applies motor, encoder or other device settings.
  3. loadYamlAxis.cmd and the PLC loaders validate and render YAML into configuration commands and record loading. These create the runtime objects and link them to I/O entries.
  4. finalize.cmd / setAppMode.cmd validate the configuration and start ECMC runtime. iocInit initializes EPICS records and completes IOC startup. Their relative order follows START_EPICS_FIRST; scalar SDORT objects automatically select EPICS first so autosave can restore before activation. Motion readiness is controlled by the startup gate.

startup.cmd

startup.cmd takes the following arguments:

 Arguments
 [optional]
 ECMC_VER          = 11.1.1 (default in startup.cmd; override for your installation)
 EthercatMC_VER    = 3.0.2 (obsolete)
 INIT              = initAll
 MASTER_ID         = 0 <-- put negative number to disable master, aka non ec-mode
 SIM               = 0/1, default 0. Use typed memory I/O instead of physical EtherCAT
 SCRIPTEXEC        = iocshLoad
 NAMING            = mXsXXX (default), ClassicNaming, ESSnaming
 EC_RATE           = 1000
 MODE              = FULL / DAQ / NO_MR
    FULL:  Init ecmc with support for both motion and DAQ (DEFAULT)
    DAQ:   Init ecmc with support for only daq (not motion)
    NO_MR: Init ecmc with support for motion (without motor record) and DAQ
 PVA               = YES / NO
 TMP_DIR           = directory for temporary files
 ENG_MODE          = 1/0. If ENG_MODE is set then PVs used for commissioning will be available
 EC_TOOL_PATH      = Path to ethercat tool defaults to ethercat tool in ECmasterECMC_DIR,
 otherwise            "/opt/etherlab/bin/ethercat"
 MAX_PARAM_COUNT   = Maximum asyn param count, defaults to 1675
 ECMC_ASYN_PORT_MAX_PARAMS = Explicit capacity override; takes precedence over MAX_PARAM_COUNT
 ECMC_ASYN_TRACE_MASK = asyn trace mask for the main ecmc asyn port, defaults to 0x1
 ECMC_STARTUP_GATE = 1/0, default 0. Set explicitly to 1 to hold motion until complete
                     native-axis and loaded motor-record startup.
 START_EPICS_FIRST = 1/0, default 0. Start EPICS records before ECMC runtime
                     and EtherCAT when set to 1. Scalar SDORT objects also
                     select this order automatically, even when this is 0.

 [set by module]
 ECMC_CONFIG_ROOT       = root directory of ${MODULE}
 ECMC_CONFIG_DB         = database directory of ${MODULE}
 EthercatMC_DB          = database directory of EthercatMC
 ECMC_EC_MASTER_ID      = EtherCAT master id in use (for use in later scripts)
 ECMC_EC_SAMPLE_RATE    = EtherCAT bus sampling rate [Hz] (1000 default)
 ECMC_EC_SAMPLE_RATE_MS = EtherCAT bus sampling rate [ms] (1 default)
 ECMC_MODE              = ecmc mode. FULL/DAQ, Defaults to FULL
 ECMC_PVA               = use pva, default NO
 ECMC_SUPPORT_MOTION    = Variable to be used to block use of motion (""/empty=support motion or "#-"=disable motion)
 ECMC_TMP_DIR           = directory for temporary files, defaults to "/tmp/${IOC}/EcMaster_${ECMC_EC_MASTER_ID}}/"
 ECMC_EC_TOOL_PATH      = path to ethercat tool
 ECMC_SAMPLE_RATE_MS    = current record update rate in milliseconds
 ECMC_SAMPLE_RATE_MS_ORIGINAL = ECMC_SAMPLE_RATE_MS (used for restore to default if ECMC_SAMPLE_RATE_MS is changed)

Normally these arguments are set when the module is required:

require ecmccfg "ENG_MODE=1,MASTER_ID=2"

Simulation backend

Use require ecmccfg "MASTER_ID=0,SIM=1,EC_RATE=1000" to select the memory backend before slave configuration. SIM=0 is the default; MASTER_ID=-1 retains masterless behavior. Feedback comes from separate models or PV writes. See Simulation backend (SIM=1) for generated SIM PVs, Python models, GUI controls and limitations.

Asyn trace output

The main ecmc asyn port trace mask is set in initAll.cmd:

asynSetTraceMask(${ECMC_ASYN_PORT}, -1, ${ECMC_ASYN_TRACE_MASK=0x1})

The asynSetTraceMask(...) command above can also be copied and executed directly in iocsh to change the trace mask for a running IOC.

The default value is 0x1. To revert to the old, more verbose asyn trace information, set ECMC_ASYN_TRACE_MASK when loading ecmccfg:

require ecmccfg "ECMC_ASYN_TRACE_MASK=0x41"

Start EPICS before EtherCAT

Without scalar SDORT objects, the default, START_EPICS_FIRST=0, preserves the traditional startup order: ECMC enters runtime and starts EtherCAT before iocInit completes. Configuring scalar SDORT objects automatically selects EPICS first, as described below.

Scalar SDORT objects configuredSTART_EPICS_FIRSTEffective order
No0 (default)ECMC/EtherCAT first
No1EPICS first
Yes0 or 1EPICS first, automatically

Set START_EPICS_FIRST=1 when EPICS records must be initialized before ECMC runtime and EtherCAT start:

require ecmccfg "START_EPICS_FIRST=1"

In this mode, startup.cmd allows iocInit to reach the IOC-running state and then schedules ECMC startup asynchronously. The worker waits for ECMC_EC_STABILIZATION_TIME seconds (default 2) before executing Cfg.SetAppMode(1).

This ordering can be useful with EPICS autosave. It gives autosave restore and record/device-support initialization an opportunity to apply restored PV values before the realtime thread and EtherCAT bus start. For example:

require ecmccfg "START_EPICS_FIRST=1,ECMC_EC_STABILIZATION_TIME=5"

The delay is a time window, not a completion handshake with autosave. Select a delay long enough for the IOC’s restore workload and verify the startup log and restored values. For ECMC builds with the complete motor-record startup gate, set ECMC_STARTUP_GATE=1 to hold cyclic motion producers until the motor handshake completes; do not rely on the fixed delay alone. Older builds need an explicit restore-complete mechanism for this guarantee.

PLCs can use epics_get_started(), ec_get_started(), and system_get_started() to inspect startup readiness. See PLC functions.

Automatic EPICS-first startup with scalar SDORT

Loading a scalar SDO through addEcSdoRT.cmd (BYTE_SIZE omitted or 0) automatically defers ECMC runtime and master activation until after EPICS initialization. This applies even when no saved value exists or WRITE_ON_VAL=0. There is no separate startup mode or additional flag to select. Static EcAddSdo* settings alone and byte-array SDORT objects do not trigger this automatic ordering.

The sequence is:

  1. Configure hardware, component defaults and SDORT objects; load EPICS records.
  2. Initialize EPICS and restore saved StartupData_ waveforms in autosave pass 1. The driver collects valid saved requests through its initialization hook.
  3. After the IOC is running, the startup worker starts ECMC. Restored writes are appended last to EtherLab’s startup SDO list, overriding component defaults. An untouched SDO appends no write, so its configured default applies.
  4. EtherLab applies the startup list in PREOP. Once each SDO’s own slave reaches OP, SDORT uploads and verifies its final value. Other, unconfigured slaves may remain PREOP.
  5. Release motion and ordinary PLC execution after verification and startup readiness checks pass. A verification failure keeps them held.

ECMC_STARTUP_GATE controls motion readiness; it does not select which starts first. Pending startup SDOs enforce the verification/readiness hold even with ECMC_STARTUP_GATE=0. With no pending SDOs, setting it to 1 still enables the general axis/motor-record startup gate described below.

See scalar SDO startup restore for the request file, manual Val/WrtCmd interface and WRITE_ON_VAL option.

Complete startup gate

Set ECMC_STARTUP_GATE=1 before setAppMode.cmd/finalize.cmd runs. With matching ECMC startup-restore support, the gate waits for IOC readiness, bus stabilization, native axis initialization, and startup of each loaded motor record, including any requested position load and its RT acknowledgement. Axes with no loaded motor record have no motor-record handshake to wait for.

Ordinary PLC/plugin cyclic execution and other motion producers stay held, drives stay disabled, and early execute/enable commands are rejected. STOP, disable, coordinate loading and status polling remain available. The dedicated safety plugin and bus I/O continue; configuration/enter-RT initialization hooks still prepare runtime, with their supported motion requests held as well. Gate 0 selects legacy startup when there are no pending startup SDOs; pending SDO verification still enforces the startup hold.

See motor position and soft-limit autosave for the restore configuration and the narrow startup COMM-alarm workaround.

EtherCAT startup timeout

When EtherCAT startup fails with messages like Max wait time 30 second(s), increase the maximum EtherCAT startup wait using the EC_TIMEOUT startup parameter. The value is in seconds and defaults to 45 seconds in ecmccfg:

require ecmccfg "EC_TIMEOUT=100"

startup.cmd applies this parameter with Cfg.SetEcStartupTimeout(${EC_TIMEOUT=45}). The underlying ecmc default is 30 seconds when no timeout is explicitly configured.

You can also override the timeout after loading ecmccfg, before ecmc enters runtime:

ecmcConfigOrDie "Cfg.SetEcStartupTimeout(100)"

Place the command after require ecmccfg or startup.cmd has loaded ecmc, but before setAppMode.cmd or finalize.cmd starts runtime. In the normal startup flow, this means before iocInit, because finalize.cmd is typically registered to run at init.

This is different from ECMC_EC_STARTUP_DELAY. That macro is used by setAppMode.cmd for Cfg.EcSetDelayECOkAtStartup(...) and controls a startup delay/minimum wait, not the maximum OP-state timeout.

MASTER_ID=-1

Setting MASTER_ID=-1 starts ecmc without claiming an EtherCAT master. This is the supported master-less or non-EtherCAT mode.

Typical use cases:

  • PLC-only IOC logic
  • data-storage workflows without fieldbus hardware
  • plugin development or testing without EtherCAT
  • startup and database testing on systems without realtime EtherCAT access

Example:

require ecmccfg "MASTER_ID=-1,ENG_MODE=1"

In this mode, EtherCAT-dependent hardware setup scripts such as addSlave.cmd are normally not used, but other parts of ecmc still work, for example:

  • PLCs loaded with loadPLCFile.cmd or loadYamlPlc.cmd
  • data storage created with addDataStorage.cmd
  • PLC variables exposed as EPICS PVs
  • plugins that do not require an active EtherCAT master

iocsh startup

ecmc needs to be started with root privileges (or with a user in the realtime group), otherwise ecmc might segfault.

Startup guides and reference