Solaris Software
Loading...
Searching...
No Matches
uart.c
Go to the documentation of this file.
1/**
2 * @file uart.c
3 * @brief UART telemetry consumer service implementation.
4 *
5 * The service keeps a small FIFO of SPP packets delivered by the PUBSUB
6 * router. Every superloop tick, @ref SPP_SERVICES_UART_consumeData transmits
7 * the oldest pending packet over the UART HAL, byte-for-byte.
8 */
9
10/* ----------------------------------------------------------------
11 * INCLUDES
12 * ---------------------------------------------------------------- */
14
15#include "spp/hal/uart/uart.h"
16
17/* ----------------------------------------------------------------
18 * STATIC FUNCTIONS DECLARATIONS
19 * ---------------------------------------------------------------- */
23
24/* ----------------------------------------------------------------
25 * VARIABLES
26 * ---------------------------------------------------------------- */
31
33
35 .priority = K_UART_CONSUMER_PRIO,
36 .p_nameConsumer = "uart",
37 .tiemoutMs = K_UART_TIMEOUT_MS,
39 .deliverToMailbox = SPP_SERVICES_UART_deliverToMailbox,
40 .consumeData = SPP_SERVICES_UART_consumeData,
41};
42
43/* ----------------------------------------------------------------
44 * PUBLIC FUNCTIONS
45 * ---------------------------------------------------------------- */
50
55
56/* ----------------------------------------------------------------
57 * STATIC FUNCTIONS
58 * ---------------------------------------------------------------- */
59
60/**
61 * @brief Initialise the UART port and clear the packet mailbox.
62 * @return K_SPP_OK on success, error code from the HAL otherwise.
63 */
73
74/**
75 * @brief Store a packet delivered by the PUBSUB router.
76 * @param packet Packet dispatched by the router.
77 * @return K_SPP_OK always; when the FIFO is full the oldest packet is dropped.
78 */
95
96/**
97 * @brief Transmit the oldest pending SPP packet over UART.
98 * @param p_data Unused (context pointer reserved for future use).
99 * @return K_SPP_OK on success (or empty mailbox), error code from the HAL otherwise.
100 */
102{
103 (void)p_data;
104
105 if (s_mailboxCount == 0U)
106 {
107 return K_SPP_OK;
108 }
109
111 if (ret == K_SPP_OK)
112 {
115 }
116
117 return ret;
118}
SPP_RetVal_t SPP_HAL_UART_transmit(const void *p_data, spp_uint16_t len)
Perform UART transaction.
Definition uart.c:44
SPP_RetVal_t SPP_HAL_UART_portInit(void)
Initialise the UART port.
Definition uart.c:22
SPP UART HAL API — dispatches through the registered HAL port.
SPP_Packet_t
Definition packet.h:79
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition returnTypes.h:24
@ K_SPP_ERROR_NOT_INITIALIZED
Definition returnTypes.h:31
@ K_SPP_OK
Definition returnTypes.h:25
const SPP_SERVICE_ConsumerContract_t * SPP_SERVICES_UART_getConsumerContract(void)
Get the UART consumer contract.
Definition uart.c:46
static spp_uint8_t s_mailboxHead
Definition uart.c:28
static SPP_Packet_t s_mailbox[K_UART_MAILBOX_SIZE]
Definition uart.c:27
SPP_RetVal_t SPP_SERVICES_UART_getInitStatus(void)
Get the result of the last UART service init.
Definition uart.c:51
static SPP_RetVal_t s_initStatus
Definition uart.c:32
static spp_uint8_t s_mailboxTail
Definition uart.c:29
static spp_uint8_t s_mailboxCount
Definition uart.c:30
static SPP_RetVal_t SPP_SERVICES_UART_consumeData(void *p_data)
Transmit the oldest pending SPP packet over UART.
Definition uart.c:101
static const SPP_SERVICE_ConsumerContract_t g_uartConsumerContract
Definition uart.c:34
static SPP_RetVal_t SPP_SERVICES_UART_deliverToMailbox(const SPP_Packet_t packet)
Store a packet delivered by the PUBSUB router.
Definition uart.c:79
static SPP_RetVal_t SPP_SERVICES_UART_init(void)
Initialise the UART port and clear the packet mailbox.
Definition uart.c:64
UART telemetry consumer service.
#define K_UART_TIMEOUT_MS
Definition uart.h:21
#define K_UART_MAILBOX_SIZE
Definition uart.h:22
#define K_UART_CONSUMER_PRIO
Definition uart.h:20
Describes the contract of a consumer module. This module needs to have:
Definition service.h:40
uint16_t spp_uint16_t
Definition types.h:29
uint8_t spp_uint8_t
Definition types.h:27