LCOV - code coverage report
Current view: top level - zephyr/drivers - emul_fuel_gauge.h Coverage Total Hit
Test: new.info Lines: 100.0 % 3 3
Test Date: 2025-09-05 20:47:19

            Line data    Source code
       1            1 : /*
       2              :  * Copyright (c) 2023 Google LLC
       3              :  *
       4              :  * SPDX-License-Identifier: Apache-2.0
       5              :  */
       6              : 
       7              : /**
       8              :  * @file
       9              :  * @brief Backend APIs for the fuel gauge emulators.
      10              :  */
      11              : 
      12              : #ifndef ZEPHYR_INCLUDE_DRIVERS_EMUL_FUEL_GAUGE_H_
      13              : #define ZEPHYR_INCLUDE_DRIVERS_EMUL_FUEL_GAUGE_H_
      14              : 
      15              : #include <stdint.h>
      16              : #include <zephyr/drivers/emul.h>
      17              : #include <zephyr/drivers/fuel_gauge.h>
      18              : 
      19              : #ifdef __cplusplus
      20              : extern "C" {
      21              : #endif
      22              : 
      23              : /**
      24              :  * @brief Fuel gauge backend emulator APIs
      25              :  * @defgroup fuel_gauge_emulator_backend Fuel gauge backend emulator APIs
      26              :  * @ingroup io_emulators
      27              :  * @ingroup fuel_gauge_interface
      28              :  * @{
      29              :  */
      30              : 
      31              : /**
      32              :  * @cond INTERNAL_HIDDEN
      33              :  *
      34              :  * These are for internal use only, so skip these in public documentation.
      35              :  */
      36              : __subsystem struct fuel_gauge_emul_driver_api {
      37              :         int (*set_battery_charging)(const struct emul *emul, uint32_t uV, int uA);
      38              :         int (*is_battery_cutoff)(const struct emul *emul, bool *cutoff);
      39              : };
      40              : /**
      41              :  * @endcond
      42              :  */
      43              : 
      44              : /**
      45              :  * @brief Set charging for fuel gauge associated battery.
      46              :  *
      47              :  * Set how much the battery associated with a fuel gauge IC is charging or discharging. Where
      48              :  * voltage is always positive and a positive or negative current denotes charging or discharging,
      49              :  * respectively.
      50              :  *
      51              :  * @param target Pointer to the emulator structure for the fuel gauge emulator instance.
      52              :  * @param uV Microvolts describing the battery voltage.
      53              :  * @param uA Microamps describing the battery current where negative is discharging.
      54              :  *
      55              :  * @retval 0 If successful.
      56              :  * @retval -EINVAL if mV or mA are 0.
      57              :  */
      58            1 : __syscall int emul_fuel_gauge_set_battery_charging(const struct emul *target, uint32_t uV, int uA);
      59              : static inline int z_impl_emul_fuel_gauge_set_battery_charging(const struct emul *target,
      60              :                                                               uint32_t uV, int uA)
      61              : {
      62              :         const struct fuel_gauge_emul_driver_api *backend_api =
      63              :                 (const struct fuel_gauge_emul_driver_api *)target->backend_api;
      64              : 
      65              :         if (backend_api->set_battery_charging == 0) {
      66              :                 return -ENOTSUP;
      67              :         }
      68              : 
      69              :         return backend_api->set_battery_charging(target, uV, uA);
      70              : }
      71              : 
      72              : /**
      73              :  * @brief Check if the battery has been cut off.
      74              :  *
      75              :  * @param target Pointer to the emulator structure for the fuel gauge emulator instance.
      76              :  * @param cutoff Pointer to bool storing variable.
      77              :  *
      78              :  * @retval 0 If successful.
      79              :  * @retval -ENOTSUP if not supported by emulator.
      80              :  */
      81            1 : __syscall int emul_fuel_gauge_is_battery_cutoff(const struct emul *target, bool *cutoff);
      82              : static inline int z_impl_emul_fuel_gauge_is_battery_cutoff(const struct emul *target, bool *cutoff)
      83              : {
      84              :         const struct fuel_gauge_emul_driver_api *backend_api =
      85              :                 (const struct fuel_gauge_emul_driver_api *)target->backend_api;
      86              : 
      87              :         if (backend_api->is_battery_cutoff == 0) {
      88              :                 return -ENOTSUP;
      89              :         }
      90              :         return backend_api->is_battery_cutoff(target, cutoff);
      91              : }
      92              : 
      93              : #ifdef __cplusplus
      94              : }
      95              : #endif
      96              : 
      97              : #include <zephyr/syscalls/emul_fuel_gauge.h>
      98              : 
      99              : /**
     100              :  * @}
     101              :  */
     102              : 
     103              : #endif /* ZEPHYR_INCLUDE_DRIVERS_EMUL_FUEL_GAUGE_H_*/
        

Generated by: LCOV version 2.0-1