Solaris Software
Toggle main menu visibility
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
* ---------------------------------------------------------------- */
9
#include "
spp/core/returnTypes.h
"
10
#include "
spp/hal/hal.h
"
11
#include "
spp/hal/uart/uart.h
"
12
13
#ifdef SPP_ENCRYPTION
14
#include "
external/encryption/cipher.h
"
15
#include <string.h>
16
#endif
17
18
/* ----------------------------------------------------------------
19
* PUBLIC FUNCTIONS
20
* ---------------------------------------------------------------- */
21
22
SPP_RetVal_t
SPP_HAL_UART_portInit
(
void
)
23
{
24
SPP_RetVal_t
ret =
K_SPP_OK
;
25
const
SPP_HalPort_t
*p_port =
SPP_HAL_getPort
();
26
27
if
(p_port == NULL)
28
{
29
ret =
K_SPP_ERROR_NULL_POINTER
;
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
44
SPP_RetVal_t
SPP_HAL_UART_transmit
(
const
void
*p_data,
spp_uint16_t
len)
45
{
46
const
SPP_HalPort_t
*p_port =
SPP_HAL_getPort
();
47
48
if
(p_port == NULL || p_data == NULL)
49
{
50
return
K_SPP_ERROR_NULL_POINTER
;
51
}
52
53
if
(p_port->
uart
.
uartTransmit
== NULL)
54
{
55
return
K_SPP_ERROR
;
56
}
57
58
#ifdef SPP_ENCRYPTION
59
spp_uint8_t
encBuf[
K_SPP_CIPHER_FRAME_LEN
];
60
spp_uint16_t
encLen = 0U;
61
62
memcpy(encBuf, p_data, len);
63
64
SPP_RetVal_t
ret =
SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket
(encBuf, &encLen);
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
76
SPP_RetVal_t
SPP_HAL_UART_read
(
void
*p_data,
spp_uint32_t
len,
spp_uint32_t
*p_readBytes)
77
{
78
const
SPP_HalPort_t
*p_port =
SPP_HAL_getPort
();
79
80
if
(p_port == NULL || p_data == NULL || p_readBytes == NULL)
81
{
82
return
K_SPP_ERROR_NULL_POINTER
;
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_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket
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
cipher.h
SPP packet AES-128-GCM cipher context.
K_SPP_CIPHER_FRAME_LEN
#define K_SPP_CIPHER_FRAME_LEN
Total output frame size after encryption.
Definition
cipher.h:45
SPP_HAL_getPort
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
hal.h
This file contains the structs that contain all the pointers to the functions that are used by the SP...
returnTypes.h
Standard return-value type used across all SPP modules.
SPP_RetVal_t
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition
returnTypes.h:24
K_SPP_OK
@ K_SPP_OK
Definition
returnTypes.h:25
K_SPP_ERROR
@ K_SPP_ERROR
Definition
returnTypes.h:26
K_SPP_ERROR_NULL_POINTER
@ K_SPP_ERROR_NULL_POINTER
Definition
returnTypes.h:30
SPP_HALUart_t::uartTransmit
SPP_RetVal_t(*) uartTransmit(const void *p_data, spp_uint32_t len)
Perform an UART transaction.
Definition
hal.h:105
SPP_HALUart_t::uartPortInit
SPP_RetVal_t(*) uartPortInit(void)
Initialise the UART port.
Definition
hal.h:94
SPP_HALUart_t::uartRead
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
SPP_HalPort_t
Ports struct that contains all the pointers to the Ports functions.
Definition
hal.h:215
SPP_HalPort_t::uart
SPP_HALUart_t uart
Definition
hal.h:220
spp_uint16_t
uint16_t spp_uint16_t
Definition
types.h:29
spp_uint32_t
uint32_t spp_uint32_t
Definition
types.h:31
spp_uint8_t
uint8_t spp_uint8_t
Definition
types.h:27
SPP_HAL_UART_transmit
SPP_RetVal_t SPP_HAL_UART_transmit(const void *p_data, spp_uint16_t len)
Perform UART transaction.
Definition
uart.c:44
SPP_HAL_UART_read
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_HAL_UART_portInit
SPP_RetVal_t SPP_HAL_UART_portInit(void)
Initialise the UART port.
Definition
uart.c:22
uart.h
SPP UART HAL API — dispatches through the registered HAL port.
solaris-v2
spp
hal
uart
uart.c
Generated by
1.18.0