Solaris Software
Toggle main menu visibility
Loading...
Searching...
No Matches
halStub.c
Go to the documentation of this file.
1
/**
2
* @file halStub.c
3
* @brief Stub HAL port for host-side unit testing.
4
*
5
* All SPI, GPIO, UART, and storage functions return K_SPP_OK without doing any
6
* real hardware access. This allows the full SPP service layer to be
7
* exercised on a development machine without an attached MCU.
8
*/
9
10
#include "
spp/hal/hal.h
"
11
#include "
spp/core/returnTypes.h
"
12
#include "
spp/core/types.h
"
13
14
#include <stdint.h>
15
#include <sys/time.h>
16
17
/* ----------------------------------------------------------------
18
* Stub implementations
19
* ---------------------------------------------------------------- */
20
21
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_spiBusInit
(
void
) {
return
K_SPP_OK
; }
22
static
void
*
SPP_PORTS_HAL_STUB_spiGetHandle
(
spp_uint8_t
deviceIdx) { (void)deviceIdx;
return
(
void
*)0x1; }
23
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_spiDeviceInit
(
void
*p_handle) { (void)p_handle;
return
K_SPP_OK
; }
24
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_spiTransmit
(
void
*p_handle,
spp_uint8_t
*p_data,
spp_uint8_t
len)
25
{
26
(void)p_handle; (void)p_data; (void)len;
27
return
K_SPP_OK
;
28
}
29
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_spiDeviceSetSpeed
(
void
*p_handle,
spp_uint32_t
speedHz)
30
{
31
(void)p_handle; (void)speedHz;
32
return
K_SPP_OK
;
33
}
34
35
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_gpioConfigInterrupt
(
spp_uint32_t
pin,
spp_uint32_t
t,
spp_uint32_t
pull)
36
{
37
(void)pin; (void)t; (void)pull;
38
return
K_SPP_OK
;
39
}
40
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_gpioRegisterIsr
(
spp_uint32_t
pin,
void
*p_ctx) { (void)pin; (void)p_ctx;
return
K_SPP_OK
; }
41
42
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_storageInit
(
void
) {
return
K_SPP_OK
; }
43
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_storageWrite
(
const
void
*p_buffer,
spp_uint32_t
first_block,
spp_uint16_t
count)
44
{
45
(void)p_buffer; (void)first_block; (void)count;
46
return
K_SPP_OK
;
47
}
48
49
static
spp_uint32_t
SPP_PORTS_HAL_STUB_getTimeMs
(
void
)
50
{
51
struct
timeval tv;
52
gettimeofday(&tv, NULL);
53
return
(
spp_uint32_t
)((tv.tv_sec * 1000UL) + (tv.tv_usec / 1000UL));
54
}
55
56
static
void
SPP_PORTS_HAL_STUB_delayMs
(
spp_uint32_t
ms) { (void)ms; }
57
58
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_uartPortInit
(
void
) {
return
K_SPP_OK
; }
59
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_uartTransmit
(
const
void
*p_data,
spp_uint32_t
len) { (void)p_data; (void)len;
return
K_SPP_OK
; }
60
static
SPP_RetVal_t
SPP_PORTS_HAL_STUB_uartRead
(
void
*p_data,
spp_uint32_t
len,
spp_uint32_t
*p_readBytes)
61
{
62
(void)p_data; (void)len;
63
if
(p_readBytes != NULL)
64
{
65
*p_readBytes = 0U;
66
}
67
return
K_SPP_OK
;
68
}
69
70
/* ----------------------------------------------------------------
71
* Port descriptor
72
* ---------------------------------------------------------------- */
73
74
const
SPP_HalPort_t
g_stubHalPort
= {
75
.spi = {
76
.spiBusInit =
SPP_PORTS_HAL_STUB_spiBusInit
,
77
.spiGetHandle =
SPP_PORTS_HAL_STUB_spiGetHandle
,
78
.spiDeviceInit =
SPP_PORTS_HAL_STUB_spiDeviceInit
,
79
.spiTransmit =
SPP_PORTS_HAL_STUB_spiTransmit
,
80
.spiDeviceSetSpeed =
SPP_PORTS_HAL_STUB_spiDeviceSetSpeed
,
81
},
82
.gpio = {
83
.gpioConfigInterrupt =
SPP_PORTS_HAL_STUB_gpioConfigInterrupt
,
84
.gpioRegisterIsr =
SPP_PORTS_HAL_STUB_gpioRegisterIsr
,
85
},
86
.storage = {
87
.storageInit =
SPP_PORTS_HAL_STUB_storageInit
,
88
.storageWrite =
SPP_PORTS_HAL_STUB_storageWrite
,
89
},
90
.time = {
91
.getTimeMs =
SPP_PORTS_HAL_STUB_getTimeMs
,
92
.delayMs =
SPP_PORTS_HAL_STUB_delayMs
,
93
},
94
.uart = {
95
.uartPortInit =
SPP_PORTS_HAL_STUB_uartPortInit
,
96
.uartTransmit =
SPP_PORTS_HAL_STUB_uartTransmit
,
97
.uartRead =
SPP_PORTS_HAL_STUB_uartRead
,
98
},
99
};
SPP_PORTS_HAL_STUB_spiGetHandle
static void * SPP_PORTS_HAL_STUB_spiGetHandle(spp_uint8_t deviceIdx)
Definition
halStub.c:22
SPP_PORTS_HAL_STUB_gpioConfigInterrupt
static SPP_RetVal_t SPP_PORTS_HAL_STUB_gpioConfigInterrupt(spp_uint32_t pin, spp_uint32_t t, spp_uint32_t pull)
Definition
halStub.c:35
SPP_PORTS_HAL_STUB_spiDeviceInit
static SPP_RetVal_t SPP_PORTS_HAL_STUB_spiDeviceInit(void *p_handle)
Definition
halStub.c:23
SPP_PORTS_HAL_STUB_spiTransmit
static SPP_RetVal_t SPP_PORTS_HAL_STUB_spiTransmit(void *p_handle, spp_uint8_t *p_data, spp_uint8_t len)
Definition
halStub.c:24
SPP_PORTS_HAL_STUB_storageInit
static SPP_RetVal_t SPP_PORTS_HAL_STUB_storageInit(void)
Definition
halStub.c:42
SPP_PORTS_HAL_STUB_spiDeviceSetSpeed
static SPP_RetVal_t SPP_PORTS_HAL_STUB_spiDeviceSetSpeed(void *p_handle, spp_uint32_t speedHz)
Definition
halStub.c:29
g_stubHalPort
const SPP_HalPort_t g_stubHalPort
Definition
halStub.c:74
SPP_PORTS_HAL_STUB_storageWrite
static SPP_RetVal_t SPP_PORTS_HAL_STUB_storageWrite(const void *p_buffer, spp_uint32_t first_block, spp_uint16_t count)
Definition
halStub.c:43
SPP_PORTS_HAL_STUB_uartTransmit
static SPP_RetVal_t SPP_PORTS_HAL_STUB_uartTransmit(const void *p_data, spp_uint32_t len)
Definition
halStub.c:59
SPP_PORTS_HAL_STUB_spiBusInit
static SPP_RetVal_t SPP_PORTS_HAL_STUB_spiBusInit(void)
Definition
halStub.c:21
SPP_PORTS_HAL_STUB_getTimeMs
static spp_uint32_t SPP_PORTS_HAL_STUB_getTimeMs(void)
Definition
halStub.c:49
SPP_PORTS_HAL_STUB_delayMs
static void SPP_PORTS_HAL_STUB_delayMs(spp_uint32_t ms)
Definition
halStub.c:56
SPP_PORTS_HAL_STUB_uartRead
static SPP_RetVal_t SPP_PORTS_HAL_STUB_uartRead(void *p_data, spp_uint32_t len, spp_uint32_t *p_readBytes)
Definition
halStub.c:60
SPP_PORTS_HAL_STUB_uartPortInit
static SPP_RetVal_t SPP_PORTS_HAL_STUB_uartPortInit(void)
Definition
halStub.c:58
SPP_PORTS_HAL_STUB_gpioRegisterIsr
static SPP_RetVal_t SPP_PORTS_HAL_STUB_gpioRegisterIsr(spp_uint32_t pin, void *p_ctx)
Definition
halStub.c:40
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
SPP_HalPort_t
Ports struct that contains all the pointers to the Ports functions.
Definition
hal.h:215
types.h
Portable integer types and SPI/storage configuration types for SPP.
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
solaris-v2
spp
ports
hal
stub
halStub.c
Generated by
1.18.0