1 /* 2 * Copyright (c) 2022 The Chromium OS Authors 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_SUBSYS_USBC_TIMER_H_ 8 #define ZEPHYR_SUBSYS_USBC_TIMER_H_ 9 10 #include <zephyr/kernel.h> 11 12 /** 13 * @brief USB-C Timer Object 14 */ 15 struct usbc_timer_t { 16 /** kernel timer */ 17 struct k_timer timer; 18 /** timeout value in ms */ 19 uint32_t timeout_ms; 20 /** flags to track timer status */ 21 atomic_t flags; 22 }; 23 24 /** 25 * @brief Initialize a timer 26 * 27 * @param usbc_timer timer object 28 * @param timeout_ms timer timeout in ms 29 */ 30 void usbc_timer_init(struct usbc_timer_t *usbc_timer, uint32_t timeout_ms); 31 32 /** 33 * @brief Start a timer 34 * 35 * @param usbc_timer timer object 36 */ 37 void usbc_timer_start(struct usbc_timer_t *usbc_timer); 38 39 /** 40 * @brief Check if a timer has expired 41 * 42 * @param usbc_timer timer object 43 * @retval true if the timer has expired 44 */ 45 bool usbc_timer_expired(struct usbc_timer_t *usbc_timer); 46 47 /** 48 * @brief Check if a timer has been started 49 * 50 * @param usbc_timer timer object 51 * @retval true if the timer is running 52 */ 53 bool usbc_timer_running(struct usbc_timer_t *usbc_timer); 54 55 /** 56 * @brief Stop a timer 57 * 58 * @param usbc_timer timer object 59 */ 60 void usbc_timer_stop(struct usbc_timer_t *usbc_timer); 61 62 #endif /* ZEPHYR_SUBSYS_USBC_TIMER_H_ */ 63