1 /* 2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @file wm_timer.h 18 * 19 * @brief Timer Driver Module 20 * 21 * @author dave 22 * 23 * Copyright (c) 2014 Winner Microelectronics Co., Ltd. 24 */ 25 #ifndef WM_TIMER_H 26 #define WM_TIMER_H 27 28 #include "wm_type_def.h" 29 /** invalid timer id */ 30 #define WM_TIMER_ID_INVALID 0xFF 31 32 /** timer interrupt callback */ 33 typedef void (*tls_timer_irq_callback)(void *arg); 34 35 /** timer unit */ 36 enum tls_timer_unit { 37 TLS_TIMER_UNIT_US = 0, /**< microsecond level(us) */ 38 TLS_TIMER_UNIT_MS /**< millisecond level(ms) */ 39 }; 40 41 /** timer configuration */ 42 struct tls_timer_cfg { 43 enum tls_timer_unit unit; /**< timer accuracy */ 44 u32 timeout; /**< timeout period */ 45 bool is_repeat; /**< cycle timer */ 46 tls_timer_irq_callback callback; /**< timeout callback function */ 47 void *arg; /**< parameter fot the timeout callback function */ 48 }; 49 50 /** 51 * @defgroup Driver_APIs Driver APIs 52 * @brief Driver APIs 53 */ 54 55 /** 56 * @addtogroup Driver_APIs 57 * @{ 58 */ 59 60 /** 61 * @defgroup TIMER_Driver_APIs TIMER Driver APIs 62 * @brief TIMER driver APIs 63 */ 64 65 /** 66 * @addtogroup TIMER_Driver_APIs 67 * @{ 68 */ 69 70 /** 71 * @brief This function is used to create a timer 72 * 73 * @param[in] cfg timer configuration 74 * 75 * @retval WM_TIMER_ID_INVALID failed 76 * @retval other timer id 77 * 78 * @note 79 * User does not need to clear the interrupt flag. 80 * Rtc callback function is called in interrupt, 81 * so do not operate the critical data in the callback fuuction. 82 * Sending messages to other tasks to handle is recommended. 83 */ 84 u8 tls_timer_create(struct tls_timer_cfg *cfg); 85 86 /** 87 * @brief This function is used to start a timer 88 * 89 * @param[in] timer_id timer id 90 * 91 * @return None 92 * 93 * @note None 94 */ 95 void tls_timer_start(u8 timer_id); 96 97 /** 98 * @brief This function is used to stop a timer 99 * 100 * @param[in] timer_id timer id 101 * 102 * @return None 103 * 104 * @note None 105 */ 106 void tls_timer_stop(u8 timer_id); 107 108 /** 109 * @brief This function is used to change a timer wait time 110 * 111 * @param[in] timer_id timer id[0~5] 112 * 113 * @param[in] newtime new wait time 114 * 115 * @retval None 116 * 117 * @note If the timer does not start, this function will start the timer 118 */ 119 void tls_timer_change(u8 timer_id, u32 newtime); 120 121 /** 122 * @brief This function is used to read a timer's current value 123 * 124 * @param[in] timer_id timer id[0~5] 125 * 126 * @retval timer's current value 127 * 128 * @note none 129 */ 130 u32 tls_timer_read(u8 timer_id); 131 132 /** 133 * @brief This function is used to delete a timer 134 * 135 * @param[in] timer_id timer id 136 * 137 * @return None 138 * 139 * @note None 140 */ 141 void tls_timer_destroy(u8 timer_id); 142 143 /** 144 * @} 145 */ 146 147 /** 148 * @} 149 */ 150 151 #endif /* WM_TIMER_H */ 152 153