LCOV - code coverage report
Current view: top level - zephyr/drivers/misc/timeaware_gpio - timeaware_gpio.h Coverage Total Hit
Test: new.info Lines: 87.5 % 8 7
Test Date: 2025-09-25 19:22:35

            Line data    Source code
       1            1 : /*
       2              :  * Copyright (c) 2023 Intel Corporation.
       3              :  *
       4              :  * SPDX-License-Identifier: Apache-2.0
       5              :  */
       6              : 
       7              : /**
       8              :  * @file
       9              :  * @brief Public APIs for Time-aware GPIO drivers
      10              :  * @ingroup tgpio_interface
      11              :  */
      12              : #ifndef ZEPHYR_DRIVERS_MISC_TIMEAWARE_GPIO_TIMEAWARE_GPIO
      13              : #define ZEPHYR_DRIVERS_MISC_TIMEAWARE_GPIO_TIMEAWARE_GPIO
      14              : 
      15              : /**
      16              :  * @brief Interfaces for time-aware GPIO controllers.
      17              :  * @defgroup tgpio_interface Time-aware GPIO
      18              :  * @since 3.5
      19              :  * @version 0.1.0
      20              :  * @ingroup io_interfaces
      21              :  * @{
      22              :  */
      23              : 
      24              : #include <zephyr/sys/__assert.h>
      25              : #include <zephyr/sys/slist.h>
      26              : 
      27              : #include <zephyr/types.h>
      28              : #include <stddef.h>
      29              : #include <zephyr/device.h>
      30              : #include <zephyr/internal/syscall_handler.h>
      31              : 
      32              : #ifdef __cplusplus
      33              : extern "C" {
      34              : #endif
      35              : 
      36              : /**
      37              :  * @brief Event polarity
      38              :  */
      39            0 : enum tgpio_pin_polarity {
      40              :         TGPIO_RISING_EDGE = 0,
      41              :         TGPIO_FALLING_EDGE,
      42              :         TGPIO_TOGGLE_EDGE,
      43              : };
      44              : 
      45              : /**
      46              :  * @cond INTERNAL_HIDDEN
      47              :  *
      48              :  * TGPIO driver API definition and system call entry points
      49              :  *
      50              :  * (Internal use only.)
      51              :  */
      52              : 
      53              : __subsystem struct tgpio_driver_api {
      54              :         int (*pin_disable)(const struct device *dev, uint32_t pin);
      55              :         int (*get_time)(const struct device *dev, uint64_t *current_time);
      56              :         int (*cyc_per_sec)(const struct device *dev, uint32_t *cycles);
      57              :         int (*set_perout)(const struct device *dev, uint32_t pin, uint64_t start_time,
      58              :                           uint64_t repeat_interval, bool periodic_enable);
      59              :         int (*config_ext_ts)(const struct device *dev, uint32_t pin, uint32_t event_polarity);
      60              :         int (*read_ts_ec)(const struct device *dev, uint32_t pin, uint64_t *timestamp,
      61              :                           uint64_t *event_count);
      62              : };
      63              : 
      64              : /**
      65              :  * @endcond
      66              :  */
      67              : 
      68              : /**
      69              :  * @brief Get time from ART timer
      70              :  *
      71              :  * @param dev TGPIO device
      72              :  * @param current_time Pointer to store timer value in cycles
      73              :  *
      74              :  * @return 0 if successful
      75              :  * @return negative errno code on failure.
      76              :  */
      77            1 : __syscall int tgpio_port_get_time(const struct device *dev, uint64_t *current_time);
      78              : 
      79              : static inline int z_impl_tgpio_port_get_time(const struct device *dev, uint64_t *current_time)
      80              : {
      81              :         const struct tgpio_driver_api *api = (const struct tgpio_driver_api *)dev->api;
      82              : 
      83              :         return api->get_time(dev, current_time);
      84              : }
      85              : 
      86              : /**
      87              :  * @brief Get current running rate
      88              :  *
      89              :  * @param dev TGPIO device
      90              :  * @param cycles pointer to store current running frequency
      91              :  *
      92              :  * @return 0 if successful, negative errno code on failure.
      93              :  */
      94            1 : __syscall int tgpio_port_get_cycles_per_second(const struct device *dev, uint32_t *cycles);
      95              : 
      96              : static inline int z_impl_tgpio_port_get_cycles_per_second(const struct device *dev,
      97              :                                                            uint32_t *cycles)
      98              : {
      99              :         const struct tgpio_driver_api *api = (const struct tgpio_driver_api *)dev->api;
     100              : 
     101              :         return api->cyc_per_sec(dev, cycles);
     102              : }
     103              : 
     104              : /**
     105              :  * @brief Disable operation on pin
     106              :  *
     107              :  * @param dev TGPIO device
     108              :  * @param pin TGPIO pin
     109              :  *
     110              :  * @return 0 if successful, negative errno code on failure.
     111              :  */
     112            1 : __syscall int tgpio_pin_disable(const struct device *dev, uint32_t pin);
     113              : 
     114              : static inline int z_impl_tgpio_pin_disable(const struct device *dev, uint32_t pin)
     115              : {
     116              :         const struct tgpio_driver_api *api = (const struct tgpio_driver_api *)dev->api;
     117              : 
     118              :         return api->pin_disable(dev, pin);
     119              : }
     120              : 
     121              : /**
     122              :  * @brief Enable/Continue operation on pin
     123              :  *
     124              :  * @param dev TGPIO device
     125              :  * @param pin TGPIO pin
     126              :  * @param event_polarity TGPIO pin event polarity
     127              :  *
     128              :  * @return 0 if successful, negative errno code on failure.
     129              :  */
     130            1 : __syscall int tgpio_pin_config_ext_timestamp(const struct device *dev, uint32_t pin,
     131              :                                               uint32_t event_polarity);
     132              : 
     133              : static inline int z_impl_tgpio_pin_config_ext_timestamp(const struct device *dev, uint32_t pin,
     134              :                                                          uint32_t event_polarity)
     135              : {
     136              :         const struct tgpio_driver_api *api = (const struct tgpio_driver_api *)dev->api;
     137              : 
     138              :         return api->config_ext_ts(dev, pin, event_polarity);
     139              : }
     140              : 
     141              : /**
     142              :  * @brief Enable periodic pulse generation on a pin
     143              :  *
     144              :  * @param dev TGPIO device
     145              :  * @param pin TGPIO pin
     146              :  * @param start_time start_time of first pulse in hw cycles
     147              :  * @param repeat_interval repeat interval between two pulses in hw cycles
     148              :  * @param periodic_enable enables periodic mode if 'true' is passed.
     149              :  *
     150              :  * @return 0 if successful, negative errno code on failure.
     151              :  */
     152            1 : __syscall int tgpio_pin_periodic_output(const struct device *dev, uint32_t pin,
     153              :                                          uint64_t start_time, uint64_t repeat_interval,
     154              :                                          bool periodic_enable);
     155              : 
     156              : static inline int z_impl_tgpio_pin_periodic_output(const struct device *dev, uint32_t pin,
     157              :                                                     uint64_t start_time, uint64_t repeat_interval,
     158              :                                                     bool periodic_enable)
     159              : {
     160              :         const struct tgpio_driver_api *api = (const struct tgpio_driver_api *)dev->api;
     161              : 
     162              :         return api->set_perout(dev, pin, start_time, repeat_interval, periodic_enable);
     163              : }
     164              : 
     165              : /**
     166              :  * @brief Read timestamp and event counter from TGPIO
     167              :  *
     168              :  * @param dev TGPIO device
     169              :  * @param pin TGPIO pin
     170              :  * @param timestamp timestamp of the last pulse received
     171              :  * @param event_count number of pulses received since the pin is enabled
     172              :  *
     173              :  * @return 0 if successful, negative errno code on failure.
     174              :  */
     175            1 : __syscall int tgpio_pin_read_ts_ec(const struct device *dev, uint32_t pin, uint64_t *timestamp,
     176              :                                     uint64_t *event_count);
     177              : 
     178              : static inline int z_impl_tgpio_pin_read_ts_ec(const struct device *dev, uint32_t pin,
     179              :                                                uint64_t *timestamp, uint64_t *event_count)
     180              : {
     181              :         const struct tgpio_driver_api *api = (const struct tgpio_driver_api *)dev->api;
     182              : 
     183              :         return api->read_ts_ec(dev, pin, timestamp, event_count);
     184              : }
     185              : 
     186              : /**
     187              :  * @}
     188              :  */
     189              : 
     190              : #ifdef __cplusplus
     191              : }
     192              : #endif
     193              : 
     194              : #include <zephyr/syscalls/timeaware_gpio.h>
     195              : 
     196              : #endif /* ZEPHYR_DRIVERS_MISC_TIMEAWARE_GPIO_TIMEAWARE_GPIO */
        

Generated by: LCOV version 2.0-1