Debian Codegraph @

src/driver/timer/timer.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /**
3 ******************************************************************************
4 * @file timer.h
5 * @author StarFive Technology
6 * @version V1.0
7 * @date 07/24/2020
8 * @brief
9 ******************************************************************************
10 * @copy
11 *
12 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STARFIVE SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 *
19 * COPYRIGHT 2020 Shanghai StarFive Technology Co., Ltd.
20 */
21
22 #ifndef __TIMER_H__
23 #define __TIMER_H__
24
25 #include <comdef.h>
26
27 #if 0
28 #define RUN_MODE_CONTINOUS 0
29 #define RUN_MODE_SINGLE 1
30
31 #define SOC_SYS_TIMER 0 /* system timer0 */
32
33 #define CONFIG_SYS_HZ_CLOCK TIMER_CLK_HZ
34
35 struct timer_driver {
36 void *base;
37 unsigned long freq;
38 int irq;
39 };
40
41 struct timer_init_s{
42 u32 int_en;
43 u32 run_mode;
44 u32 size;
45 u32 one_shot;
46 u32 count; /* TODO: time value */
47 void (*callback)(void*);
48 void *arg;
49 u32 wdog_reset_en;
50 };
51
52 /*
53 * public function definition
54 */
55 /*---------------------------------------------------
56 *
57 * timer_clr_int_status:
58 * This function clear int_status register.
59 *
60 * timer_clr_int_status() interface:
61 * id:0/1/2 indicate clear timer0/timer1/timer2
62 int_status register.
63 *
64 * Returns: 0 on success, not 0 on failure
65 */
66 int timer_clr_int_status(u32 id);
67
68 /*---------------------------------------------------
69 *
70 * timer_set:
71 * This function set registers defined by timer_init_s
72 struct.
73 *
74 * timer_set() interface:
75 * id:0/1/2 indicate clear timer0/timer1/timer2
76 int_status register.
77 init:timer_init_s struct ptr.
78 *
79 * Returns: 0 on success, not 0 on failure
80 */
81 int timer_set(u32 id,struct timer_init_s *init);
82
83
84
85 /*---------------------------------------------------
86 *
87 */
88 void timer_reload(u32 id);
89
90 /*---------------------------------------------------
91 *
92 * timer_stop:
93 * This function disable and clear interrupt regs of the timer.
94 *
95 * timer_stop() interface:
96 * id:0/1/2 indicate clear timer0/timer1/timer2
97 int_status register.
98 *
99 * Returns: 0 on success, not 0 on failure
100 */
101 int timer_stop(u32 id);
102 /*---------------------------------------------------
103 *
104 * timer_start:
105 * This function enable the timer.
106 *
107 * timer_start() interface:
108 * id:0/1/2 indicate clear timer0/timer1/timer2
109 int_status register.
110 *
111 * Returns: 0 on success, not 0 on failure
112 */
113 int timer_start(u32 id);
114 /*---------------------------------------------------
115 * timer_init:
116 * This function initialize module hardware and some software structures.
117 * You must call this function before other operation
118 *
119 * Returns: 0 on success, not 0 on failure
120 */
121 int timer_init(int id);
122
123 /*---------------------------------------------------
124 * module_exit:
125 * This function free memory.
126 *
127 * Returns: 0 on success, not 0 on failure
128 */
129 int timer_exit(void);
130 #endif
131
132 /*---------------------------------------------------
133 *
134 * udelay:
135 * This function used for delay usec microsecond.
136 *
137 * udelay() interface:
138 * usec:0~357913941(MAX) int number.
139 *
140 * Returns: 0 on success, not 0 on failure
141 */
142 int udelay(u32 usec);
143
144 void mdelay(unsigned int ms);
145
146 void sdelay(unsigned int s);
147
148 u32 get_timer(unsigned int base);
149
150 /*---------------------------------------------------
151 *
152 * get_ticks:
153 * This function get system ticks number.
154 *
155 * get_ticks() interface:
156 * tick_base:base number of system ticks.
157 *
158 * Returns: a long long int number represent how many
159 ticks from system start based on tick_base.
160 */
161
162 unsigned long long get_ticks(void);
163
164
165 /*---------------------------------------------------
166 *
167 * usec_to_tick:
168 * This function convert microsecond to system ticks.
169 *
170 * usec_to_tick() interface:
171 * usec:0~357913941(MAX) int number.
172 *
173 * Returns: converted system ticks.
174 */
175 u64 usec_to_tick(u64 usec);
176
177 #define delay udelay
178
179 #endif /* __TIMER_H__ */