Solaris Software
Loading...
Searching...
No Matches
uart.c
Go to the documentation of this file.
1/**
2 * @file uart.c
3 * @brief HAL UART functions implementation. Calls the function pointer and returns the result.
4 */
5
6/* ----------------------------------------------------------------
7 * INCLUDES
8 * ---------------------------------------------------------------- */
10#include "spp/hal/hal.h"
11#include "spp/hal/uart/uart.h"
12
13#ifdef SPP_ENCRYPTION
15#include <string.h>
16#endif
17
18/* ----------------------------------------------------------------
19 * PUBLIC FUNCTIONS
20 * ---------------------------------------------------------------- */
21
23{
25 const SPP_HalPort_t *p_port = SPP_HAL_getPort();
26
27 if (p_port == NULL)
28 {
30 return ret;
31 }
32
33 if (p_port->uart.uartPortInit == NULL)
34 {
35 ret = K_SPP_ERROR;
36 return ret;
37 }
38
39 ret = p_port->uart.uartPortInit();
40
41 return ret;
42}
43
45{
46 const SPP_HalPort_t *p_port = SPP_HAL_getPort();
47
48 if (p_port == NULL || p_data == NULL)
49 {
51 }
52
53 if (p_port->uart.uartTransmit == NULL)
54 {
55 return K_SPP_ERROR;
56 }
57
58#ifdef SPP_ENCRYPTION
60 spp_uint16_t encLen = 0U;
61
62 memcpy(encBuf, p_data, len);
63
65 if (ret != K_SPP_OK)
66 {
67 return ret;
68 }
69
70 return p_port->uart.uartTransmit(encBuf, (spp_uint32_t)encLen);
71#else
72 return p_port->uart.uartTransmit(p_data, len);
73#endif
74}
75
77{
78 const SPP_HalPort_t *p_port = SPP_HAL_getPort();
79
80 if (p_port == NULL || p_data == NULL || p_readBytes == NULL)
81 {
83 }
84
85 if (p_port->uart.uartRead == NULL)
86 {
87 return K_SPP_ERROR;
88 }
89
90 return p_port->uart.uartRead(p_data, len, p_readBytes);
91}
SPP_RetVal_t SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket(spp_uint8_t *p_buffer, spp_uint16_t *p_outSize)
Encrypt an SPP packet buffer in-place with AES-128-GCM.
Definition cipher.c:56
SPP packet AES-128-GCM cipher context.
#define K_SPP_CIPHER_FRAME_LEN
Total output frame size after encryption.
Definition cipher.h:45
const SPP_HalPort_t * SPP_HAL_getPort(void)
This function is used to get the pointers to the functions that are used by the SPP library....
Definition hal.c:52
This file contains the structs that contain all the pointers to the functions that are used by the SP...
Standard return-value type used across all SPP modules.
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition returnTypes.h:24
@ K_SPP_OK
Definition returnTypes.h:25
@ K_SPP_ERROR
Definition returnTypes.h:26
@ K_SPP_ERROR_NULL_POINTER
Definition returnTypes.h:30
SPP_RetVal_t(*) uartTransmit(const void *p_data, spp_uint32_t len)
Perform an UART transaction.
Definition hal.h:105
SPP_RetVal_t(*) uartPortInit(void)
Initialise the UART port.
Definition hal.h:94
SPP_RetVal_t(*) uartRead(void *p_data, spp_uint32_t len, spp_uint32_t *p_readBytes)
Reads data from the ESP32 UART.
Definition hal.h:115
Ports struct that contains all the pointers to the Ports functions.
Definition hal.h:215
SPP_HALUart_t uart
Definition hal.h:220
uint16_t spp_uint16_t
Definition types.h:29
uint32_t spp_uint32_t
Definition types.h:31
uint8_t spp_uint8_t
Definition types.h:27
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_read(void *p_data, spp_uint32_t len, spp_uint32_t *p_readBytes)
Perform UART read.
Definition uart.c:76
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.