2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 /******************************************************************************
18 * @brief header file for timer driver
21 ******************************************************************************/
31 #include <drv_common.h>
33 /// definition for timer handle.
34 typedef void *timer_handle_t;
36 /*----- TIMER Control Codes: Mode -----*/
38 TIMER_MODE_FREE_RUNNING = 0, ///< free running mode
39 TIMER_MODE_RELOAD ///< reload mode
46 uint32_t active : 1; ///< timer active flag
47 uint32_t timeout : 1; ///< timeout flag
54 TIMER_EVENT_TIMEOUT = 0 ///< time out event
57 typedef void (*timer_event_cb_t)(timer_event_e event, void *arg); ///< Pointer to \ref timer_event_cb_t : TIMER Event call back.
60 \brief TIMER Device Driver Capabilities.
63 uint32_t interrupt_mode : 1; ///< supports Interrupt mode
64 } timer_capabilities_t;
67 \brief get timer instance count.
68 \return timer instance count
70 int32_t csi_timer_get_instance_count(void);
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
79 timer_handle_t csi_timer_initialize(int32_t idx, timer_event_cb_t cb_event, void *cb_arg);
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.
86 int32_t csi_timer_uninitialize(timer_handle_t handle);
89 \brief Get driver capabilities.
90 \param[in] handle timer handle to operate.
91 \return \ref timer_capabilities_t
93 timer_capabilities_t csi_timer_get_capabilities(timer_handle_t handle);
96 \brief config timer mode.
97 \param[in] handle timer handle to operate.
98 \param[in] mode \ref timer_mode_e
101 int32_t csi_timer_config(timer_handle_t handle, timer_mode_e mode);
105 \param[in] handle timer handle to operate.
106 \param[in] timeout the timeout value in microseconds(us).
109 int32_t csi_timer_set_timeout(timer_handle_t handle, uint32_t timeout);
113 \param[in] handle timer handle to operate.
114 \param[in] apbfreq APB frequency
117 int32_t csi_timer_start(timer_handle_t handle, uint32_t apbfreq);
121 \param[in] handle timer handle to operate.
124 int32_t csi_timer_stop(timer_handle_t handle);
127 \brief suspend timer.
128 \param[in] handle timer handle to operate.
131 int32_t csi_timer_suspend(timer_handle_t handle);
135 \param[in] handle timer handle to operate.
138 int32_t csi_timer_resume(timer_handle_t handle);
141 \brief get timer current value
142 \param[in] handle timer handle to operate.
143 \param[in] value timer current value
146 int32_t csi_timer_get_current_value(timer_handle_t handle, uint32_t *value);
149 \brief Get TIMER status.
150 \param[in] handle timer handle to operate.
151 \return TIMER status \ref timer_status_t
153 timer_status_t csi_timer_get_status(timer_handle_t handle);
156 \brief get timer reload value
157 \param[in] handle timer handle to operate.
158 \param[in] value timer reload value
161 int32_t csi_timer_get_load_value(timer_handle_t handle, uint32_t *value);
167 #endif /* _CSI_TIMER_H_ */