1 /* 2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 /****************************************************************************** 17 * @file drv_timer.h 18 * @brief header file for timer driver 19 * @version V1.0 20 * @date 02. June 2017 21 ******************************************************************************/ 22 23 #ifndef _CSI_TIMER_H_ 24 #define _CSI_TIMER_H_ 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #include <stdint.h> 31 #include <drv_common.h> 32 33 /// definition for timer handle. 34 typedef void *timer_handle_t; 35 36 /*----- TIMER Control Codes: Mode -----*/ 37 typedef enum { 38 TIMER_MODE_FREE_RUNNING = 0, ///< free running mode 39 TIMER_MODE_RELOAD ///< reload mode 40 } timer_mode_e; 41 42 /** 43 \brief TIMER Status 44 */ 45 typedef struct { 46 uint32_t active : 1; ///< timer active flag 47 uint32_t timeout : 1; ///< timeout flag 48 } timer_status_t; 49 50 /** 51 \brief TIMER Event 52 */ 53 typedef enum { 54 TIMER_EVENT_TIMEOUT = 0 ///< time out event 55 } timer_event_e; 56 57 typedef void (*timer_event_cb_t)(timer_event_e event, void *arg); ///< Pointer to \ref timer_event_cb_t : TIMER Event call back. 58 59 /** 60 \brief TIMER Device Driver Capabilities. 61 */ 62 typedef struct { 63 uint32_t interrupt_mode : 1; ///< supports Interrupt mode 64 } timer_capabilities_t; 65 66 /** 67 \brief get timer instance count. 68 \return timer instance count 69 */ 70 int32_t csi_timer_get_instance_count(void); 71 72 /** 73 \brief Initialize TIMER Interface. 1. Initializes the resources needed for the TIMER interface 2.registers event callback function 74 \param[in] idx instance timer index 75 \param[in] cb_event Pointer to \ref timer_event_cb_t 76 \param[in] cb_arg arguments of cb_event 77 \return pointer to timer instance 78 */ 79 timer_handle_t csi_timer_initialize(int32_t idx, timer_event_cb_t cb_event, void *cb_arg); 80 81 /** 82 \brief De-initialize TIMER Interface. stops operation and releases the software resources used by the interface 83 \param[in] handle timer handle to operate. 84 \return error code 85 */ 86 int32_t csi_timer_uninitialize(timer_handle_t handle); 87 88 /** 89 \brief Get driver capabilities. 90 \param[in] handle timer handle to operate. 91 \return \ref timer_capabilities_t 92 */ 93 timer_capabilities_t csi_timer_get_capabilities(timer_handle_t handle); 94 95 /** 96 \brief config timer mode. 97 \param[in] handle timer handle to operate. 98 \param[in] mode \ref timer_mode_e 99 \return error code 100 */ 101 int32_t csi_timer_config(timer_handle_t handle, timer_mode_e mode); 102 103 /** 104 \brief Set timer. 105 \param[in] handle timer handle to operate. 106 \param[in] timeout the timeout value in microseconds(us). 107 \return error code 108 */ 109 int32_t csi_timer_set_timeout(timer_handle_t handle, uint32_t timeout); 110 111 /** 112 \brief Start timer. 113 \param[in] handle timer handle to operate. 114 \param[in] apbfreq APB frequency 115 \return error code 116 */ 117 int32_t csi_timer_start(timer_handle_t handle, uint32_t apbfreq); 118 119 /** 120 \brief Stop timer. 121 \param[in] handle timer handle to operate. 122 \return error code 123 */ 124 int32_t csi_timer_stop(timer_handle_t handle); 125 126 /** 127 \brief suspend timer. 128 \param[in] handle timer handle to operate. 129 \return error code 130 */ 131 int32_t csi_timer_suspend(timer_handle_t handle); 132 133 /** 134 \brief resume timer. 135 \param[in] handle timer handle to operate. 136 \return error code 137 */ 138 int32_t csi_timer_resume(timer_handle_t handle); 139 140 /** 141 \brief get timer current value 142 \param[in] handle timer handle to operate. 143 \param[in] value timer current value 144 \return error code 145 */ 146 int32_t csi_timer_get_current_value(timer_handle_t handle, uint32_t *value); 147 148 /** 149 \brief Get TIMER status. 150 \param[in] handle timer handle to operate. 151 \return TIMER status \ref timer_status_t 152 */ 153 timer_status_t csi_timer_get_status(timer_handle_t handle); 154 155 #ifdef __cplusplus 156 } 157 #endif 158 159 #endif /* _CSI_TIMER_H_ */ 160 161