emul: Add syscall support for fuel gauge emulators

In order to ease user thread testing with fuel gauges, enable syscalls for
the fuel gauge emulator backend API.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
This commit is contained in:
Aaron Massey 2023-08-13 14:04:33 -06:00 committed by Fabio Baltieri
parent 77998b2171
commit 8035ec69fa
4 changed files with 38 additions and 4 deletions

View file

@ -6,3 +6,8 @@ add_subdirectory_ifdef(CONFIG_SBS_GAUGE_NEW_API sbs_gauge)
add_subdirectory_ifdef(CONFIG_MAX17048 max17048)
zephyr_library_sources_ifdef(CONFIG_USERSPACE fuel_gauge_syscall_handlers.c)
if (CONFIG_EMUL AND CONFIG_USERSPACE)
zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/drivers/emul_fuel_gauge.h)
zephyr_library_sources(emul_fuel_gauge_syscall_handlers.c)
endif()

View file

@ -0,0 +1,25 @@
/*
* Copyright 2023 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/syscall_handler.h>
#include <zephyr/drivers/emul_fuel_gauge.h>
/* Emulator syscalls just need to exist as stubs as these are only called by tests. */
static inline int z_vrfy_emul_fuel_gauge_is_battery_cutoff(const struct emul *target, bool *cutoff)
{
return z_impl_emul_fuel_gauge_is_battery_cutoff(target, cutoff);
}
#include <syscalls/emul_fuel_gauge_is_battery_cutoff_mrsh.c>
static inline int z_vrfy_emul_fuel_gauge_set_battery_charging(const struct emul *target,
uint32_t uV, int uA)
{
return z_impl_emul_fuel_gauge_set_battery_charging(target, uV, uA);
}
#include <syscalls/emul_fuel_gauge_set_battery_charging_mrsh.c>

View file

@ -54,8 +54,9 @@ __subsystem struct fuel_gauge_emul_driver_api {
* @retval 0 If successful.
* @retval -EINVAL if mV or mA are 0.
*/
static inline int emul_fuel_gauge_set_battery_charging(const struct emul *target, uint32_t uV,
int uA)
__syscall int emul_fuel_gauge_set_battery_charging(const struct emul *target, uint32_t uV, int uA);
static inline int z_impl_emul_fuel_gauge_set_battery_charging(const struct emul *target,
uint32_t uV, int uA)
{
const struct fuel_gauge_emul_driver_api *backend_api =
(const struct fuel_gauge_emul_driver_api *)target->backend_api;
@ -76,7 +77,8 @@ static inline int emul_fuel_gauge_set_battery_charging(const struct emul *target
* @retval 0 If successful.
* @retval -ENOTSUP if not supported by emulator.
*/
static inline int emul_fuel_gauge_is_battery_cutoff(const struct emul *target, bool *cutoff)
__syscall int emul_fuel_gauge_is_battery_cutoff(const struct emul *target, bool *cutoff);
static inline int z_impl_emul_fuel_gauge_is_battery_cutoff(const struct emul *target, bool *cutoff)
{
const struct fuel_gauge_emul_driver_api *backend_api =
(const struct fuel_gauge_emul_driver_api *)target->backend_api;
@ -91,6 +93,8 @@ static inline int emul_fuel_gauge_is_battery_cutoff(const struct emul *target, b
}
#endif
#include <syscalls/emul_fuel_gauge.h>
/**
* @}
*/

View file

@ -344,7 +344,7 @@ ZTEST_USER_F(sbs_gauge_new_api, test_get_buffer_props__returns_ok)
zassert_ok(ret);
}
ZTEST_F(sbs_gauge_new_api, test_charging_5v_3a)
ZTEST_USER_F(sbs_gauge_new_api, test_charging_5v_3a)
{
/* Validate what props are supported by the driver */
uint32_t expected_uV = 5000 * 1000;