LCOV - code coverage report
Current view: top level - zephyr/drivers - emul_bbram.h Coverage Total Hit
Test: new.info Lines: 66.7 % 3 2
Test Date: 2025-09-05 16:43:28

            Line data    Source code
       1            0 : /*
       2              :  * Copyright 2024 Google LLC
       3              :  * SPDX-License-Identifier: Apache-2.0
       4              :  */
       5              : 
       6              : #ifndef INCLUDE_ZEPHYR_DRIVERS_EMUL_BBRAM_H_
       7              : #define INCLUDE_ZEPHYR_DRIVERS_EMUL_BBRAM_H_
       8              : 
       9              : #include <zephyr/drivers/emul.h>
      10              : 
      11              : #include <stdint.h>
      12              : 
      13              : /**
      14              :  * @brief BBRAM emulator backend API
      15              :  * @defgroup bbram_emulator_backend BBRAM emulator backend API
      16              :  * @ingroup io_emulators
      17              :  * @ingroup bbram_interface
      18              :  * @{
      19              :  */
      20              : 
      21              : /**
      22              :  * @cond INTERNAL_HIDDEN
      23              :  *
      24              :  * These are for internal use only, so skip these in public documentation.
      25              :  */
      26              : 
      27              : __subsystem struct emul_bbram_driver_api {
      28              :         /** Sets the data */
      29              :         int (*set_data)(const struct emul *target, size_t offset, size_t count,
      30              :                         const uint8_t *data);
      31              :         /** Checks the data */
      32              :         int (*get_data)(const struct emul *target, size_t offset, size_t count, uint8_t *data);
      33              : };
      34              : 
      35              : /**
      36              :  * @endcond
      37              :  */
      38              : 
      39              : /**
      40              :  * @brief Set the expected data in the bbram region
      41              :  *
      42              :  * @param target Pointer to the emulator instance to operate on
      43              :  * @param offset Offset within the memory to set
      44              :  * @param count Number of bytes to write
      45              :  * @param data The data to write
      46              :  * @return 0 if successful
      47              :  * @return -ENOTSUP if no backend API or if the set_data function isn't implemented
      48              :  * @return -ERANGE if the destination address is out of range.
      49              :  */
      50            1 : static inline int emul_bbram_backend_set_data(const struct emul *target, size_t offset,
      51              :                                               size_t count, const uint8_t *data)
      52              : {
      53              :         if (target == NULL || target->backend_api == NULL) {
      54              :                 return -ENOTSUP;
      55              :         }
      56              : 
      57              :         struct emul_bbram_driver_api *api = (struct emul_bbram_driver_api *)target->backend_api;
      58              : 
      59              :         if (api->set_data == NULL) {
      60              :                 return -ENOTSUP;
      61              :         }
      62              : 
      63              :         return api->set_data(target, offset, count, data);
      64              : }
      65              : 
      66              : /**
      67              :  * @brief Get the expected data in the bbram region
      68              :  *
      69              :  * @param target Pointer to the emulator instance to operate on
      70              :  * @param offset Offset within the memory to get
      71              :  * @param count Number of bytes to read
      72              :  * @param data The data buffer to hold the result
      73              :  * @return 0 if successful
      74              :  * @return -ENOTSUP if no backend API or if the get_data function isn't implemented
      75              :  * @return -ERANGE if the address is out of range.
      76              :  */
      77            1 : static inline int emul_bbram_backend_get_data(const struct emul *target, size_t offset,
      78              :                                               size_t count, uint8_t *data)
      79              : {
      80              :         if (target == NULL || target->backend_api == NULL) {
      81              :                 return -ENOTSUP;
      82              :         }
      83              : 
      84              :         struct emul_bbram_driver_api *api = (struct emul_bbram_driver_api *)target->backend_api;
      85              : 
      86              :         if (api->get_data == NULL) {
      87              :                 return -ENOTSUP;
      88              :         }
      89              : 
      90              :         return api->get_data(target, offset, count, data);
      91              : }
      92              : 
      93              : /**
      94              :  * @}
      95              :  */
      96              : 
      97              : #endif /* INCLUDE_ZEPHYR_DRIVERS_EMUL_BBRAM_H_ */
        

Generated by: LCOV version 2.0-1