Solaris Software
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"
12#include "spp/core/types.h"
13
14#include <stdint.h>
15#include <sys/time.h>
16
17/* ----------------------------------------------------------------
18 * Stub implementations
19 * ---------------------------------------------------------------- */
20
22static void *SPP_PORTS_HAL_STUB_spiGetHandle(spp_uint8_t deviceIdx) { (void)deviceIdx; return (void*)0x1; }
23static SPP_RetVal_t SPP_PORTS_HAL_STUB_spiDeviceInit(void *p_handle) { (void)p_handle; return K_SPP_OK; }
25{
26 (void)p_handle; (void)p_data; (void)len;
27 return K_SPP_OK;
28}
30{
31 (void)p_handle; (void)speedHz;
32 return K_SPP_OK;
33}
34
36{
37 (void)pin; (void)t; (void)pull;
38 return K_SPP_OK;
39}
40static 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
43static 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
50{
51 struct timeval tv;
52 gettimeofday(&tv, NULL);
53 return (spp_uint32_t)((tv.tv_sec * 1000UL) + (tv.tv_usec / 1000UL));
54}
55
56static void SPP_PORTS_HAL_STUB_delayMs(spp_uint32_t ms) { (void)ms; }
57
59static 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; }
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
75 .spi = {
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 = {
93 },
94 .uart = {
95 .uartPortInit = SPP_PORTS_HAL_STUB_uartPortInit,
96 .uartTransmit = SPP_PORTS_HAL_STUB_uartTransmit,
98 },
99};
static void * SPP_PORTS_HAL_STUB_spiGetHandle(spp_uint8_t deviceIdx)
Definition halStub.c:22
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
static SPP_RetVal_t SPP_PORTS_HAL_STUB_spiDeviceInit(void *p_handle)
Definition halStub.c:23
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
static SPP_RetVal_t SPP_PORTS_HAL_STUB_storageInit(void)
Definition halStub.c:42
static SPP_RetVal_t SPP_PORTS_HAL_STUB_spiDeviceSetSpeed(void *p_handle, spp_uint32_t speedHz)
Definition halStub.c:29
const SPP_HalPort_t g_stubHalPort
Definition halStub.c:74
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
static SPP_RetVal_t SPP_PORTS_HAL_STUB_uartTransmit(const void *p_data, spp_uint32_t len)
Definition halStub.c:59
static SPP_RetVal_t SPP_PORTS_HAL_STUB_spiBusInit(void)
Definition halStub.c:21
static spp_uint32_t SPP_PORTS_HAL_STUB_getTimeMs(void)
Definition halStub.c:49
static void SPP_PORTS_HAL_STUB_delayMs(spp_uint32_t ms)
Definition halStub.c:56
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
static SPP_RetVal_t SPP_PORTS_HAL_STUB_uartPortInit(void)
Definition halStub.c:58
static SPP_RetVal_t SPP_PORTS_HAL_STUB_gpioRegisterIsr(spp_uint32_t pin, void *p_ctx)
Definition halStub.c:40
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
Ports struct that contains all the pointers to the Ports functions.
Definition hal.h:215
Portable integer types and SPI/storage configuration types for SPP.
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