1 /*****************************************************************************
2 * Copyright 2004 - 2008 Broadcom Corporation. All rights reserved.
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
13 *****************************************************************************/
15 /****************************************************************************/
19 * @brief API definitions for low level Timer driver
22 /****************************************************************************/
26 #include <csp/stdint.h>
28 typedef uint32_t tmrHw_ID_t
; /* Timer ID */
29 typedef uint32_t tmrHw_COUNT_t
; /* Timer count */
30 typedef uint32_t tmrHw_INTERVAL_t
; /* Timer interval */
31 typedef uint32_t tmrHw_RATE_t
; /* Timer event (count/interrupt) rate */
34 tmrHw_INTERRUPT_STATUS_SET
, /* Interrupted */
35 tmrHw_INTERRUPT_STATUS_UNSET
/* No Interrupt */
36 } tmrHw_INTERRUPT_STATUS_e
;
39 tmrHw_CAPABILITY_CLOCK
, /* Clock speed in HHz */
40 tmrHw_CAPABILITY_RESOLUTION
/* Timer resolution in bits */
43 /****************************************************************************/
45 * @brief Get timer capability
47 * This function returns various capabilities/attributes of a timer
49 * @return Numeric capability
52 /****************************************************************************/
53 uint32_t tmrHw_getTimerCapability(tmrHw_ID_t timerId
, /* [ IN ] Timer Id */
54 tmrHw_CAPABILITY_e capability
/* [ IN ] Timer capability */
57 /****************************************************************************/
59 * @brief Configures a periodic timer in terms of timer interrupt rate
61 * This function initializes a periodic timer to generate specific number of
62 * timer interrupt per second
64 * @return On success: Effective timer frequency
68 /****************************************************************************/
69 tmrHw_RATE_t
tmrHw_setPeriodicTimerRate(tmrHw_ID_t timerId
, /* [ IN ] Timer Id */
70 tmrHw_RATE_t rate
/* [ IN ] Number of timer interrupt per second */
73 /****************************************************************************/
75 * @brief Configures a periodic timer to generate timer interrupt after
76 * certain time interval
78 * This function initializes a periodic timer to generate timer interrupt
79 * after every time interval in milisecond
81 * @return On success: Effective interval set in mili-second
85 /****************************************************************************/
86 tmrHw_INTERVAL_t
tmrHw_setPeriodicTimerInterval(tmrHw_ID_t timerId
, /* [ IN ] Timer Id */
87 tmrHw_INTERVAL_t msec
/* [ IN ] Interval in mili-second */
90 /****************************************************************************/
92 * @brief Configures a periodic timer to generate timer interrupt just once
93 * after certain time interval
95 * This function initializes a periodic timer to generate a single ticks after
96 * certain time interval in milisecond
98 * @return On success: Effective interval set in mili-second
102 /****************************************************************************/
103 tmrHw_INTERVAL_t
tmrHw_setOneshotTimerInterval(tmrHw_ID_t timerId
, /* [ IN ] Timer Id */
104 tmrHw_INTERVAL_t msec
/* [ IN ] Interval in mili-second */
107 /****************************************************************************/
109 * @brief Configures a timer to run as a free running timer
111 * This function initializes a timer to run as a free running timer
113 * @return Timer resolution (count / sec)
116 /****************************************************************************/
117 tmrHw_RATE_t
tmrHw_setFreeRunningTimer(tmrHw_ID_t timerId
, /* [ IN ] Timer Id */
118 uint32_t divider
/* [ IN ] Dividing the clock frequency */
119 ) __attribute__ ((section(".aramtext")));
121 /****************************************************************************/
123 * @brief Starts a timer
125 * This function starts a preconfigured timer
127 * @return -1 - On Failure
130 /****************************************************************************/
131 int tmrHw_startTimer(tmrHw_ID_t timerId
/* [ IN ] Timer id */
132 ) __attribute__ ((section(".aramtext")));
134 /****************************************************************************/
136 * @brief Stops a timer
138 * This function stops a running timer
140 * @return -1 - On Failure
143 /****************************************************************************/
144 int tmrHw_stopTimer(tmrHw_ID_t timerId
/* [ IN ] Timer id */
147 /****************************************************************************/
149 * @brief Gets current timer count
151 * This function returns the current timer value
153 * @return Current downcounting timer value
156 /****************************************************************************/
157 tmrHw_COUNT_t
tmrHw_GetCurrentCount(tmrHw_ID_t timerId
/* [ IN ] Timer id */
158 ) __attribute__ ((section(".aramtext")));
160 /****************************************************************************/
162 * @brief Gets timer count rate
164 * This function returns the number of counts per second
169 /****************************************************************************/
170 tmrHw_RATE_t
tmrHw_getCountRate(tmrHw_ID_t timerId
/* [ IN ] Timer id */
171 ) __attribute__ ((section(".aramtext")));
173 /****************************************************************************/
175 * @brief Enables timer interrupt
177 * This function enables the timer interrupt
182 /****************************************************************************/
183 void tmrHw_enableInterrupt(tmrHw_ID_t timerId
/* [ IN ] Timer id */
186 /****************************************************************************/
188 * @brief Disables timer interrupt
190 * This function disable the timer interrupt
194 /****************************************************************************/
195 void tmrHw_disableInterrupt(tmrHw_ID_t timerId
/* [ IN ] Timer id */
198 /****************************************************************************/
200 * @brief Clears the interrupt
202 * This function clears the timer interrupt
207 * Must be called under the context of ISR
209 /****************************************************************************/
210 void tmrHw_clearInterrupt(tmrHw_ID_t timerId
/* [ IN ] Timer id */
213 /****************************************************************************/
215 * @brief Gets the interrupt status
217 * This function returns timer interrupt status
219 * @return Interrupt status
221 /****************************************************************************/
222 tmrHw_INTERRUPT_STATUS_e
tmrHw_getInterruptStatus(tmrHw_ID_t timerId
/* [ IN ] Timer id */
225 /****************************************************************************/
227 * @brief Indentifies a timer causing interrupt
229 * This functions returns a timer causing interrupt
231 * @return 0xFFFFFFFF : No timer causing an interrupt
232 * ! 0xFFFFFFFF : timer causing an interrupt
234 * tmrHw_clearIntrrupt() must be called with a valid timer id after calling this function
236 /****************************************************************************/
237 tmrHw_ID_t
tmrHw_getInterruptSource(void);
239 /****************************************************************************/
241 * @brief Displays specific timer registers
247 /****************************************************************************/
248 void tmrHw_printDebugInfo(tmrHw_ID_t timerId
, /* [ IN ] Timer id */
249 int (*fpPrint
) (const char *, ...) /* [ IN ] Print callback function */
252 /****************************************************************************/
254 * @brief Use a timer to perform a busy wait delay for a number of usecs.
258 /****************************************************************************/
259 void tmrHw_udelay(tmrHw_ID_t timerId
, /* [ IN ] Timer id */
260 unsigned long usecs
/* [ IN ] usec to delay */
261 ) __attribute__ ((section(".aramtext")));
263 #endif /* _TMRHW_H */