1  /*
2  * Copyright (C) 2017-2024 Alibaba Group Holding Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /******************************************************************************
20  * @file       drv/wdt.h
21  * @brief      Header File for WDT Driver
22  * @version    V1.0
23  * @date       9. Oct 2020
24  * @model      wdt
25  ******************************************************************************/
26 
27 #ifndef _DRV_WDT_H_
28 #define _DRV_WDT_H_
29 
30 #include <drv/common.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct csi_wdt csi_wdt_t;
37 
38 struct csi_wdt {
39     csi_dev_t       dev;
40     void (*callback)(csi_wdt_t *wdt,  void *arg);
41     void            *arg;
42     void            *priv;
43 };
44 
45 /**
46   \brief       Initialize WDT interface. Initializes the resources needed for the WDT interface
47   \param[in]   wdt    Handle to operate
48   \param[in]   idx    WDT index
49   \return      Error code \ref csi_error_t
50 */
51 csi_error_t csi_wdt_init(csi_wdt_t *wdt, uint32_t idx);
52 
53 /**
54   \brief       De-initialize WDT interface. Stops operation and releases the software resources used by the interface
55   \param[in]   wdt    Handle to operate
56   \return      None
57 */
58 void csi_wdt_uninit(csi_wdt_t *wdt);
59 
60 /**
61   \brief       Set the WDT value
62   \param[in]   wdt    Handle to operate
63   \param[in]   ms     The timeout value(ms)
64   \return      Error code \ref csi_error_t
65 */
66 csi_error_t csi_wdt_set_timeout(csi_wdt_t *wdt, uint32_t ms);
67 
68 /**
69   \brief       Start the WDT
70   \param[in]   wdt    Handle to operate
71   \return      Error code \ref csi_error_t
72 */
73 csi_error_t csi_wdt_start(csi_wdt_t *wdt);
74 
75 /**
76   \brief       Stop the WDT
77   \param[in]   wdt    Handle to operate
78   \return      None
79 */
80 void csi_wdt_stop(csi_wdt_t *wdt);
81 
82 /**
83   \brief       Feed the WDT
84   \param[in]   wdt    Handle to operate
85   \return      Error code \ref csi_error_t
86 */
87 csi_error_t csi_wdt_feed(csi_wdt_t *wdt);
88 
89 /**
90   \brief       Get the remaining time to timeout
91   \param[in]   wdt    Handle to operate
92   \return      The remaining time of WDT(ms)
93 */
94 uint32_t csi_wdt_get_remaining_time(csi_wdt_t *wdt);
95 
96 /**
97   \brief       Check WDT is running
98   \param[in]   wdt    Handle to operate
99   \return
100                true  - WDT is running
101                false - WDT is stopped
102 */
103 bool csi_wdt_is_running(csi_wdt_t *wdt);
104 
105 /**
106   \brief       Attach the callback handler to WDT
107   \param[in]   wdt         Handle to operate
108   \param[in]   callback    Callback function
109   \param[in]   arg         Callback's param
110   \return      Error code \ref csi_error_t
111 */
112 csi_error_t csi_wdt_attach_callback(csi_wdt_t *wdt, void *callback, void *arg);
113 
114 /**
115   \brief       Detach the callback handler
116   \param[in]   wdt    Handle to operate
117   \return      None
118 */
119 void csi_wdt_detach_callback(csi_wdt_t *wdt);
120 
121 /**
122   \brief       Enable WDT power manage
123   \param[in]   wdt    Handle to operate
124   \return      Error code \ref csi_error_t
125 */
126 csi_error_t csi_wdt_enable_pm(csi_wdt_t *wdt);
127 
128 /**
129   \brief       Disable WDT power manage
130   \param[in]   wdt    Handle to operate
131   \return      None
132 */
133 void csi_wdt_disable_pm(csi_wdt_t *wdt);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif /* _DRV_WDT_H_ */
140