Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
Channel Link (single redundant link)

Files

 One redundant channel: validates parameters, then dispatches to its configured send/recv callbacks, tracking health as a side effect (ADR-025).

Data Structures

struct  rte_channel_health_t
 Health statistics for one vital channel. More...
struct  rte_channel_config_t
 Configuration for rte_channel_init(). More...
struct  rte_channel_storage_t
 Storage for one vital channel instance (opaque to caller). More...

Typedefs

typedef rte_status_t(*) rte_channel_send_fn(void *channel_handle, const void *data, size_t data_size)
 OSAdapter send callback: transmits on this channel's underlying transport.
typedef rte_status_t(*) rte_channel_recv_fn(void *channel_handle, void *data, size_t data_size, uint32_t timeout_ms)
 OSAdapter receive callback: reads from this channel's underlying transport.
typedef rte_channel_storage_t rte_channel_t
 Opaque handle to a vital channel instance.

Functions

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.
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.
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.
rte_status_t rte_channel_get_health (const rte_channel_t *handle, rte_channel_health_t *out_health)
 Queries this channel's health statistics.
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.
rte_status_t rte_channel_set_healthy (rte_channel_t *handle, bool is_healthy)
 Marks this channel healthy/unhealthy.
rte_status_t rte_channel_destroy (rte_channel_t *handle)
 Destroys a vital channel instance.

Detailed Description

Typedef Documentation

◆ rte_channel_send_fn

typedef rte_status_t(*) rte_channel_send_fn(void *channel_handle, const void *data, size_t data_size)

OSAdapter send callback: transmits on this channel's underlying transport.

Parameters
[in]channel_handleOpaque transport handle (as supplied in rte_channel_config_t::channel_handle)
[in]dataData to send
[in]data_sizeSize of data in bytes
Returns
RTE_STATUS_OK on success; RTE_STATUS_TIMEOUT if the operation times out; RTE_STATUS_HARDWARE_FAULT on any other send error.

Definition at line 67 of file rte_channel.h.

◆ rte_channel_recv_fn

typedef rte_status_t(*) rte_channel_recv_fn(void *channel_handle, void *data, size_t data_size, uint32_t timeout_ms)

OSAdapter receive callback: reads from this channel's underlying transport.

Parameters
[in]channel_handleOpaque transport handle
[out]dataBuffer to receive data
[in]data_sizeSize of data buffer
[in]timeout_msTimeout in milliseconds
Returns
RTE_STATUS_OK on success; RTE_STATUS_TIMEOUT if the operation times out; RTE_STATUS_HARDWARE_FAULT on any other receive error.

Definition at line 82 of file rte_channel.h.

◆ rte_channel_t

Opaque handle to a vital channel instance.

Created by rte_channel_init(); used directly, or registered into a rte_voter_t (N-way voting) or rte_cross_comparator_t (2-way comparison) for the redundancy/comparison use case.

Definition at line 127 of file rte_channel.h.

Function Documentation

◆ 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.

Parameters
[out]storagePre-allocated storage. Must not be NULL.
[in]configConfiguration with send/recv callbacks. Must not be NULL; config->send and config->recv must not be NULL.
Returns
RTE_STATUS_OK on success
RTE_STATUS_INVALID_PARAM if storage or config is NULL, or config->send/config->recv is NULL
Precondition
storage != NULL
config != NULL, config->send != NULL, config->recv != NULL
Postcondition
On success, storage is initialized with is_healthy = true and all counters at 0.
Safety:
No dynamic memory allocation. Performs no I/O itself - the underlying transport must already be operational.

REQ-CHANNEL-001: No dynamic allocation; caller supplies storage. REQ-CHANNEL-002: Rejects a NULL config->send/config->recv.

Local makros Local types declarations Local variables declarations Global variables declarations Local function declarations Global functions

Definition at line 23 of file rte_channel.c.

◆ 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.

Parameters
[in]handleVital channel handle. Must not be NULL and must have been initialized.
[in]dataData to send. Must not be NULL.
[in]data_sizeSize of data in bytes. Must be > 0.
Returns
RTE_STATUS_OK on success
RTE_STATUS_INVALID_PARAM if handle/data is NULL, data_size is 0, or handle was never initialized
Whatever config->send() itself returns on failure (typically RTE_STATUS_TIMEOUT or RTE_STATUS_HARDWARE_FAULT)
Postcondition
health.send_count or health.send_error_count is incremented; on failure, health.last_error is updated.

REQ-CHANNEL-003: Dispatches to config->send and updates health counters on every call, regardless of outcome.

Definition at line 56 of file rte_channel.c.

◆ 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.

Parameters
[in]handleVital channel handle. Must not be NULL and must have been initialized.
[out]dataBuffer to receive data. Must not be NULL.
[in]data_sizeSize of data buffer. Must be > 0.
[in]timeout_msTimeout passed to config->recv().
Returns
RTE_STATUS_OK on success
RTE_STATUS_INVALID_PARAM if handle/data is NULL, data_size is 0, or handle was never initialized
Whatever config->recv() itself returns on failure
Postcondition
health.receive_count or health.receive_error_count is incremented; on failure, health.last_error is updated.

REQ-CHANNEL-003: Dispatches to config->recv and updates health counters on every call, regardless of outcome.

Definition at line 84 of file rte_channel.c.

◆ 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.

Parameters
[in]handleVital channel handle. Must not be NULL.
[out]out_healthReceives a copy of the current health state. Must not be NULL.
Returns
RTE_STATUS_OK on success
RTE_STATUS_INVALID_PARAM if handle or out_health is NULL
Safety:
Read-only; safe to call from any context.

Definition at line 113 of file rte_channel.c.

◆ 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.

Parameters
[in]handleVital channel handle. Must not be NULL.
Returns
The channel's name (may itself be NULL if none was configured, or if handle was never initialized); NULL if handle is NULL.
Safety:
Read-only; safe to call from any context.

REQ-CHANNEL-005: rte_channel_config_t::name is optional and not copied (caller-owned, must outlive the channel); returned verbatim, NULL if handle is NULL or no name was configured.

Definition at line 124 of file rte_channel.c.

◆ rte_channel_set_healthy()

rte_status_t rte_channel_set_healthy ( rte_channel_t * handle,
bool is_healthy )

Marks this channel healthy/unhealthy.

Intended for a rte_voter_t/rte_cross_comparator_t (or any other owner) to call after deciding, by its own policy, that this channel should stop (or resume) participating - this module itself never changes is_healthy on its own (a single I/O failure alone does not mark a channel unhealthy; that decision belongs to the owner tracking failures across multiple channels).

Parameters
[in]handleVital channel handle. Must not be NULL.
[in]is_healthyNew health state.
Returns
RTE_STATUS_OK on success
RTE_STATUS_INVALID_PARAM if handle is NULL

REQ-CHANNEL-004: is_healthy defaults true at init and is never cleared automatically by this module - only via this explicit call.

Definition at line 133 of file rte_channel.c.

◆ rte_channel_destroy()

rte_status_t rte_channel_destroy ( rte_channel_t * handle)

Destroys a vital channel instance.

No dynamic memory to free; the underlying transport is NOT closed (caller retains ownership of channel_handle).

Parameters
[in]handleVital channel handle. May be NULL.
Returns
RTE_STATUS_OK always (including when handle is NULL).
Safety:
Idempotent; safe to call with NULL.

Definition at line 144 of file rte_channel.c.