Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Precision Clock PPS. More...

Data Structures

struct  precision_clock_pps_config
 Configuration of a Precision Clock PPS instance. More...
struct  precision_clock_pps_state
 Coherent snapshot of an instance's autonomous PPS output state. More...
struct  precision_clock_pps
 Caller-owned autonomous one-pulse-per-second output instance. More...

Macros

#define PRECISION_CLOCK_PPS_CONFIG_DEFAULTS
 Initialize PPS configuration from subsystem Kconfig defaults.

Typedefs

typedef void(* precision_clock_pps_callback_t) (struct precision_clock_pps *pps)
 Callback invoked when a PPS poll produces one or more events.

Enumerations

enum  precision_clock_pps_event {
  PRECISION_CLOCK_PPS_EVENT_NONE = 0 , PRECISION_CLOCK_PPS_EVENT_ARMED = BIT(0) , PRECISION_CLOCK_PPS_EVENT_RECOVERED = BIT(1) , PRECISION_CLOCK_PPS_EVENT_HARD_STEP = BIT(2) ,
  PRECISION_CLOCK_PPS_EVENT_OUTPUT_INACTIVE = BIT(3) , PRECISION_CLOCK_PPS_EVENT_READ_ERROR = BIT(4) , PRECISION_CLOCK_PPS_EVENT_READ_RECOVERED = BIT(5) , PRECISION_CLOCK_PPS_EVENT_STATUS_ERROR = BIT(6) ,
  PRECISION_CLOCK_PPS_EVENT_STATUS_RECOVERED = BIT(7) , PRECISION_CLOCK_PPS_EVENT_STOP_ERROR = BIT(8) , PRECISION_CLOCK_PPS_EVENT_START_ERROR = BIT(9)
}
 Events reported by the autonomous PPS service. More...
enum  precision_clock_pps_phase {
  PRECISION_CLOCK_PPS_STOPPED = 0 , PRECISION_CLOCK_PPS_STARTING , PRECISION_CLOCK_PPS_ARMING , PRECISION_CLOCK_PPS_ACTIVE ,
  PRECISION_CLOCK_PPS_REARMING , PRECISION_CLOCK_PPS_STOPPING
}
 Lifecycle phase of an autonomous PPS instance. More...

Functions

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.
int precision_clock_pps_start (struct precision_clock_pps *pps)
 Start autonomously arming and maintaining the output.
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_stop (struct precision_clock_pps *pps)
 Stop an autonomous PPS output instance.

Detailed Description

Precision Clock PPS.

Since
4.6
Version
0.1.0

Macro Definition Documentation

◆ PRECISION_CLOCK_PPS_CONFIG_DEFAULTS

#define PRECISION_CLOCK_PPS_CONFIG_DEFAULTS

#include <zephyr/precision_timing/precision_clock_pps.h>

Value:
{ \
.channel = CONFIG_PRECISION_CLOCK_PPS_CHANNEL, \
.width_policy = IS_ENABLED(CONFIG_PRECISION_CLOCK_PPS_WIDTH_EXACT) \
.pulse_width_ns = IS_ENABLED(CONFIG_PRECISION_CLOCK_PPS_WIDTH_EXACT) \
? CONFIG_PRECISION_CLOCK_PPS_PULSE_WIDTH_NS \
: 0, \
.start_guard_ns = CONFIG_PRECISION_CLOCK_PPS_START_GUARD_NS, \
.step_limit_ns = CONFIG_PRECISION_CLOCK_PPS_STEP_LIMIT_NS, \
.poll_interval_ms = CONFIG_PRECISION_CLOCK_PPS_POLL_INTERVAL_MS, \
}
@ PRECISION_CLOCK_OUTPUT_WIDTH_PROVIDER_DEFAULT
Use the provider's native default high-pulse width.
Definition precision_clock_output.h:38
@ PRECISION_CLOCK_OUTPUT_WIDTH_EXACT
Use the exact high-pulse width supplied in the configuration.
Definition precision_clock_output.h:40
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:166

