Home Learning Paths ECU Lab Assessments Interview Preparation Arena Pricing Log In Sign Up

FlexRay Global Time and Sync Frames

Clock Synchronisation via Sync Frames
  Sync Node A (Slot 1, SYNC bit=1):
  Transmits at its local clock time T_local_A
  ┌───────────────────────────────────────────────────────┐
  │ Each receiver measures: actual_arrival - expected_slot │
  │ = offset from its own local clock                     │
  │                                                       │
  │ Node B measures: A's frame arrived 0.3 µs late        │
  │ Node C measures: A's frame arrived 0.1 µs early       │
  │ Node D measures: A's frame arrived 0.2 µs late        │
  └───────────────────────────────────────────────────────┘
  After collecting offsets from ≥ gMinSyncNodeCount sync nodes:
  → FTM algorithm discards outliers, computes midpoint correction

Fault-Tolerant Midpoint (FTM) Algorithm

Pythonflexray_ftm.py
# FlexRay Fault-Tolerant Midpoint clock synchronisation algorithm
# Per FlexRay Protocol Specification v3.0.1, Section 5.4

def fault_tolerant_midpoint(offset_measurements, g_min_sync=2):
    """
    offset_measurements: list of (node_id, measured_offset_ns) from sync frames
    Returns: clock correction to apply in NIT
    """
    if len(offset_measurements) < g_min_sync:
        return 0  # insufficient sync nodes — no correction

    offsets = sorted([m[1] for m in offset_measurements])
    n = len(offsets)

    # Discard highest and lowest (fault tolerance against 1 faulty sync node)
    if n >= 4:
        trimmed = offsets[1:-1]  # remove 1 from each end
    else:
        trimmed = offsets

    # Midpoint = average of trimmed set
    correction = sum(trimmed) / len(trimmed)
    return correction

# Example: 4 sync nodes measured
measurements = [
    ("ECU_A", 50),    # 50 ns offset
    ("ECU_B", 45),    # 45 ns offset (could be faulty outlier)
    ("ECU_C", 200),   # 200 ns offset — suspicious, will be trimmed
    ("ECU_D", 48),    # 48 ns
]

correction = fault_tolerant_midpoint(measurements)
print(f"Clock correction: {correction:.1f} ns")
# With outlier 200 trimmed and 45 trimmed: average of [50, 48] = 49 ns

Microtick and Macrotick Relationship

Time UnitResolutionDerivationAUTOSAR Module
Microtick (µT)Nanoseconds (node-specific)Derived from node oscillator frequencyInternal to FlexRay CC
Macrotick (MT)N × microticks (cluster-wide)Configurable per cluster; same for all nodes after syncFrIf uses MT for slot timing
Global time(cycle_number, macrotick_offset)Expressed as pair — unambiguous position in FlexRay timelineStbM exposes as AUTOSAR TimeBase
Cflexray_global_time.c
/* Read FlexRay global time via AUTOSAR StbM (Synchronized Time-Base Manager) */
#include "StbM.h"
#include "FrIf.h"

StbM_TimeStampType  globalTime;
StbM_UserDataType   userData;
Std_ReturnType      retVal;

/* Read FlexRay-derived synchronized time base */
retVal = StbM_GetCurrentTime(STBM_SYNCHRONISED_TIME_BASE_FLEXRAY, &globalTime, &userData);

if (retVal == E_OK) {
    /* globalTime.seconds + nanoseconds = absolute FlexRay cluster time */
    uint32_t cycle_number = FrIf_GetCycleCounter(FR_CHANNEL_A);
    uint16_t macrotick    = FrIf_GetMacrotick(FR_CHANNEL_A);
    /* Use for timestamping safety-critical events with µs-level accuracy */
}

Synchronisation Parameters and Oscillator Spec

ParameterTypical ValueConsequence if Exceeded
gOffsetCorrectionMax100–200 µsCorrection request rejected; node may lose sync; cold start required
gRateCorrectionMax±0.1%Rate correction clamped; accumulated offset → lose sync over time
Oscillator stability±50 ppm (typical automotive quartz)Must be < gRateCorrectionMax / 2 to guarantee convergence
gMinSyncNodeCount2Below this: FTM cannot run; all nodes default to no correction

Summary

FlexRay global time synchronisation achieves sub-microsecond accuracy across all cluster nodes using sync frames and the FTM algorithm. The FTM's outlier rejection provides fault tolerance against one misbehaving sync node. Oscillator stability must be within the rate correction bounds — ±50 ppm automotive-grade quartz is sufficient for typical FlexRay clusters. AUTOSAR StbM exposes the FlexRay time base to application-layer modules for timestamping and time-triggered scheduling.

🔬 Deep Dive — Core Concepts Expanded

This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.

Key principles to reinforce:

  • Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
  • Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
  • Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.

🏭 How This Topic Appears in Production Projects

  • Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
  • Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
  • Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.

⚠️ Common Mistakes and How to Avoid Them

  1. Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
  2. Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
  3. Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
  4. Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.

📊 Industry Note

Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.

← PreviousStatic & Dynamic SegmentsNext →FlexRay Communication Cycle Design