Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Toggle main menu visibility
Loading...
Searching...
No Matches
sapi_clocksync.c
Go to the documentation of this file.
1
6
#include "
safeapi/oal/clocksync/sapi_clocksync.h
"
7
#include "
safeapi/utils/lifecycle/sapi_lifecycle.h
"
8
#include "
safeapi_backend/clocksync/sapi_clocksync_backend.h
"
9
11
13
18
static
const
sapi_clocksync_backend_t
*
s_backend
= NULL;
19
21
23
24
26
sapi_status_t
sapi_clocksync_register_backend
(
const
sapi_clocksync_backend_t
*backend)
27
{
28
sapi_status_t
status =
SAPI_STATUS_OK
;
29
30
if
(backend == NULL)
31
{
32
status =
SAPI_STATUS_INVALID_PARAM
;
33
}
34
else
35
{
36
/* REQ-LIFECYCLE-001 (ADR-026): registering a backend is a setup-only
37
* action - refuse once the application's setup phase has been locked. */
38
status =
sapi_lifecycle_check_setup_allowed
();
39
if
(status ==
SAPI_STATUS_OK
)
40
{
41
s_backend
= backend;
42
}
43
}
44
45
return
status;
46
}
47
48
sapi_status_t
sapi_clocksync_get_offset_ms
(int64_t *out_offset_ms)
49
{
50
sapi_status_t
status =
SAPI_STATUS_OK
;
51
52
if
(out_offset_ms == NULL)
53
{
54
status =
SAPI_STATUS_INVALID_PARAM
;
55
}
56
else
if
(
s_backend
== NULL)
57
{
58
status =
SAPI_STATUS_NOT_INITIALIZED
;
59
}
60
else
if
(
s_backend
->
get_offset_ms
== NULL)
61
{
62
status =
SAPI_STATUS_NOT_SUPPORTED
;
63
}
64
else
65
{
66
status =
s_backend
->
get_offset_ms
(out_offset_ms);
67
}
68
69
return
status;
70
}
71
72
sapi_status_t
sapi_clocksync_get_quality
(
sapi_clocksync_quality_t
*out_quality)
73
{
74
sapi_status_t
status =
SAPI_STATUS_OK
;
75
76
if
(out_quality == NULL)
77
{
78
status =
SAPI_STATUS_INVALID_PARAM
;
79
}
80
else
if
(
s_backend
== NULL)
81
{
82
status =
SAPI_STATUS_NOT_INITIALIZED
;
83
}
84
else
if
(
s_backend
->
get_quality
== NULL)
85
{
86
status =
SAPI_STATUS_NOT_SUPPORTED
;
87
}
88
else
89
{
90
status =
s_backend
->
get_quality
(out_quality);
91
}
92
93
return
status;
94
}
sapi_clocksync_register_backend
sapi_status_t sapi_clocksync_register_backend(const sapi_clocksync_backend_t *backend)
Registers the backend implementation used by every sapi_clocksync_* call (ADR-005-style single global...
Definition
sapi_clocksync.c:26
sapi_clocksync_quality_t
sapi_clocksync_quality_t
Coarse quality/confidence of the current clock synchronization.
Definition
sapi_clocksync.h:60
sapi_clocksync_get_offset_ms
sapi_status_t sapi_clocksync_get_offset_ms(int64_t *out_offset_ms)
Reports this node's estimated clock offset (diagnostic/timeout- sizing only - see the file-level note...
Definition
sapi_clocksync.c:48
sapi_clocksync_get_quality
sapi_status_t sapi_clocksync_get_quality(sapi_clocksync_quality_t *out_quality)
Reports the backend's current confidence in the clock offset.
Definition
sapi_clocksync.c:72
sapi_lifecycle_check_setup_allowed
sapi_status_t sapi_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
Definition
sapi_lifecycle.c:40
sapi_status_t
sapi_status_t
Common result/status codes.
Definition
sapi_status.h:27
SAPI_STATUS_NOT_SUPPORTED
@ SAPI_STATUS_NOT_SUPPORTED
Definition
sapi_status.h:34
SAPI_STATUS_INVALID_PARAM
@ SAPI_STATUS_INVALID_PARAM
Definition
sapi_status.h:29
SAPI_STATUS_NOT_INITIALIZED
@ SAPI_STATUS_NOT_INITIALIZED
Definition
sapi_status.h:30
SAPI_STATUS_OK
@ SAPI_STATUS_OK
Definition
sapi_status.h:28
s_backend
static const sapi_clocksync_backend_t * s_backend
Definition
sapi_clocksync.c:18
sapi_clocksync.h
Pluggable wall-clock synchronization backend (ADR-017).
sapi_clocksync_backend.h
OS-backend adaptation surface for Clock Synchronization (ADR-005, ADR-017, ADR-021).
sapi_lifecycle.h
Process-wide application setup-phase lock (ADR-026).
sapi_clocksync_backend_t
Backend vtable: an integrator's implementation of clock synchronization for a specific mechanism (PTP...
Definition
sapi_clocksync_backend.h:36
sapi_clocksync_backend_t::get_offset_ms
sapi_status_t(*) get_offset_ms(int64_t *out_offset_ms)
Definition
sapi_clocksync_backend.h:40
sapi_clocksync_backend_t::get_quality
sapi_status_t(*) get_quality(sapi_clocksync_quality_t *out_quality)
Definition
sapi_clocksync_backend.h:42
src
oal
clocksync
sapi_clocksync.c
Generated by
1.18.0