LCOV - code coverage report
Current view: top level - drivers/gpio - gpio_utils.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 16 0.0 %
Date: 2022-08-18 11:36:24 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 28 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2016 Intel Corporation.
       3                 :            :  *
       4                 :            :  * SPDX-License-Identifier: Apache-2.0
       5                 :            :  */
       6                 :            : 
       7                 :            : /**
       8                 :            :  * @file Header where utility code can be found for GPIO drivers
       9                 :            :  */
      10                 :            : 
      11                 :            : #ifndef ZEPHYR_DRIVERS_GPIO_GPIO_UTILS_H_
      12                 :            : #define ZEPHYR_DRIVERS_GPIO_GPIO_UTILS_H_
      13                 :            : 
      14                 :            : #define GPIO_PORT_PIN_MASK_FROM_NGPIOS(ngpios)                  \
      15                 :            :         ((gpio_port_pins_t)(((uint64_t)1 << (ngpios)) - 1U))
      16                 :            : 
      17                 :            : #define GPIO_PORT_PIN_MASK_FROM_DT_NODE(node_id)                \
      18                 :            :         GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_PROP(node_id, ngpios))
      19                 :            : 
      20                 :            : #define GPIO_PORT_PIN_MASK_FROM_DT_INST(inst)                   \
      21                 :            :         GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_PROP(inst, ngpios))
      22                 :            : 
      23                 :            : /**
      24                 :            :  * @brief Generic function to insert or remove a callback from a callback list
      25                 :            :  *
      26                 :            :  * @param callbacks A pointer to the original list of callbacks (can be NULL)
      27                 :            :  * @param callback A pointer of the callback to insert or remove from the list
      28                 :            :  * @param set A boolean indicating insertion or removal of the callback
      29                 :            :  *
      30                 :            :  * @return 0 on success, negative errno otherwise.
      31                 :            :  */
      32                 :          0 : static inline int gpio_manage_callback(sys_slist_t *callbacks,
      33                 :            :                                         struct gpio_callback *callback,
      34                 :            :                                         bool set)
      35                 :            : {
      36         [ #  # ]:          0 :         __ASSERT(callback, "No callback!");
      37         [ #  # ]:          0 :         __ASSERT(callback->handler, "No callback handler!");
      38                 :            : 
      39         [ #  # ]:          0 :         if (!sys_slist_is_empty(callbacks)) {
      40         [ #  # ]:          0 :                 if (!sys_slist_find_and_remove(callbacks, &callback->node)) {
      41         [ #  # ]:          0 :                         if (!set) {
      42                 :          0 :                                 return -EINVAL;
      43                 :            :                         }
      44                 :            :                 }
      45                 :            :         }
      46                 :            : 
      47         [ #  # ]:          0 :         if (set) {
      48                 :          0 :                 sys_slist_prepend(callbacks, &callback->node);
      49                 :            :         }
      50                 :            : 
      51                 :          0 :         return 0;
      52                 :            : }
      53                 :            : 
      54                 :            : /**
      55                 :            :  * @brief Generic function to go through and fire callback from a callback list
      56                 :            :  *
      57                 :            :  * @param list A pointer on the gpio callback list
      58                 :            :  * @param port A pointer on the gpio driver instance
      59                 :            :  * @param pins The actual pin mask that triggered the interrupt
      60                 :            :  */
      61                 :          0 : static inline void gpio_fire_callbacks(sys_slist_t *list,
      62                 :            :                                         const struct device *port,
      63                 :            :                                         uint32_t pins)
      64                 :            : {
      65                 :            :         struct gpio_callback *cb, *tmp;
      66                 :            : 
      67   [ #  #  #  #  :          0 :         SYS_SLIST_FOR_EACH_CONTAINER_SAFE(list, cb, tmp, node) {
          #  #  #  #  #  
                #  #  # ]
      68         [ #  # ]:          0 :                 if (cb->pin_mask & pins) {
      69         [ #  # ]:          0 :                         __ASSERT(cb->handler, "No callback handler!");
      70                 :          0 :                         cb->handler(port, cb, cb->pin_mask & pins);
      71                 :            :                 }
      72                 :            :         }
      73                 :          0 : }
      74                 :            : 
      75                 :            : #endif /* ZEPHYR_DRIVERS_GPIO_GPIO_UTILS_H_ */

Generated by: LCOV version 1.14