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_channel.c
Go to the documentation of this file.
1
8
#include "
rte/redundancy/channel_link/rte_channel.h
"
9
#include "
rte/utils/lifecycle/rte_lifecycle.h
"
10
12
14
16
18
20
21
23
rte_status_t
rte_channel_init
(
rte_channel_storage_t
*storage,
24
const
rte_channel_config_t
*config)
25
{
26
rte_status_t
lifecycle_status;
27
28
if
((storage == NULL) || (config == NULL))
29
{
30
return
RTE_STATUS_INVALID_PARAM
;
31
}
32
if
((config->
send
== NULL) || (config->
recv
== NULL))
33
{
34
return
RTE_STATUS_INVALID_PARAM
;
35
}
36
/* REQ-LIFECYCLE-001 (ADR-026): a channel is a setup-only resource - refuse once the
37
* application's setup phase has been locked. */
38
lifecycle_status =
rte_lifecycle_check_setup_allowed
();
39
if
(lifecycle_status !=
RTE_STATUS_OK
)
40
{
41
return
lifecycle_status;
42
}
43
44
storage->
config
= *config;
45
storage->
health
.
send_count
= 0U;
46
storage->
health
.
send_error_count
= 0U;
47
storage->
health
.
receive_count
= 0U;
48
storage->
health
.
receive_error_count
= 0U;
49
storage->
health
.
is_healthy
=
true
;
50
storage->
health
.
last_error
=
RTE_STATUS_OK
;
51
storage->
initialized
=
true
;
52
53
return
RTE_STATUS_OK
;
54
}
55
56
rte_status_t
rte_channel_send
(
rte_channel_t
*handle,
57
const
void
*data,
58
size_t
data_size)
59
{
60
rte_status_t
status;
61
62
if
((handle == NULL) || (data == NULL) || (data_size == 0U))
63
{
64
return
RTE_STATUS_INVALID_PARAM
;
65
}
66
if
(!handle->
initialized
)
67
{
68
return
RTE_STATUS_NOT_INITIALIZED
;
69
}
70
71
status = handle->
config
.
send
(handle->
config
.
channel_handle
, data, data_size);
72
if
(status ==
RTE_STATUS_OK
)
73
{
74
handle->
health
.
send_count
++;
75
}
76
else
77
{
78
handle->
health
.
send_error_count
++;
79
handle->
health
.
last_error
= status;
80
}
81
return
status;
82
}
83
84
rte_status_t
rte_channel_receive
(
rte_channel_t
*handle,
85
void
*data,
86
size_t
data_size,
87
uint32_t timeout_ms)
88
{
89
rte_status_t
status;
90
91
if
((handle == NULL) || (data == NULL) || (data_size == 0U))
92
{
93
return
RTE_STATUS_INVALID_PARAM
;
94
}
95
if
(!handle->
initialized
)
96
{
97
return
RTE_STATUS_NOT_INITIALIZED
;
98
}
99
100
status = handle->
config
.
recv
(handle->
config
.
channel_handle
, data, data_size, timeout_ms);
101
if
(status ==
RTE_STATUS_OK
)
102
{
103
handle->
health
.
receive_count
++;
104
}
105
else
106
{
107
handle->
health
.
receive_error_count
++;
108
handle->
health
.
last_error
= status;
109
}
110
return
status;
111
}
112
113
rte_status_t
rte_channel_get_health
(
const
rte_channel_t
*handle,
114
rte_channel_health_t
*out_health)
115
{
116
if
((handle == NULL) || (out_health == NULL))
117
{
118
return
RTE_STATUS_INVALID_PARAM
;
119
}
120
*out_health = handle->
health
;
121
return
RTE_STATUS_OK
;
122
}
123
124
const
char
*
rte_channel_get_name
(
const
rte_channel_t
*handle)
125
{
126
if
(handle == NULL)
127
{
128
return
NULL;
129
}
130
return
handle->
config
.
name
;
131
}
132
133
rte_status_t
rte_channel_set_healthy
(
rte_channel_t
*handle,
134
bool
is_healthy)
135
{
136
if
(handle == NULL)
137
{
138
return
RTE_STATUS_INVALID_PARAM
;
139
}
140
handle->
health
.
is_healthy
= is_healthy;
141
return
RTE_STATUS_OK
;
142
}
143
144
rte_status_t
rte_channel_destroy
(
rte_channel_t
*handle)
145
{
146
/* No dynamic memory to free - handle is caller-allocated. */
147
if
(handle == NULL)
148
{
149
return
RTE_STATUS_OK
;
150
}
151
handle->
initialized
=
false
;
152
return
RTE_STATUS_OK
;
153
}
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_INITIALIZED
@ RTE_STATUS_NOT_INITIALIZED
Definition
rte_status.h:30
rte_channel_get_name
const char * rte_channel_get_name(const rte_channel_t *handle)
Returns this channel's name, as given in rte_channel_config_t::name at rte_channel_init() time.
Definition
rte_channel.c:124
rte_channel_destroy
rte_status_t rte_channel_destroy(rte_channel_t *handle)
Destroys a vital channel instance.
Definition
rte_channel.c:144
rte_channel_receive
rte_status_t rte_channel_receive(rte_channel_t *handle, void *data, size_t data_size, uint32_t timeout_ms)
Receives data on this channel via its OSAdapter receive callback.
Definition
rte_channel.c:84
rte_channel_set_healthy
rte_status_t rte_channel_set_healthy(rte_channel_t *handle, bool is_healthy)
Marks this channel healthy/unhealthy.
Definition
rte_channel.c:133
rte_channel_get_health
rte_status_t rte_channel_get_health(const rte_channel_t *handle, rte_channel_health_t *out_health)
Queries this channel's health statistics.
Definition
rte_channel.c:113
rte_channel_t
rte_channel_storage_t rte_channel_t
Opaque handle to a vital channel instance.
Definition
rte_channel.h:127
rte_channel_init
rte_status_t rte_channel_init(rte_channel_storage_t *storage, const rte_channel_config_t *config)
Initializes one vital channel over a caller-supplied transport.
Definition
rte_channel.c:23
rte_channel_send
rte_status_t rte_channel_send(rte_channel_t *handle, const void *data, size_t data_size)
Sends data on this channel via its OSAdapter send callback.
Definition
rte_channel.c:56
rte_channel.h
A single redundant "channel": an opaque transport handle plus send/receive callbacks,...
rte_lifecycle.h
Process-wide application setup-phase lock (ADR-026).
rte_channel_config_t
Configuration for rte_channel_init().
Definition
rte_channel.h:90
rte_channel_config_t::channel_handle
void * channel_handle
Definition
rte_channel.h:94
rte_channel_config_t::send
rte_channel_send_fn send
Definition
rte_channel.h:96
rte_channel_config_t::recv
rte_channel_recv_fn recv
Definition
rte_channel.h:98
rte_channel_config_t::name
const char * name
Definition
rte_channel.h:105
rte_channel_health_t
Health statistics for one vital channel.
Definition
rte_channel.h:39
rte_channel_health_t::is_healthy
bool is_healthy
Definition
rte_channel.h:51
rte_channel_health_t::receive_error_count
uint32_t receive_error_count
Definition
rte_channel.h:47
rte_channel_health_t::send_error_count
uint32_t send_error_count
Definition
rte_channel.h:43
rte_channel_health_t::send_count
uint32_t send_count
Definition
rte_channel.h:41
rte_channel_health_t::receive_count
uint32_t receive_count
Definition
rte_channel.h:45
rte_channel_health_t::last_error
rte_status_t last_error
Definition
rte_channel.h:53
rte_channel_storage_t
Storage for one vital channel instance (opaque to caller).
Definition
rte_channel.h:114
rte_channel_storage_t::config
rte_channel_config_t config
Definition
rte_channel.h:115
rte_channel_storage_t::health
rte_channel_health_t health
Definition
rte_channel.h:116
rte_channel_storage_t::initialized
bool initialized
Definition
rte_channel.h:117
src
redundancy
channel_link
rte_channel.c
Generated by
1.18.0