1 /**
2  * @file timer.h
3  * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited
4  */
5 
6 #ifndef HAL_TIMER_H
7 #define HAL_TIMER_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /** @addtogroup hal_timer TIMER
14  *  timer hal API.
15  *
16  *  @{
17  */
18 
19 #include <stdint.h>
20 
21 #define TIMER_RELOAD_AUTO  1 /**< timer reload automatic */
22 #define TIMER_RELOAD_MANU  2 /**< timer reload manual */
23 
24 /* Define timer handle function type */
25 typedef void (*hal_timer_cb_t)(void *arg);
26 
27 /* Define timer config args */
28 typedef struct {
29     uint32_t        period;         /**< timer period, us */
30     uint8_t         reload_mode;    /**< auto reload or not */
31     hal_timer_cb_t  cb;             /**< timer handle when expired */
32     void           *arg;            /**< timer handle args */
33 } timer_config_t;
34 
35 /* Define timer dev handle */
36 typedef struct {
37     int8_t          port;   /**< timer port */
38     timer_config_t  config; /**< timer config */
39     void           *priv;   /**< priv data */
40 } timer_dev_t;
41 
42 /**
43  * init a hardware timer
44  *
45  * @param[in]  tim  timer device
46  *
47  * @return  0 : on success,  otherwise is error
48  */
49 int32_t hal_timer_init(timer_dev_t *tim);
50 
51 /**
52  * start a hardware timer
53  *
54  * @param[in]  tim  timer device
55  *
56  * @return  0 : on success,  otherwise is error
57  */
58 int32_t hal_timer_start(timer_dev_t *tim);
59 
60 /**
61  * stop a hardware timer
62  *
63  * @param[in]  tim  timer device
64  *
65  * @return  none
66  */
67 void hal_timer_stop(timer_dev_t *tim);
68 
69 /**
70  * change the config of a hardware timer
71  *
72  * @param[in]  tim   timer device
73  * @param[in]  para  timer config
74  *
75  * @return  0 : on success,  otherwise is error
76  */
77 int32_t hal_timer_para_chg(timer_dev_t *tim, timer_config_t para);
78 
79 /**
80  * De-initialises an TIMER interface, Turns off an TIMER hardware interface
81  *
82  * @param[in]  tim  timer device
83  *
84  * @return  0 : on success,  otherwise is error
85  */
86 int32_t hal_timer_finalize(timer_dev_t *tim);
87 
88 /** @} */
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif /* HAL_TIMER_H */
95 
96