• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef _DUET_TIMER_H_
17 #define _DUET_TIMER_H_
18 #include <stdint.h>
19 
20 #define DUET_TIMER1_INDEX 0
21 #define DUET_TIMER2_INDEX 1
22 #define DUET_TIMER_NUM 2
23 
24 #define TIMER_RELOAD_AUTO  1  /* timer reload automatic */
25 #define TIMER_RELOAD_MANU  2  /* timer reload manual */
26 
27 typedef void (*duet_timer_cb_handler_t)(void *arg);
28 typedef struct {
29     duet_timer_cb_handler_t cb;
30     void *arg;
31 } duet_timer_cb_t;
32 
33 typedef struct {
34     uint32_t       period;   /* us */
35     uint8_t        reload_mode;
36     duet_timer_cb_handler_t cb;
37     void          *arg;
38 } duet_timer_config_t;
39 
40 typedef struct {
41     int8_t         port;   /* timer port */
42     duet_timer_config_t config; /* timer config */
43     void          *priv;   /* priv data */
44 } duet_timer_dev_t;
45 
46 /**
47  * init a hardware timer
48  *
49  * @param[in]  tim  timer device
50  *
51  * @return  0 : on success, EIO : if an error occurred with any step
52  */
53 int32_t duet_timer_init(duet_timer_dev_t *tim);
54 
55 /**
56  * start a hardware timer
57  *
58  * @param[in]  tim  timer device
59  *
60  * @return  0 : on success, EIO : if an error occurred with any step
61  */
62 int32_t duet_timer_start(duet_timer_dev_t *tim);
63 
64 /**
65  * get hardware timer remain time
66  *
67  * @return   success return remain time, EIO == failure
68  */
69 int32_t duet_timer_get(duet_timer_dev_t *tim);
70 /**
71  * reload hardware timer value
72  *
73  * @return   0 == success, EIO == failure
74  */
75 int32_t duet_timer_reload(duet_timer_dev_t *tim);
76 
77 /**
78  * stop a hardware timer
79  *
80  * @param[in]  tim  timer device
81  *
82  * @return  none
83  */
84 void duet_timer_stop(duet_timer_dev_t *tim);
85 
86 /**
87  * De-initialises an TIMER interface, Turns off an TIMER hardware interface
88  *
89  * @param[in]  tim  timer device
90  *
91  * @return  0 : on success, EIO : if an error occurred with any step
92  */
93 int32_t duet_timer_finalize(duet_timer_dev_t *tim);
94 
95 #endif // _DUET_TIMER_H_