1 /*
2  * Copyright (C) 2017-2020 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       9. Oct 2020
10  * @model      timer
11  ******************************************************************************/
12 
13 #ifndef _DRV_TIMER_H_
14 #define _DRV_TIMER_H_
15 
16 #include <drv/common.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 typedef struct csi_timer csi_timer_t;
23 
24 struct csi_timer {
25     csi_dev_t        dev;
26     void (*callback)(csi_timer_t *timer, void *arg);
27     void            *arg;
28     void            *priv;
29 };
30 
31 /**
32   \brief       Initialize TIMER interface. initializes the resources needed for the TIMER interface
33   \param[in]   timer    Handle to operate
34   \param[in]   idx      TIMER index
35   \return      Error code \ref csi_error_t
36 */
37 csi_error_t csi_timer_init(csi_timer_t *timer, uint32_t idx);
38 
39 /**
40   \brief       De-initialize TIMER interface. stops operation and releases the software resources used by the interface
41   \param[in]   timer    Handle to operate
42   \return      None
43 */
44 void csi_timer_uninit(csi_timer_t *timer);
45 
46 /**
47   \brief       Start TIMER
48   \param[in]   timer         Handle to operate
49   \param[in]   timeout_us    The timeout for TIMER
50   \return      Error code \ref csi_error_t
51 */
52 csi_error_t csi_timer_start(csi_timer_t *timer, uint32_t timeout_us);
53 
54 /**
55   \brief       Stop TIMER
56   \param[in]   timer    Handle to operate
57   \return      None
58 */
59 void csi_timer_stop(csi_timer_t *timer);
60 
61 /**
62   \brief       Get TIMER remaining value
63   \param[in]   timer    Handle to operate
64   \return      remaining value
65 */
66 uint32_t csi_timer_get_remaining_value(csi_timer_t *timer);
67 
68 /**
69   \brief       Get TIMER load value
70   \param[in]   timer    Handle to operate
71   \return      Load value
72 */
73 uint32_t csi_timer_get_load_value(csi_timer_t *timer);
74 
75 /**
76   \brief       Check TIMER is running
77   \param[in]   timer    Handle to operate
78   \return
79                true  - TIMER is running
80                false - TIMER is stopped
81 */
82 bool csi_timer_is_running(csi_timer_t *timer);
83 
84 /**
85   \brief       Attach the callback handler to TIMER
86   \param[in]   timer       Operate handle
87   \param[in]   callback    Callback function
88   \param[in]   arg         Callback's param
89   \return      Error code \ref csi_error_t
90 */
91 csi_error_t csi_timer_attach_callback(csi_timer_t *timer, void *callback, void *arg);
92 
93 /**
94   \brief       Detach the callback handler
95   \param[in]   timer    Operate handle
96   \return      None
97 */
98 void csi_timer_detach_callback(csi_timer_t *timer);
99 
100 /**
101   \brief       Enable TIMER power manage
102   \param[in]   timer    Handle to operate
103   \return      Error code \ref csi_error_t
104 */
105 csi_error_t csi_timer_enable_pm(csi_timer_t *timer);
106 
107 /**
108   \brief       Disable TIMER power manage
109   \param[in]   timer    Handle to operate
110   \return      None
111 */
112 void csi_timer_disable_pm(csi_timer_t *timer);
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* _DRV_TIMER_H_ */
119