Initialize PPS configuration from subsystem Kconfig defaults.

Callers may override individual fields before initializing the service. Provider-default width uses zero as the unused exact-width value.

Typedef Documentation

◆ precision_clock_pps_callback_t

typedef void(* precision_clock_pps_callback_t) (struct precision_clock_pps *pps)

#include <zephyr/precision_timing/precision_clock_pps.h>

Callback invoked when a PPS poll produces one or more events.

The callback runs on the subsystem's dedicated workqueue without the instance lock held. Use precision_clock_pps_state_get() to read the current state and this notification's event mask, and pps->config.user_data to read the caller's context. The mask remains stable throughout the callback, but the phase can become PRECISION_CLOCK_PPS_STOPPING if another thread stops the instance. The callback must not block for an extended time, as it delays subsequent polls on the shared workqueue.

Calling precision_clock_pps_stop() on pps from this callback returns -EDEADLK. Stopping a different instance is allowed.

Parameters
ppsInstance that produced the notification.

Enumeration Type Documentation

◆ precision_clock_pps_event

#include <zephyr/precision_timing/precision_clock_pps.h>

Events reported by the autonomous PPS service.

More than one flag may be set at once, for example a hard step that is immediately followed by a successful rearm. These events do not report physical pulse edges or their timestamps.

Enumerator
PRECISION_CLOCK_PPS_EVENT_NONE 

No event has been reported.

PRECISION_CLOCK_PPS_EVENT_ARMED 

The output was armed or adopted for the first time since start.

PRECISION_CLOCK_PPS_EVENT_RECOVERED 

The output was rearmed after previously being active.

PRECISION_CLOCK_PPS_EVENT_HARD_STEP 

A clock discontinuity beyond the configured threshold was detected.

PRECISION_CLOCK_PPS_EVENT_OUTPUT_INACTIVE 

A previously active output was found unconfigured, mismatched, or inactive.

PRECISION_CLOCK_PPS_EVENT_READ_ERROR 

Reading the registered clock failed.

PRECISION_CLOCK_PPS_EVENT_READ_RECOVERED 

Reading the registered clock recovered after a prior failure.

PRECISION_CLOCK_PPS_EVENT_STATUS_ERROR 

Querying the output channel status failed.

PRECISION_CLOCK_PPS_EVENT_STATUS_RECOVERED 

Querying the output channel status recovered after a prior failure.

PRECISION_CLOCK_PPS_EVENT_STOP_ERROR 

The service failed to stop the channel before arming it.

PRECISION_CLOCK_PPS_EVENT_START_ERROR 

The service failed to compute the next edge time or start the channel.

◆ precision_clock_pps_phase

#include <zephyr/precision_timing/precision_clock_pps.h>

Lifecycle phase of an autonomous PPS instance.

Enumerator
PRECISION_CLOCK_PPS_STOPPED 

The instance is initialized but not polling.

PRECISION_CLOCK_PPS_STARTING 

Polling for initial status; a matching output may be adopted.

PRECISION_CLOCK_PPS_ARMING 

An initial stop and arm is required.

PRECISION_CLOCK_PPS_ACTIVE 

The matching output is armed or running.

PRECISION_CLOCK_PPS_REARMING 

A stop and rearm is required after previously being active.

PRECISION_CLOCK_PPS_STOPPING 

A caller is synchronously stopping the service.

Function Documentation

◆ precision_clock_pps_init()

int precision_clock_pps_init ( struct precision_clock_pps * pps,
const struct precision_clock * precision_clk,
const struct precision_clock_pps_config * config )

#include <zephyr/precision_timing/precision_clock_pps.h>

Initialize a one-pulse-per-second output instance.

Copies config into pps, validates it against the configured clock output channel's capabilities, and prepares the internal poll work and lock. The clock time is not read here, and the output is not changed.

