Safe API Framework
0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Toggle main menu visibility
Loading...
Searching...
No Matches
rte_timer.c
Go to the documentation of this file.
1
7
#include "
rte/utils/lifecycle/rte_lifecycle.h
"
8
#include "
rte/oal/timer/rte_timer.h
"
9
#include "
rte_osadapter/timer/rte_osadapter_timer.h
"
10
12
14
17
static
const
rte_osadapter_timer_t
*
s_osadapter
= NULL;
18
20
22
23
25
rte_status_t
rte_osadapter_timer_register
(
const
rte_osadapter_timer_t
*osadapter)
26
{
27
rte_status_t
lifecycle_status;
28
29
if
(osadapter == NULL)
30
{
31
return
RTE_STATUS_INVALID_PARAM
;
32
}
33
/* REQ-LIFECYCLE-001 (ADR-026): registering an OSAdapter is a setup-only
34
* action - refuse once the application's setup phase has been locked. */
35
lifecycle_status =
rte_lifecycle_check_setup_allowed
();
36
if
(lifecycle_status !=
RTE_STATUS_OK
)
37
{
38
return
lifecycle_status;
39
}
40
s_osadapter
= osadapter;
41
return
RTE_STATUS_OK
;
42
}
43
44
rte_status_t
rte_timer_create
(rte_timer_storage_t *storage,
45
const
rte_timer_config_t
*config,
46
rte_timer_handle_t
*out_handle)
47
{
48
if
((storage == NULL) || (config == NULL) || (out_handle == NULL))
49
{
50
return
RTE_STATUS_INVALID_PARAM
;
51
}
52
if
((config->
callback
== NULL) || (config->
period_ms
== 0U))
53
{
54
return
RTE_STATUS_INVALID_PARAM
;
55
}
56
*out_handle = NULL;
57
/* REQ-LIFECYCLE-001 (ADR-026): a timer is a setup-only resource - refuse once the
58
* application's setup phase has been locked (rte_appmanager_run(),
59
* after ops->init() succeeds). */
60
{
61
rte_status_t
lifecycle_status =
rte_lifecycle_check_setup_allowed
();
62
63
if
(lifecycle_status !=
RTE_STATUS_OK
)
64
{
65
return
lifecycle_status;
66
}
67
}
68
if
(
s_osadapter
== NULL)
69
{
70
return
RTE_STATUS_NOT_INITIALIZED
;
71
}
72
if
(
s_osadapter
->create == NULL)
73
{
74
return
RTE_STATUS_NOT_SUPPORTED
;
75
}
76
return
s_osadapter
->create(storage, config, out_handle);
77
}
78
79
rte_status_t
rte_timer_start
(
rte_timer_handle_t
handle)
80
{
81
if
(handle == NULL)
82
{
83
return
RTE_STATUS_INVALID_PARAM
;
84
}
85
/* REQ-LIFECYCLE-001/003 (ADR-026, OSA rules): setup-only - refused and reported once the setup phase is locked. */
86
{
87
rte_status_t
lifecycle_status =
rte_lifecycle_check_setup_allowed
();
88
89
if
(lifecycle_status !=
RTE_STATUS_OK
)
90
{
91
return
lifecycle_status;
92
}
93
}
94
if
(
s_osadapter
== NULL)
95
{
96
return
RTE_STATUS_NOT_INITIALIZED
;
97
}
98
if
(
s_osadapter
->start == NULL)
99
{
100
return
RTE_STATUS_NOT_SUPPORTED
;
101
}
102
return
s_osadapter
->start(handle);
103
}
104
105
rte_status_t
rte_timer_stop
(
rte_timer_handle_t
handle)
106
{
107
if
(handle == NULL)
108
{
109
return
RTE_STATUS_INVALID_PARAM
;
110
}
111
if
(
s_osadapter
== NULL)
112
{
113
return
RTE_STATUS_NOT_INITIALIZED
;
114
}
115
if
(
s_osadapter
->stop == NULL)
116
{
117
return
RTE_STATUS_NOT_SUPPORTED
;
118
}
119
return
s_osadapter
->stop(handle);
120
}
121
122
rte_status_t
rte_timer_destroy
(
rte_timer_handle_t
handle)
123
{
124
if
(handle == NULL)
125
{
126
return
RTE_STATUS_INVALID_PARAM
;
127
}
128
if
(
s_osadapter
== NULL)
129
{
130
return
RTE_STATUS_NOT_INITIALIZED
;
131
}
132
if
(
s_osadapter
->destroy == NULL)
133
{
134
return
RTE_STATUS_NOT_SUPPORTED
;
135
}
136
return
s_osadapter
->destroy(handle);
137
}
138
139
rte_status_t
rte_timer_now
(
rte_timestamp_ms_t
*out_now_ms)
140
{
141
if
(out_now_ms == NULL)
142
{
143
return
RTE_STATUS_INVALID_PARAM
;
144
}
145
*out_now_ms = 0U;
146
if
(
s_osadapter
== NULL)
147
{
148
return
RTE_STATUS_NOT_INITIALIZED
;
149
}
150
if
(
s_osadapter
->now == NULL)
151
{
152
return
RTE_STATUS_NOT_SUPPORTED
;
153
}
154
return
s_osadapter
->now(out_now_ms);
155
}
rte_lifecycle_check_setup_allowed
rte_status_t rte_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
Definition
rte_lifecycle.c:41
rte_status_t
rte_status_t
Common result/status codes.
Definition
rte_status.h:27
RTE_STATUS_OK
@ RTE_STATUS_OK
Definition
rte_status.h:28
RTE_STATUS_INVALID_PARAM
@ RTE_STATUS_INVALID_PARAM
Definition
rte_status.h:29
RTE_STATUS_NOT_SUPPORTED
@ RTE_STATUS_NOT_SUPPORTED
Definition
rte_status.h:34
RTE_STATUS_NOT_INITIALIZED
@ RTE_STATUS_NOT_INITIALIZED
Definition
rte_status.h:30
rte_timer_now
rte_status_t rte_timer_now(rte_timestamp_ms_t *out_now_ms)
Returns the current monotonic time base used by all timers.
Definition
rte_timer.c:139
rte_timer_stop
rte_status_t rte_timer_stop(rte_timer_handle_t handle)
Stops a running timer; safe to call on an already-stopped timer.
Definition
rte_timer.c:105
rte_timer_start
rte_status_t rte_timer_start(rte_timer_handle_t handle)
Starts (or restarts) a created timer.
Definition
rte_timer.c:79
rte_timer_handle_t
struct rte_timer_impl_s * rte_timer_handle_t
Definition
rte_timer.h:31
rte_timer_create
rte_status_t rte_timer_create(rte_timer_storage_t *storage, const rte_timer_config_t *config, rte_timer_handle_t *out_handle)
Creates a timer bound to caller-owned storage. Does not start it.
Definition
rte_timer.c:44
rte_timer_destroy
rte_status_t rte_timer_destroy(rte_timer_handle_t handle)
Destroys a timer, releasing any OSAdapter resources bound to it.
Definition
rte_timer.c:122
rte_timestamp_ms_t
uint64_t rte_timestamp_ms_t
Definition
rte_types.h:30
s_osadapter
static const rte_osadapter_clocksync_t * s_osadapter
Definition
rte_clocksync.c:18
rte_lifecycle.h
Process-wide application setup-phase lock (ADR-026).
rte_osadapter_timer.h
OSAdapter interface for monotonic timers and timestamps.
rte_osadapter_timer_register
rte_status_t rte_osadapter_timer_register(const rte_osadapter_timer_t *adapter)
Registers the OSAdapter timer implementation.
Definition
rte_timer.c:25
rte_timer.h
OS Abstraction Layer - Timer service.
rte_osadapter_timer_t
OSAdapter timer operations vtable.
Definition
rte_osadapter_timer.h:21
rte_timer_config_t
Configuration for rte_timer_create().
Definition
rte_timer.h:53
rte_timer_config_t::callback
rte_timer_callback_t callback
Definition
rte_timer.h:56
rte_timer_config_t::period_ms
rte_duration_ms_t period_ms
Definition
rte_timer.h:55
src
oal
timer
rte_timer.c
Generated by
1.18.0