• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)(int32_t idx, timer_event_e event);   ///< Pointer to \ref timer_event_cb_t : TIMER Event call back.
58 
59 /**
60   \brief       Initialize TIMER Interface. 1. Initializes the resources needed for the TIMER interface 2.registers event callback function
61   \param[in]   idx  timer index
62   \param[in]   cb_event  event call back function \ref timer_event_cb_t
63   \param[in]   cb_arg    arguments of cb_event
64   \return      pointer to timer instance
65 */
66 timer_handle_t csi_timer_initialize(int32_t idx, timer_event_cb_t cb_event);
67 
68 /**
69   \brief       De-initialize TIMER Interface. stops operation and releases the software resources used by the interface
70   \param[in]   handle timer handle to operate.
71   \return      error code
72 */
73 int32_t csi_timer_uninitialize(timer_handle_t handle);
74 
75 /**
76   \brief       control timer power.
77   \param[in]   handle  timer handle to operate.
78   \param[in]   state   power state.\ref csi_power_stat_e.
79   \return      error code
80 */
81 int32_t csi_timer_power_control(timer_handle_t handle, csi_power_stat_e state);
82 
83 /**
84   \brief       config timer mode.
85   \param[in]   handle timer handle to operate.
86   \param[in]   mode      \ref timer_mode_e
87   \return      error code
88 */
89 int32_t csi_timer_config(timer_handle_t handle, timer_mode_e mode);
90 
91 /**
92   \brief       Set timeout just for the reload mode.
93   \param[in]   handle timer handle to operate.
94   \param[in]   timeout the timeout value in microseconds(us).
95   \return      error code
96 */
97 int32_t csi_timer_set_timeout(timer_handle_t handle, uint32_t timeout);
98 
99 /**
100   \brief       Start timer.
101   \param[in]   handle timer handle to operate.
102   \return      error code
103 */
104 int32_t csi_timer_start(timer_handle_t handle);
105 
106 /**
107   \brief       Stop timer.
108   \param[in]   handle timer handle to operate.
109   \return      error code
110 */
111 int32_t csi_timer_stop(timer_handle_t handle);
112 
113 /**
114   \brief       suspend timer.
115   \param[in]   handle timer handle to operate.
116   \return      error code
117 */
118 int32_t csi_timer_suspend(timer_handle_t handle);
119 
120 /**
121   \brief       resume timer.
122   \param[in]   handle timer handle to operate.
123   \return      error code
124 */
125 int32_t csi_timer_resume(timer_handle_t handle);
126 
127 /**
128   \brief       get timer current value
129   \param[in]   handle timer handle to operate.
130   \param[out]   value     timer current value
131   \return      error code
132 */
133 int32_t csi_timer_get_current_value(timer_handle_t handle, uint32_t *value);
134 
135 /**
136   \brief       Get TIMER status.
137   \param[in]   handle timer handle to operate.
138   \return      TIMER status \ref timer_status_t
139 */
140 timer_status_t csi_timer_get_status(timer_handle_t handle);
141 
142 /**
143   \brief       get timer reload value
144   \param[in]   handle timer handle to operate.
145   \param[out]   value    timer reload value
146   \return      error code
147 */
148 int32_t csi_timer_get_load_value(timer_handle_t handle, uint32_t *value);
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif /* _CSI_TIMER_H_ */
155