Call from thread context, before using the instance in any other PPS API. Do not reinitialize an instance while it is in use. Using the instance before this function succeeds is outside the API contract.

Parameters
ppsCaller-owned instance storage to initialize.
precision_clkProtocol-neutral clock that owns the output channel.
configRuntime configuration copied into the instance.
Return values
0on success.
-EINVALif an argument is null or the configuration is invalid, for example an unknown width policy, an out-of-range exact pulse width, a negative guard or step limit, a zero poll interval, or invalid provider resolution or minimum lead time.
-ENOTSUPif the requested channel is unavailable or lacks support for periodic waveforms or the requested width policy.
-ERANGEif the poll interval is not a finite kernel timeout, the period or exact width is outside the channel's limits or resolution, or adding the start guard to the minimum lead time overflows.
Returns
Another negative error code from querying the clock capabilities.

◆ precision_clock_pps_start()

int precision_clock_pps_start ( struct precision_clock_pps * pps)

#include <zephyr/precision_timing/precision_clock_pps.h>

Start autonomously arming and maintaining the output.

Schedules the first poll immediately on the subsystem's dedicated workqueue. Arming does not wait for or inspect any synchronization protocol; it proceeds as soon as the clock can be read and its output channel controlled. Multiple instances have independent configuration, state, and lifetime, but their polls, poll-time provider operations, and callbacks are serialized on one shared dedicated workqueue. A blocking poll-time provider operation or callback for one instance can therefore delay polling of other instances. The capability query in init() and the provider stop in stop() run on the calling thread and may overlap another instance's poll. Providers must support concurrent operations on different channels of the same clock.

Call this function from thread context on an initialized, stopped instance. The caller must grant the instance exclusive management of its configured clock and output-channel pair until precision_clock_pps_stop() succeeds. During that interval, no other PPS instance or direct scheduled-output API caller may use the channel. A matching output that exists before the first poll may be adopted only when its exclusive management has been transferred to this instance.

Parameters
ppsInitialized instance to start.
Return values
0on success.
-EINVALif pps is null.
-EALREADYif the instance is not stopped.
Returns
Another negative error code if scheduling the first poll fails.

◆ precision_clock_pps_state_get()

int precision_clock_pps_state_get ( struct precision_clock_pps * pps,
struct precision_clock_pps_state * state )

#include <zephyr/precision_timing/precision_clock_pps.h>

Copy the current autonomous PPS output state.

When a callback is configured, the snapshot contains the most recent notification mask without clearing it. Otherwise the snapshot contains the accumulated events since the previous call, and copying them clears the accumulated mask. A successful start clears any previously reported events in either mode.

Call from thread context, not from an ISR. The snapshot may be taken while stopped, concurrently with polling, and from the instance callback.

Parameters
ppsInitialized instance to observe.
stateDestination for the coherent state snapshot.
Return values
0on success.
-EINVALif an argument is null.

◆ precision_clock_pps_stop()

int precision_clock_pps_stop ( struct precision_clock_pps * pps)

#include <zephyr/precision_timing/precision_clock_pps.h>

Stop an autonomous PPS output instance.

On success, synchronously cancels any pending or running poll, stops the output channel, and marks the instance stopped. Cancellation waits for a running poll and its callback to finish before stopping the output, so neither will use the clock or callback context after a successful stop unless the instance is started again. A stopped instance may be restarted without reinitialization if its clock and callback context remain valid.

If the provider stop fails, the instance returns to its prior phase and polling resumes. Do not release the clock or callback context in that case.

Call this function from thread context, and never from the instance's own precision_clock_pps_callback_t; a self-stop is rejected with -EDEADLK. Stopping a different instance from a callback is allowed.

Parameters
ppsInstance to stop.
Return values
0on success.
-EINVALif pps is null.
-EALREADYif the instance is not started.
-EBUSYif another stop call is already in progress.
-EDEADLKif called from pps's own poll or callback context.
Returns
A provider-specific negative error code if stopping the output channel fails; the instance remains started in that case.