huangcm
2025-07-03 a76b2fadf6ad4adf86e241e3753a63efe03ef80c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
*********************************************************************************************************
*                                                AR100 SYSTEM
*                                     AR100 Software System Develop Kits
*                                                timer  module
*
*                                    (c) Copyright 2012-2016, Sunny China
*                                             All Rights Reserved
*
* File    : timer.h
* By      : Sunny
* Version : v1.0
* Date    : 2012-4-27
* Descript: timer controller public header.
* Update  : date                auther      ver     notes
*           2012-4-27 17:03:52  Sunny       1.0     Create this file.
*********************************************************************************************************
*/
 
#ifndef __TIMER_H__
#define __TIMER_H__
 
/* the total number of hardware timer */
#define TIMERC_TIMERS_NUMBER (2)
#define SOFTTIMER_NUMBER     (2)
 
/* timer work mode */
typedef enum timer_mode {
   TIMER_MODE_PERIOD       = 0x0,  /* period trigger mode */
   TIMER_MODE_ONE_SHOOT    = 0x1,  /* one shoot trigger mode */
} timer_mode_e;
 
/*
*********************************************************************************************************
*                                       INIT TIMER
*
* Description:  initialize timer.
*
* Arguments  :  none.
*
* Returns    :  OK if initialize timer succeeded, others if failed.
*********************************************************************************************************
*/
s32 timer_init(void);
 
/*
*********************************************************************************************************
*                                       EXIT TIMER
*
* Description:  exit timer.
*
* Arguments  :  none.
*
* Returns    :  OK if exit timer succeeded, others if failed.
*********************************************************************************************************
*/
s32 timer_exit(void);
 
/*
*********************************************************************************************************
*                                       REQUEST TIMER
*
* Description:  request a hardware timer.
*
* Arguments  :  phdle   : the callback when the requested timer tick reached.
*               parg    : the argument for the callback.
*
* Returns    :  the handler if request hardware timer succeeded, NULL if failed.
*
* Note       :  the callback execute entironment : CPU disable interrupt response.
*********************************************************************************************************
*/
HANDLE timer_request(__pCBK_t phdle, void *parg);
 
/*
*********************************************************************************************************
*                                       RELEASE TIMER
*
* Description:  release a hardware timer.
*
* Arguments  :  htimer  : the handler of the released timer.
*
* Returns    :  OK if release hardware timer succeeded, others if failed.
*********************************************************************************************************
*/
s32 timer_release(HANDLE htimer);
 
/*
*********************************************************************************************************
*                                       START TIMER
*
* Description:  start a hardware timer.
*
* Arguments  :  htimer  : the timer handler which we want to start.
*               period  : the period of the timer trigger, base on us.
*               mode    : the mode the timer trigger, details please
*                         refer to timer trigger mode.
*
* Returns    :  OK if start hardware timer succeeded, others if failed.
*********************************************************************************************************
*/
s32 timer_start(HANDLE htimer, u32 period, u32 mode);
 
 
/*
*********************************************************************************************************
*                                       STOP TIMER
*
* Description:  stop a hardware timer.
*
* Arguments  :  htimer  : the timer handler which we want ot stop.
*
* Returns    :  OK if stop hardware timer succeeded, others if failed.
*********************************************************************************************************
*/
s32 timer_stop(HANDLE htimer);
 
/* timer standby services */
s32  timer_standby_init(void);
s32  timer_standby_exit(void);
bool timer_standby_expired(void);
 
/* timer delay services */
void time_mdelay(u32 ms);     /* base on hardware timer */
void time_cdelay(u32 cycles); /* base on cpu cycle */
void time_udelay(u32 us);     /* base on hardware counter */
void cnt64_udelay(u32 us);
 
#define udelay(us) time_udelay(us)
#define mdelay(ms) time_mdelay(ms)
 
 
#endif  /*__TIMER_H__*/