Unified time service library and distributed time synchronization infrastructure for automotive ECU software.
Portable and high-performance implementation of time services for the S-CORE project.
This repository contains source code for time clocks, time distribution infrastructure, and PTP synchronization. The Time module is implemented in C++ and provides working examples demonstrating usage patterns.
High-level functionality provided by the Time module:
- Clock Domains: Four time sources accessed through unified
Clock<Tag>API; all domains support nanosecond resolution and compile-time domain selection preventing cross-domain timing errors; mock backends andScopedClockOverrideavailable for testing- SystemTime: Wall-clock time (Unix epoch) for timestamps and user-visible time displays
- SteadyTime: Monotonic time for duration measurements and timeouts
- HighResSteadyTime: High-resolution monotonic time for precise timing applications
- VehicleTime: PTP-synchronized time for distributed automotive applications requiring initialization
- Clock API: Type-safe
Clock<Tag>::GetInstance().Now()returns time and status information - Event Subscription:
Subscribe<EventType>()/Unsubscribe<EventType>()for status changes and PTP timebase data - Time Infrastructure
- TimeDaemon: Standalone daemon that retrieves synchronized time from TimeSlave, validates timepoints, sets synchronization status, and distributes VehicleTime to applications
- TimeSlave: gPTP (IEEE 802.1AS) slave endpoint that implements network synchronization protocol, calculates time offset, and publishes synchronization time data to the TimeDaemon
| Target | Purpose |
|---|---|
//score/time/system_time |
Wall-clock time (Unix epoch) for timestamps |
//score/time/system_time:system_time_mock |
Mock backend for SystemTime testing |
//score/time/system_time:interface |
Header-only interface (no backend) |
| Target | Purpose |
|---|---|
//score/time/steady_time |
Monotonic time for duration measurement |
//score/time/steady_time:steady_time_mock |
Mock backend for SteadyTime testing |
//score/time/steady_time:interface |
Header-only interface (no backend) |
| Target | Purpose |
|---|---|
//score/time/high_res_steady_time |
High-resolution monotonic time |
//score/time/high_res_steady_time:high_res_steady_time_mock |
Mock backend for HighResSteadyTime testing |
//score/time/high_res_steady_time:interface |
Header-only interface (no backend) |
| Target | Purpose |
|---|---|
//score/time/vehicle_time |
PTP-synchronized vehicle time |
//score/time/vehicle_time:vehicle_time_mock |
Mock backend for VehicleTime testing |
//score/time/vehicle_time:interface |
Header-only interface (no backend) |
| Target | Purpose |
|---|---|
//score/time/clock:clock_test_utils |
ScopedClockOverride and ClockTestFactory utilities |
Add to your MODULE.bazel:
bazel_dep(name = "score_time", version = "x.x.x")Check available versions in the S-CORE Bazel Registry.
To depend on an unreleased version (for development or testing), use a git override in your MODULE.bazel:
git_override(
module_name = "score_time",
commit = "abc123...",
remote = "https://github.com/eclipse-score/time.git",
)Replace the commit value with the specific git hash you want to use.
For deployment, use these executable targets:
Available binaries:
@score_time//score/time_daemon:time_daemon- TimeDaemon executable for time distribution@score_time//score/time_slave:time_slave- TimeSlave executable for PTP synchronization
Run artifacts directly:
bazel run @score_time//score/time_daemon:time_daemon
bazel run @score_time//score/time_slave:time_slaveDo not add these to deps as libraries. Use them as runtime artifacts for your deployment system.
- Time Feature Documentation: High-level feature overview and S-CORE platform integration
- Time Module Documentation: Detailed API documentation, architecture, and requirements
Generate module documentation locally:
bazel run //:docsThis section contains information on how to build and use the Time module.
git clone https://github.com/eclipse-score/time.git
cd time- C++ Compiler: gcc/clang with C++17 support
- Build System: Bazel 8+ (managed via Bazelisk)
- Operating System: Linux (Ubuntu 24.04+)
- Dependencies: S-CORE Baselibs, Google Test
- For QNX targets: QNX 8.0 SDP
Use devcontainer as default path. It includes Bazel tooling and dependencies.
- Install Docker.
- Open repository in a devcontainer-capable editor (for example VS Code with Dev Containers extension).
- Reopen workspace in container.
Follow the S-CORE Development Environment Guide for Linux host setup requirements.
Build all components for Linux x86_64 by running:
bazel build --config=time-x86_64-linux //score/... //examples/...Run all tests:
bazel test --config=time-x86_64-linux //score/... //examples/...Linux AArch64:
bazel build --config=time-arm64-linux //score/... //examples/...
bazel test --config=time-arm64-linux //score/... //examples/...QNX x86_64:
bazel build --config=time-x86_64-qnx //score/... //examples/...
bazel test --config=time-x86_64-qnx //score/... //examples/...QNX AArch64:
bazel build --config=time-aarch64-qnx //score/... //examples/...
bazel test --config=time-aarch64-qnx //score/... //examples/...To test with AddressSanitizer, UBSan, and LeakSanitizer enabled:
bazel test --config=time-x86_64-linux --config=asan_ubsan_lsan --build_tests_only //score/... //examples/...Working examples demonstrating clock usage patterns, testing approaches, and integration techniques are available in the examples/ directory:
- examples/time/system_time β SystemTime usage for wall-clock timestamps
- examples/time/steady_time β SteadyTime usage for duration measurements
- examples/time/high_res_steady_time β HighResSteadyTime usage for high-resolution timing
- examples/time/vehicle_time β VehicleTime usage with PTP synchronization
Each example includes a handler demonstrating the Clock API and corresponding unit tests.
βββ score/
β βββ time/ # Clock domains (SystemTime, SteadyTime, etc.)
β βββ time_daemon/ # Time distribution daemon
β βββ time_slave/ # PTP timebase implementation
β βββ ts_client/ # Library for time slave communication
βββ examples/ # Usage examples and patterns
βββ docs/ # Module documentation
βββ tools/ # Build and development utilities
See our Contributing Guide for contribution guidelines and development workflow.
- Issues: Report bugs and request features via GitHub Issues
- Discussions: Join time Slack Channel