Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
precision_clock_pps.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
3 * SPDX-FileCopyrightText: Copyright (c) 2026 Philipp Steiner
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
12
13#ifndef ZEPHYR_INCLUDE_ZEPHYR_PRECISION_TIMING_PRECISION_CLOCK_PPS_H_
14#define ZEPHYR_INCLUDE_ZEPHYR_PRECISION_TIMING_PRECISION_CLOCK_PPS_H_
15
16#include <stdbool.h>
17#include <stdint.h>
18
19#include <zephyr/kernel.h>
21#include <zephyr/sys/util.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
35
67
69
87
131
138#define PRECISION_CLOCK_PPS_CONFIG_DEFAULTS \
139 { \
140 .channel = CONFIG_PRECISION_CLOCK_PPS_CHANNEL, \
141 .width_policy = IS_ENABLED(CONFIG_PRECISION_CLOCK_PPS_WIDTH_EXACT) \
142 ? PRECISION_CLOCK_OUTPUT_WIDTH_EXACT \
143 : PRECISION_CLOCK_OUTPUT_WIDTH_PROVIDER_DEFAULT, \
144 .pulse_width_ns = IS_ENABLED(CONFIG_PRECISION_CLOCK_PPS_WIDTH_EXACT) \
145 ? CONFIG_PRECISION_CLOCK_PPS_PULSE_WIDTH_NS \
146 : 0, \
147 .start_guard_ns = CONFIG_PRECISION_CLOCK_PPS_START_GUARD_NS, \
148 .step_limit_ns = CONFIG_PRECISION_CLOCK_PPS_STEP_LIMIT_NS, \
149 .poll_interval_ms = CONFIG_PRECISION_CLOCK_PPS_POLL_INTERVAL_MS, \
150 }
151
167
177
220
249 const struct precision_clock *precision_clk,
250 const struct precision_clock_pps_config *config);
251
282
303
332
334
335#ifdef __cplusplus
336}
337#endif
338
339#endif /* ZEPHYR_INCLUDE_ZEPHYR_PRECISION_TIMING_PRECISION_CLOCK_PPS_H_ */
precision_clock_output_width_policy
Precision clock output high-pulse width policy for periodic waveforms.
Definition precision_clock_output.h:36
int precision_clock_pps_stop(struct precision_clock_pps *pps)
Stop an autonomous PPS output instance.
precision_clock_pps_phase
Lifecycle phase of an autonomous PPS instance.
Definition precision_clock_pps.h:153
int precision_clock_pps_start(struct precision_clock_pps *pps)
Start autonomously arming and maintaining the output.
precision_clock_pps_event
Events reported by the autonomous PPS service.
Definition precision_clock_pps.h:43
void(* precision_clock_pps_callback_t)(struct precision_clock_pps *pps)
Callback invoked when a PPS poll produces one or more events.
Definition precision_clock_pps.h:86
int precision_clock_pps_state_get(struct precision_clock_pps *pps, struct precision_clock_pps_state *state)
Copy the current autonomous PPS output state.
int precision_clock_pps_init(struct precision_clock_pps *pps, const struct precision_clock *precision_clk, const struct precision_clock_pps_config *config)
Initialize a one-pulse-per-second output instance.
@ PRECISION_CLOCK_PPS_STOPPING
A caller is synchronously stopping the service.
Definition precision_clock_pps.h:165
@ PRECISION_CLOCK_PPS_ACTIVE
The matching output is armed or running.
Definition precision_clock_pps.h:161
@ PRECISION_CLOCK_PPS_REARMING
A stop and rearm is required after previously being active.
Definition precision_clock_pps.h:163
@ PRECISION_CLOCK_PPS_ARMING
An initial stop and arm is required.
Definition precision_clock_pps.h:159
@ PRECISION_CLOCK_PPS_STOPPED
The instance is initialized but not polling.
Definition precision_clock_pps.h:155
@ PRECISION_CLOCK_PPS_STARTING
Polling for initial status; a matching output may be adopted.
Definition precision_clock_pps.h:157
@ PRECISION_CLOCK_PPS_EVENT_READ_RECOVERED
Reading the registered clock recovered after a prior failure.
Definition precision_clock_pps.h:57
@ PRECISION_CLOCK_PPS_EVENT_ARMED
The output was armed or adopted for the first time since start.
Definition precision_clock_pps.h:47
@ PRECISION_CLOCK_PPS_EVENT_OUTPUT_INACTIVE
A previously active output was found unconfigured, mismatched, or inactive.
Definition precision_clock_pps.h:53
@ PRECISION_CLOCK_PPS_EVENT_STATUS_ERROR
Querying the output channel status failed.
Definition precision_clock_pps.h:59
@ PRECISION_CLOCK_PPS_EVENT_STOP_ERROR
The service failed to stop the channel before arming it.
Definition precision_clock_pps.h:63
@ PRECISION_CLOCK_PPS_EVENT_STATUS_RECOVERED
Querying the output channel status recovered after a prior failure.
Definition precision_clock_pps.h:61
@ PRECISION_CLOCK_PPS_EVENT_NONE
No event has been reported.
Definition precision_clock_pps.h:45
@ PRECISION_CLOCK_PPS_EVENT_HARD_STEP
A clock discontinuity beyond the configured threshold was detected.
Definition precision_clock_pps.h:51
@ PRECISION_CLOCK_PPS_EVENT_START_ERROR
The service failed to compute the next edge time or start the channel.
Definition precision_clock_pps.h:65
@ PRECISION_CLOCK_PPS_EVENT_RECOVERED
The output was rearmed after previously being active.
Definition precision_clock_pps.h:49
@ PRECISION_CLOCK_PPS_EVENT_READ_ERROR
Reading the registered clock failed.
Definition precision_clock_pps.h:55
int64_t precision_time_t
Signed precision time value expressed in nanoseconds.
Definition precision_time.h:40
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
Public kernel APIs.
state
Definition parser_state.h:29
Protocol-neutral scheduled precision clock outputs.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Kernel mutex structure.
Definition kernel.h:3777
A structure used to submit work after a delay.
Definition kernel.h:4968
A structure holding internal state for a pending synchronous operation on a work item or queue.
Definition kernel.h:5063
Configuration of a periodic clock output waveform.
Definition precision_clock_output.h:100
Configuration of a Precision Clock PPS instance.
Definition precision_clock_pps.h:100
void * user_data
Opaque caller context, available to the callback as pps->config.user_data.
Definition precision_clock_pps.h:129
uint32_t channel
Zero-based scheduled-output channel armed by the instance.
Definition precision_clock_pps.h:102
uint32_t poll_interval_ms
Positive interval between polls, representable as a finite kernel timeout.
Definition precision_clock_pps.h:125
precision_clock_pps_callback_t callback
Event callback, or NULL to accumulate events for polling instead.
Definition precision_clock_pps.h:127
enum precision_clock_output_width_policy width_policy
High-pulse width policy for the one-second waveform.
Definition precision_clock_pps.h:104
precision_time_t step_limit_ns
Non-negative clock-discontinuity threshold in nanoseconds.
Definition precision_clock_pps.h:123
precision_time_t pulse_width_ns
Exact active-high pulse width in nanoseconds.
Definition precision_clock_pps.h:110
precision_time_t start_guard_ns
Non-negative guard added to the provider's minimum lead time before aligning the first output edge to...
Definition precision_clock_pps.h:115
Coherent snapshot of an instance's autonomous PPS output state.
Definition precision_clock_pps.h:169
struct precision_clock_output_waveform_config config
Effective waveform configuration, valid only in PRECISION_CLOCK_PPS_ACTIVE.
Definition precision_clock_pps.h:171
uint32_t events
Combination of precision_clock_pps_event flags.
Definition precision_clock_pps.h:175
enum precision_clock_pps_phase phase
Current lifecycle phase.
Definition precision_clock_pps.h:173
Caller-owned autonomous one-pulse-per-second output instance.
Definition precision_clock_pps.h:192
struct precision_clock_pps_state state
Published state snapshot.
Definition precision_clock_pps.h:206
precision_time_t clock_phc_ns
Registered clock time at the most recent successful service read.
Definition precision_clock_pps.h:208
precision_time_t clock_mono_post_ns
Monotonic time immediately after that clock read.
Definition precision_clock_pps.h:212
struct k_work_delayable work
Delayable poll work scheduled on the subsystem workqueue.
Definition precision_clock_pps.h:194
precision_time_t start_lead_time_ns
Provider's minimum lead time plus the instance's start guard.
Definition precision_clock_pps.h:204
bool read_failed
Whether the most recent clock read failed.
Definition precision_clock_pps.h:216
bool clock_read_done
Whether a successful clock sample is available for continuity checking.
Definition precision_clock_pps.h:214
struct precision_clock_pps_config config
Immutable configuration copied from the caller.
Definition precision_clock_pps.h:202
precision_time_t clock_mono_pre_ns
Monotonic time immediately before that clock read.
Definition precision_clock_pps.h:210
const struct precision_clock * precision_clk
Protocol-neutral clock that owns the output channel.
Definition precision_clock_pps.h:200
uint8_t consecutive_status_errors
Consecutive status errors, saturated at the threshold until status recovers.
Definition precision_clock_pps.h:218
struct k_work_sync work_sync
Sync object for synchronous poll cancellation during stop.
Definition precision_clock_pps.h:196
struct k_mutex lock
Per-instance lock protecting the state below.
Definition precision_clock_pps.h:198
Protocol-neutral precision clock instance.
Definition precision_clock.h:79
Misc utilities.