|
Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
|
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. | |
Precision Clock PPS.
| #define PRECISION_CLOCK_PPS_CONFIG_DEFAULTS |
#include <zephyr/precision_timing/precision_clock_pps.h>
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 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.
| pps | Instance that produced the notification. |
#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.
#include <zephyr/precision_timing/precision_clock_pps.h>
Lifecycle phase of an autonomous PPS instance.
| 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.
| pps | Caller-owned instance storage to initialize. |
| precision_clk | Protocol-neutral clock that owns the output channel. |
| config | Runtime configuration copied into the instance. |
| 0 | on success. |
| -EINVAL | if 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. |
| -ENOTSUP | if the requested channel is unavailable or lacks support for periodic waveforms or the requested width policy. |
| -ERANGE | if 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. |
| 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.
| pps | Initialized instance to start. |
| 0 | on success. |
| -EINVAL | if pps is null. |
| -EALREADY | if the instance is not stopped. |
| 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.
| pps | Initialized instance to observe. |
| state | Destination for the coherent state snapshot. |
| 0 | on success. |
| -EINVAL | if an argument is null. |
| 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.
| pps | Instance to stop. |
| 0 | on success. |
| -EINVAL | if pps is null. |
| -EALREADY | if the instance is not started. |
| -EBUSY | if another stop call is already in progress. |
| -EDEADLK | if called from pps's own poll or callback context. |