1 /*
2  * Copyright (C) 2017-2019 Alibaba Group Holding Limited
3  */
4 
5 /******************************************************************************
6  * @file     drv_timer.h
7  * @brief    header file for timer driver
8  * @version  V1.0
9  * @date     02. June 2017
10  * @model    timer
11  ******************************************************************************/
12 
13 #ifndef _CSI_TIMER_H_
14 #define _CSI_TIMER_H_
15 
16 
17 #include <stdint.h>
18 #include <drv_common.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 /// definition for timer handle.
24 typedef void *timer_handle_t;
25 
26 /*----- TIMER Control Codes: Mode -----*/
27 typedef enum {
28     TIMER_MODE_FREE_RUNNING                 = 0,   ///< free running mode
29     TIMER_MODE_RELOAD                              ///< reload mode
30 } timer_mode_e;
31 
32 /**
33 \brief TIMER Status
34 */
35 typedef struct {
36     uint32_t active   : 1;                        ///< timer active flag
37     uint32_t timeout  : 1;                        ///< timeout flag
38 } timer_status_t;
39 
40 /**
41 \brief TIMER Event
42 */
43 typedef enum {
44     TIMER_EVENT_TIMEOUT  = 0   ///< time out event
45 } timer_event_e;
46 
47 typedef void (*timer_event_cb_t)(int32_t idx, timer_event_e event);   ///< Pointer to \ref timer_event_cb_t : TIMER Event call back.
48 
49 /**
50   \brief       Initialize TIMER Interface. 1. Initializes the resources needed for the TIMER interface 2.registers event callback function
51   \param[in]   idx  timer index
52   \param[in]   cb_event  event call back function \ref timer_event_cb_t
53   \param[in]   cb_arg    arguments of cb_event
54   \return      pointer to timer instance
55 */
56 timer_handle_t csi_timer_initialize(int32_t idx, timer_event_cb_t cb_event);
57 
58 /**
59   \brief       De-initialize TIMER Interface. stops operation and releases the software resources used by the interface
60   \param[in]   handle timer handle to operate.
61   \return      error code
62 */
63 int32_t csi_timer_uninitialize(timer_handle_t handle);
64 
65 /**
66   \brief       control timer power.
67   \param[in]   handle  timer handle to operate.
68   \param[in]   state   power state.\ref csi_power_stat_e.
69   \return      error code
70 */
71 int32_t csi_timer_power_control(timer_handle_t handle, csi_power_stat_e state);
72 
73 /**
74   \brief       config timer mode.
75   \param[in]   handle timer handle to operate.
76   \param[in]   mode      \ref timer_mode_e
77   \return      error code
78 */
79 int32_t csi_timer_config(timer_handle_t handle, timer_mode_e mode);
80 
81 /**
82   \brief       Set timeout just for the reload mode.
83   \param[in]   handle timer handle to operate.
84   \param[in]   timeout the timeout value in microseconds(us).
85   \return      error code
86 */
87 int32_t csi_timer_set_timeout(timer_handle_t handle, uint32_t timeout);
88 
89 /**
90   \brief       Start timer.
91   \param[in]   handle timer handle to operate.
92   \return      error code
93 */
94 int32_t csi_timer_start(timer_handle_t handle);
95 
96 /**
97   \brief       Stop timer.
98   \param[in]   handle timer handle to operate.
99   \return      error code
100 */
101 int32_t csi_timer_stop(timer_handle_t handle);
102 
103 /**
104   \brief       suspend timer.
105   \param[in]   handle timer handle to operate.
106   \return      error code
107 */
108 int32_t csi_timer_suspend(timer_handle_t handle);
109 
110 /**
111   \brief       resume timer.
112   \param[in]   handle timer handle to operate.
113   \return      error code
114 */
115 int32_t csi_timer_resume(timer_handle_t handle);
116 
117 /**
118   \brief       get timer current value
119   \param[in]   handle timer handle to operate.
120   \param[out]   value     timer current value
121   \return      error code
122 */
123 int32_t csi_timer_get_current_value(timer_handle_t handle, uint32_t *value);
124 
125 /**
126   \brief       Get TIMER status.
127   \param[in]   handle timer handle to operate.
128   \return      TIMER status \ref timer_status_t
129 */
130 timer_status_t csi_timer_get_status(timer_handle_t handle);
131 
132 /**
133   \brief       get timer reload value
134   \param[in]   handle timer handle to operate.
135   \param[out]   value    timer reload value
136   \return      error code
137 */
138 int32_t csi_timer_get_load_value(timer_handle_t handle, uint32_t *value);
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif /* _CSI_TIMER_H_ */
145 
146