DC synchronization
Slave-level Distributed Clocks (DC) configuration. Access it through the slave.dc() instance obtained from SlaveDC.
In most scenarios, use master.configure_dc_all() to configure all DC slaves in one call.
Slave-level methods are for scenarios where individual slaves need different parameters.
Read-only properties
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| DC state | slave.has_dc() | Option<bool> | read-only | Whether the ESC hardware supports DC (None = the slave structure cannot be read, which does not mean there is no DC) |
| slave.dc().has_esi_dc_sync() | bool | read-only | Whether the ESI declares DC synchronization for this slave (OpMode/AssignActivate non-zero) | |
| slave.dc().esi_dc_sync_mode() | i32 | read-only | DC synchronization tier declared by the ESI: 3 = DC-Sync0 + SYNC1; 2 = DC-Sync0 only; 0 = not declared / undeterminable | |
| slave.dc_active() | u16 | read-only | Landed value of 0x0980 (AssignActivate). 0 = DC not enabled; 0x0300 is only a common landed value and not the criterion for "armed" — whether armed is reported by dc().dc_sync0_armed() (underlying tri-state), and whether synchronized by dc().dc_sync_window().in_sync() | |
| DC time | slave.dc_cycle0() | i32 | read-only | Current SYNC0 cycle (nanoseconds) |
| slave.dc_cycle1() | i32 | read-only | Current SYNC1 cycle (nanoseconds) | |
| slave.dc_shift() | i32 | read-only | Current phase shift (nanoseconds) | |
| slave.dc().propagation_delay() | i32 | read-only | Propagation delay of a frame from the master to this slave (nanoseconds) | |
| DC topology | slave.dc_next() / dc_previous() | u16 | read-only | Index of the next / previous slave in the DC chain |
| slave.dc_parent_port() | i32 | read-only | Compatibility entry for parent_port(): 0..3 = parent port, -1 = unknown or invalid parameter | |
| slave.dc_receive_time_a/b/c/d() | i32 | read-only | Receive time per port (nanoseconds) |
has_dc() reflects only the ESC hardware bit and does not mean the application layer uses DC. Some slaves report DC capable in the ESC but
their ESI does not declare a DC OpMode; in that case run FreeRun / SM-Sync, because forcing DC makes the slave refuse to enter OP.
has_dc() returns Option<bool>: Some(true) = explicitly supported, Some(false) = explicitly unsupported,
None = the slave structure cannot be read (master not created / invalid slave index) — do not treat None as "no DC" when judging capability.
A safe pattern before enabling DC:
if slave.has_dc() == Some(true) && slave.dc().has_esi_dc_sync() {
slave.dc().configure(1_000_000, 0, None)?;
}
DcSyncMode::FreeRun can be queried, but it is the slave's local clock: it is not DC enabled and not synchronized. DC synchronization = SYNC0 (0x1C32/0x1C33 = 2) plus dc().dc_sync0_armed() == Some(true) (armed); whether the clocks across the whole network have converged is reported by dc().dc_sync_window().in_sync(). The dc_active() in 0x0300 is only a common landed value, not a criterion. in_sync is always false under FreeRun.
DC synchronization types declared by the ESI
has_dc() answers only "does the ESC hardware support DC"; esi_dc_sync_mode() answers "which DC synchronization tier the vendor requires for this slave in the ESI". The tier decides whether SYNC1 can be enabled:
| Value | Meaning | Typical ESI |
|---|---|---|
3 | ESI declares DC-Sync0 + SYNC1: AssignActivate contains the SYNC1 enable bit 0x0400 (e.g. #x700) | Beckhoff EL7411 |
2 | ESI declares DC-Sync0 only: AssignActivate is non-zero but does not contain 0x0400 (e.g. #x300) | EL7041 / Ezi-SERVO2 |
0 | ESI does not declare DC, or it is undeterminable (ESI not bound / cannot be read) | EK1100 / EK1110 / EL6022 / GCAN-8200 |
There is only one rule: DC-Sync01 can be requested only when the value is 3; with 2 only DC-Sync0 is possible. Treating 2 as 3 (forcing SYNC1) makes a slave that declares only Sync0 refuse to enter OP, and it does not necessarily report an AL status code.
ESI-declared value ≠ landed value: slave.dc().esi_dc_assign_activate() returns a three-state EsiDeclaredValue { state, value }. With state = Declared, value is the raw 16-bit SYNC0 <Dc><OpMode><AssignActivate> declared in the ESI AssignActivate (Declared is a legitimate declared value under 0); state = NotDeclared means the ESI does not declare it (take the fallback); state = Unreadable means unbound / bad argument / cannot be read — the last two are not the same thing, do not collapse them. It is not the landed value written into the slave's 0x0980 — read slave.dc_active() (or slave.dc().dc_assign_activate()) for that.
How the three entry points divide the work:
dc_sync_mode_from_esi()— the raw underlying value, keeping negative values such as-1(the ESI declares no<Dc>) /-2(no ESI bound), for callers that need to distinguish "explicitly no DC" from "cannot be read";esi_dc_sync_mode()— the normalized public view:>= 2is returned as is (2/3), while0/1and negative values all yield0. Normalization happens only here; upper layers must not parse the raw value themselves;has_esi_dc_sync()— a Boolean capability judgment; when>= 0it is equivalent to>= 2; when the underlying call returns-2(not bound) it degrades conservatively tohas_dc()(when the hardware bit also cannot be read, it is treated as "unsupported" — this function returns an availability conclusion, not a raw reading).
Use esi_dc_sync_mode() when you need to know exactly "which tier the ESI declares"; use has_esi_dc_sync() when you need "do not wrongly turn DC off while unbound".
Example:
let dc = slave.dc();
let mode = dc.esi_dc_sync_mode();
if slave.has_dc() == Some(true) && dc.has_esi_dc_sync() {
if mode == 3 {
dc.configure_mode(DcSyncMode::DcSynchron01, 1_000_000, 1_000_000, None)?; // SYNC0 + SYNC1
} else {
dc.configure_mode(DcSyncMode::DcSynchron, 1_000_000, 0, None)?; // SYNC0 only
}
}
Configuration methods
dc().configure()
pub fn configure(&self, sync0_ns: u32, sync1_ns: u32, shift_ns: Option<i32>) -> Result<()>
Configures DC synchronization for the slave. All parameter units are nanoseconds (ns).
Parameters:
sync0_ns(u32) — SYNC0 cycle (nanoseconds); 0 means disarm SYNC0 (back to FreeRun)sync1_ns(u32) — SYNC1 increment time (nanoseconds); 0 means SYNC0 onlyshift_ns(Option<i32>) — phase shift (nanoseconds):None= phase not specified, resolved by the single underlying source (ESI explicit → user explicit → default 70%);Some(0)and negative values are both user-explicit phases and are sent as is (Some(0)is the literal 0 phase and does not fall back to 70%)
Example:
slave.dc().configure(1_000_000, 0, None)?; // SYNC0 = 1ms, phase uses default resolution
slave.dc().configure(1_000_000, 0, Some(0))?; // SYNC0 = 1ms, phase 0 ns
- Only
Nonetriggers resolution by precedence: ESIShiftTimeSync0not 0 → user explicit → default 「1 cycle + 70%」sync0_ns * 70 / 100(1 ms → 700 µs). - The phase is only a phase shift and is not combined with software propagation delay compensation; the propagation delay is corrected by the ESC in hardware according to
0x0928. Some(0)is the literal 0 phase, not "unspecified", and does not fall back to 70%; passNonefor the default 70% (underlying sentinelDC_SHIFT_UNSPECIFIED=i32::MIN).sync0_ns = 0means disarm SYNC0 (FreeRun), not a 「0 ns cycle」. Slaves with PDOs write0x1C32:01/0x1C33:01back to 0 to clear leftovers from the previous session (otherwise the transition to SafeOp may report AL=0x002D); when SM2/SM3 are not mapped, the write is postponed until mapping completes.- On hot-plug recovery the SDK re-arms the DC start point and activates SYNC0 automatically (the start point is based on the re-read slave DC time). The phase comes from the same source as the first time (the same resolution result, phase only) and does not jump on re-arming; if the reference clock fails, it is reselected immediately.
dc().configure_mode()
pub fn configure_mode(&self, mode: DcSyncMode, sync0_ns: u32, sync1_ns: u32, shift_ns: Option<i32>) -> Result<bool>
Configures DC according to the synchronization mode (ETG.1020). Returns Ok(true) = this configuration took effect; Ok(false) = the underlying layer did not land it (the caller may report this truthfully and must not treat it as success); Err = the call failed.
Parameters:
mode(DcSyncMode) — DC synchronization modesync0_ns(u32) — SYNC0 cycle (nanoseconds), used only in DcSynchron modesync1_ns(u32) — SYNC1 cycle (nanoseconds), used only in DcSynchron modeshift_ns(Option<i32>) — phase shift (nanoseconds), used only in DcSynchron mode;None= unspecified (resolved by precedence),Some(0)and negative values take effect as is
Related structures:
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DcSyncMode {
FreeRun = 0, // free run (local clock, not DC synchronization)
SmSynchron = 1, // SM synchronization - triggered by SM events
DcSynchron = 2, // DC synchronization - SYNC0 only
DcSynchron01 = 3, // DC synchronization - SYNC0 + SYNC1
}
Example:
slave.dc().configure_mode(DcSyncMode::DcSynchron, 1_000_000, 0, None)?; // DC SYNC0 = 1ms
slave.dc().configure_mode(DcSyncMode::SmSynchron, 0, 0, None)?; // SM synchronization mode
slave.dc().configure_mode(DcSyncMode::FreeRun, 0, 0, None)?; // free run
dc().current_dc_sync_mode()
pub fn current_dc_sync_mode(&self) -> Option<DcSyncMode>
Gets the current synchronization mode; returns None when it cannot be read (FreeRun is not invented). FreeRun / SmSynchron can be queried, but they are not DC synchronization. DC synchronization is only DcSynchron / DcSynchron01 and requires 0x1C32/0x1C33 = 2 and dc().dc_sync0_armed() == Some(true); whether the whole network has converged is reported by dc().dc_sync_window().in_sync(). dc_active() == 0x0300 is not a criterion (0x0300 is only a common landed value).
Example:
let mode = slave.dc().current_dc_sync_mode();
println!("当前 DC 同步模式: {:?}", mode); // Current DC sync mode: {:?}
dc().disable()
pub fn disable(&self)
Disables DC synchronization for this slave.
slave.set_dc_sync()
pub fn set_dc_sync(&self, sync0_ns: u32, sync1_ns: u32, shift_ns: i32)
The raw DC configuration entry on the slave handle: all parameters are integers, it returns nothing, and it does not report whether the settings were actually landed. The call registers a "user-explicit configuration" intent — later automatic arming does not override it.
Parameters:
sync0_ns(u32) — SYNC0 cycle (nanoseconds);0= disarm SYNC0 (back to FreeRun)sync1_ns(u32) — SYNC1 increment time (nanoseconds);0= SYNC0 onlyshift_ns(i32) — phase shift (nanoseconds), tri-state:DC_SHIFT_UNSPECIFIED(i32::MIN) = not specified, resolved by the single underlying source (ESI explicit → user explicit → default 70%);0= the literal 0 phase; a negative value = an explicit negative phase. The latter two are sent as is
Returns: nothing. The hardware is really rewritten only in the writable configuration phase (in practice every slave is in INIT / PreOp); a call made at runtime registers the intent but does not send it, and no error signal is available. For a landed conclusion use dc().configure_mode() (Ok(false) = not landed) or slave.arm_sync_auto(); to check afterwards use dc().dc_sync0_armed().
Both send the same action: configure() takes the phase as Option<i32> (None means not specified) and is the more commonly used entry; set_dc_sync() is the raw integer form, in which the caller expresses the phase tri-state itself.
slave.arm_sync_auto()
pub fn arm_sync_auto(&self, sync0_ns: u32, sync1_ns: u32, shift_ns: i32) -> SyncArmOutcome
Arms SYNC0 automatically according to the slave's intent. This entry does not register a "user-explicit configuration" intent — it is meant for flows such as automatic startup and hot-plug recovery that "arm once more according to the current capability", and it does not override an existing user intent record; conversely, a slave that already has an "explicit FreeRun" intent on record is not forcibly armed by it.
Parameters:
sync0_ns(u32) — SYNC0 cycle (nanoseconds);0= disarm (this direction is not subject to the contract gate)sync1_ns(u32) — SYNC1 cycle (nanoseconds);0= SYNC0 onlyshift_ns(i32) — phase (nanoseconds), with the same tri-state semantics asset_dc_sync()
Returns: SyncArmOutcome (not a Result); a failure is likewise reported truthfully through the enum:
pub enum SyncArmOutcome {
Armed, // Arming dispatched; if the hardware is already armed the same way, return this tier directly (do not stop / write / activate again)
MasterUnavailable, // The master has no usable context (not open / closing) or the station number is out of range; the intent is unchanged
WriteDeferred, // Not currently in a writable configuration phase (some station has reached SafeOp / OP, or the state cannot be read); nothing was sent this time
DcDisabled, // The configuration contract marks DC as disabled, so automatic sources are refused (explicit user configuration paths are allowed)
ExplicitFreeRun, // This station has recorded an "explicit FreeRun" intent; an automatic source must not override it
Unrecognized(i32), // Unclassified return code
}
impl SyncArmOutcome {
pub fn is_armed(self) -> bool; // true only when Armed
}
Timing preconditions:
- A usable master instance must exist and the slave index must be within the current slave range; otherwise
MasterUnavailable. - Arming (
sync0_ns > 0) is really sent only in the writable configuration phase (in practice every slave is in INIT / PreOp); when it is blocked at runtime (a slave has reached SafeOp / OP, or the state cannot be read) it returnsWriteDeferred: nothing is sent and no intent is registered this time. - Disarming (
sync0_ns == 0) is not bound by the DC contract or a FreeRun intent — recalling a leftover arming is exactly its intended action.
Example:
let outcome = slave.arm_sync_auto(1_000_000, 0, i32::MIN); // Phase not specified
if outcome.is_armed() {
println!("SYNC0 已武装"); // SYNC0 armed
} else {
println!("未武装: {:?}", outcome); // Unarmed: {:?}
}
Sync window diagnostics
dc().sync_window_status()
pub fn sync_window_status(&self) -> Option<SyncWindowStatus>
Gets the detailed status of the slave DC synchronization window. Returns None when DC is unsupported or the read fails.
Returns:
Option<SyncWindowStatus>— sync window status
Related structures:
pub struct SyncWindowStatus {
pub diff_ns: i32, // current time difference (nanoseconds)
pub max_diff_ns: i32, // maximum time difference (nanoseconds)
pub min_diff_ns: i32, // minimum time difference (nanoseconds)
pub in_sync: bool, // whether inside the DC SYNC0 synchronization window. Always false under FreeRun; must not be taken as synchronized
pub out_of_sync_count: u32, // number of times outside the synchronization window
}
If you only need in_sync or sync_time_difference, access them through slave.diagnostics().dc(). is_in_sync() returns Some(true) for "reference clock and SYNC0 armed" (0x092C is by definition N/A for the reference clock itself, and the underlying layer no longer synthesizes an in-sync value; it only means the slave can be treated as synchronized, not that measured convergence was observed). sync_window_status() suits scenarios that need the full statistics.
dc().reset_sync_window_stats()
pub fn reset_sync_window_stats(&self)
Resets the sync window statistics of this slave (max/min time difference, number of times outside the sync window, and so on).
DC diagnostics (per slave)
The per-slave DC diagnostics surface is entirely read-only and reads the diagnostic data already held locally (slave structure / sync window status); it sends no bus frames and may be called from the UI thread or a background thread. When unavailable it always reports None / Unknown with a reason and never substitutes 0 / false.
Method table
| Category | Method | Return type | Read/write | Description |
|---|---|---|---|---|
| DC capability | dc().dc_capability() | DcCapability | read-only | Capability tier: Unknown / None / FreeRunOnly / Sync0 / Sync0AndSync1. Unknown = undeterminable, not "no capability" |
| DC diagnostics | dc().dc_arm_outcome() | Option<DcArmResult> | read-only | Always None: the arming outcome is accounted by the SDK, and this language has no equivalent read entry point; see DC_ARM_OUTCOME_UNAVAILABLE_REASON for the reason. None is not the same as DcArmResult::Unknown |
| DC diagnostics | dc().dc_assign_activate() | Option<u16> | read-only | Landed value of 0x0980. None = no DC / cannot be read; Some(0) = DC capable but currently inactive (FreeRun) |
| DC diagnostics | dc().dc_sync0_cycle_ns() | Option<i32> | read-only | Landed value of 0x09A0. Some(0) = cycle not landed by the underlying layer (not armed / FreeRun), not a 「0 ns cycle」 |
| DC diagnostics | dc().dc_sync1_cycle_ns() | Option<i32> | read-only | Landed value of 0x09A4, same semantics as above |
| DC diagnostics | dc().dc_shift_ns() | Option<i32> | read-only | Current landed DC phase shift (nanoseconds). None = no DC capability / cannot be read; Some(0) = 0 phase landed. Reads the post-write read-back mirror and sends no bus frame |
| DC diagnostics | dc().dc_propagation_delay_ns() | Option<i32> | read-only | Landed value of 0x0928 (ns). None = no DC / cannot be read / raw value negative |
| DC diagnostics | dc().dc_propagation_delay_source() | DcPropagationDelayOrigin | read-only | Propagation delay source tier: Unknown / ZeroNsAmbiguous / NonZeroLandedBaseline. The underlying layer does not distinguish the 0 ns ambiguity (domain root / not measured), so it reports ZeroNsAmbiguous |
| DC diagnostics | dc().dc_sync_window() | DcSyncWindowInfo | read-only | Measured sync window surface; when unavailable, applicable() == false and all numeric fields are None |
| DC diagnostics | dc().dc_sync0_armed() | Option<bool> | read-only | SYNC0 arming tri-state: Some(true) committed to generate SYNC0; Some(false) not armed with evidence; None = the underlying layer cannot answer |
| DC diagnostics | dc().dc_convergence_ms() | Option<i32> | read-only | Convergence time (ms) from the 2 s snapshot. None = no complete transition observed / not sampled yet |
| DC diagnostics | dc().dc_jitter() | Option<DcJitterStats> | read-only | Steady-state quality (σ / peak-to-peak / largest adjacent change) from the 2 s snapshot; None when there are fewer than 2 samples |
DcSyncWindowInfo fields:
| Category | Method | Return | Read/write | Description |
|---|---|---|---|---|
| DC diagnostics | applicable() | bool | read-only | Whether this sample has usable measurements (when false, see not_applicable_reason()) |
| DC diagnostics | not_applicable_reason() | DcSyncWindowNaReason | read-only | Reason for unavailability, see the table below; DcSyncWindowNaReason::None when available |
| DC diagnostics | diff_ns() | Option<i32> | read-only | Current synchronization difference (ns) |
| DC diagnostics | max_diff_ns() | Option<i32> | read-only | Maximum difference within the window (ns) |
| DC diagnostics | min_diff_ns() | Option<i32> | read-only | Minimum difference within the window (ns) |
| DC diagnostics | out_of_sync_count() | Option<u32> | read-only | Cumulative number of times outside the window |
| DC diagnostics | in_sync() | Option<bool> | read-only | Whether this sample is inside the sync window (the AND of the underlying measurement and armed) |
| DC diagnostics | sync_window_threshold_ns() | Option<i32> | read-only | Window threshold (ns); None = cannot be read |
| DC diagnostics | reading_unchanged() | Option<bool> | read-only | Whether the four 0x092C readings stayed completely unchanged for several consecutive samples (frozen-proxy bit). false does not mean "confirmed to be advancing" |
| DC diagnostics | unchanged_streak() | i32 | read-only | Number of consecutive samples with identical readings |
| DC diagnostics | sampled_at_utc() | Option<SystemTime> | read-only | Sampling time of this sample (UTC) |
Seven states
The seven states describe only "decidable synchronization window states"; the read-failure family and "armed but outside the window" are not among them.
| Category | State | Read/write | Rust expression | Meaning |
|---|---|---|---|---|
| DC diagnostics | No capability | read-only | not_applicable_reason() == NoDcCapability | No SYNC0 cycle unit, so synchronization error does not exist |
| DC diagnostics | Not armed | read-only | not_applicable_reason() == Sync0NotArmed | Known not to participate in DC synchronization, so 0x092C is undefined |
| DC diagnostics | Reference clock itself | read-only | not_applicable_reason() == ReferenceClockItself | Synchronization error does not exist by definition |
| DC diagnostics | Armed but readings frozen | read-only | applicable() == true and reading_unchanged() == Some(true) | The four readings stayed completely unchanged for several consecutive samples |
| DC diagnostics | Truly in the window | read-only | applicable() == true and in_sync() == Some(true) | Armed and measured inside the window |
| DC diagnostics | Arming unknown | read-only | not_applicable_reason() == ArmedUnknown | The underlying layer cannot answer, so participation cannot be asserted either way |
| DC diagnostics | Never sampled | read-only | not_applicable_reason() == NotSampled | All four are 0 and in_sync == false; 0 is not "perfect synchronization" |
Read-failure family (also in not_applicable_reason(), not part of the seven states):
| Category | Reason | Read/write | Meaning |
|---|---|---|---|
| DC diagnostics | SlaveReadFailed | read-only | The slave snapshot cannot be read, so even the capability cannot be determined |
| DC diagnostics | WindowReadFailed | read-only | Armed and not the reference clock, but the measured window read failed |
| DC diagnostics | ReferenceClockUnknown | read-only | The reference clock slave index cannot be read. The Rust side never produces this tier: the underlying interface that fetches the reference clock has no failure channel (0 also means "no reference clock"), so the enum is kept only for semantic alignment with the other languages |
Armed but outside the window = applicable() == true and in_sync() == Some(false) (not frozen). It belongs to none of the seven states, and the caller must read it truthfully as "outside the window", never as "not armed" or "unknown".
Three honest tri-states
| Category | Conclusion | Read/write | Rust expression | When there is no conclusion |
|---|---|---|---|---|
| DC diagnostics | Whether all are in the window | read-only | master.diagnostics_info().dc_diagnostics().all_in_sync | No confirmed participant (no DC / all unarmed / only the reference clock) → None, not true |
| DC diagnostics | Maximum synchronization difference | read-only | master.diagnostics_info().dc_diagnostics().max_drift_ns | No usable window → None, not 0 |
| DC diagnostics | SYNC0 armed | read-only | dc().dc_sync0_armed() | The underlying layer cannot answer → None, not false |
"Not applicable" is never written as 0: the sync window of the reference clock itself is always N/A, and not armed / no DC / never sampled likewise never produce 0 ns.
dc_arm_outcome() and the snapshot field arm_outcome are always None in this language, meaning "this SDK does not provide that conclusion", not DcArmResult::Unknown (the latter means "there is accounting, but this sample has no record for that slave"). Do not write it as "not armed yet" or "not participating".
Reference clock and time base
- Reference clock: the master selects the first slave on the link, in chain order, that is DC active (real SYNC0); when there is no armed slave at all, it falls back to the first DC-capable slave in the chain. The whole bus has only this one time base.
- Single start point: the reference domain has one start instant (the same physical moment), which the master converts into the time domain of each slave and writes into
0x0990; each slave does not measure its own start point. - Reference clock change (slave loss / hot-plug / capability change): every
0x0920written in the time domain of the old clock becomes invalid. In chain order, the master re-reads0x0920for each DC slave that is not in OP, not lost, and not the reference clock itself, proves it by reading back, and then rewrites that slave's0x0990in the new time domain; slaves in OP are not interrupted in their SYNC0 and have the error corrected by online compensation. - Phase only:
0x0928is corrected in hardware by the ESC when generating SYNC0;shift_nsis only a phase shift and contains no propagation delay compensation. - Diagnostics: the current SDK does not expose read-only properties for
0x0990/0x0920; register-level evidence is in the DC diagnostic log lines ofevents.log.
Complete example
let slave = master.slave(1);
if slave.has_dc() == Some(true) {
let dc = slave.dc();
dc.configure(1_000_000, 0, None)?; // SYNC0 = 1ms, automatic offset
println!("DCActive={}, DCCycle0={}ns, DCShift={}ns",
slave.dc_active(), slave.dc_cycle0(), slave.dc_shift());
// detailed sync window status
if let Some(status) = dc.sync_window_status() {
println!("同步差={}ns, 同步={}", status.diff_ns, status.in_sync); // Sync diff={}ns, in sync={}
}
dc.disable();
}