1/***************************************************************************** 2* Copyright 2004 - 2008 Broadcom Corporation. All rights reserved. 3* 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"). 8* 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 12* consent. 13*****************************************************************************/ 14 15/****************************************************************************/ 16/** 17* @file tmrHw.h 18* 19* @brief API definitions for low level Timer driver 20* 21*/ 22/****************************************************************************/ 23#ifndef _TMRHW_H 24#define _TMRHW_H 25 26#include <csp/stdint.h> 27 28typedef uint32_t tmrHw_ID_t; /* Timer ID */ 29typedef uint32_t tmrHw_COUNT_t; /* Timer count */ 30typedef uint32_t tmrHw_INTERVAL_t; /* Timer interval */ 31typedef uint32_t tmrHw_RATE_t; /* Timer event (count/interrupt) rate */ 32 33typedef enum { 34 tmrHw_INTERRUPT_STATUS_SET, /* Interrupted */ 35 tmrHw_INTERRUPT_STATUS_UNSET /* No Interrupt */ 36} tmrHw_INTERRUPT_STATUS_e; 37 38typedef enum { 39 tmrHw_CAPABILITY_CLOCK, /* Clock speed in HHz */ 40 tmrHw_CAPABILITY_RESOLUTION /* Timer resolution in bits */ 41} tmrHw_CAPABILITY_e; 42 43/****************************************************************************/ 44/** 45* @brief Get timer capability 46* 47* This function returns various capabilities/attributes of a timer 48* 49* @return Numeric capability 50* 51*/ 52/****************************************************************************/ 53uint32_t tmrHw_getTimerCapability(tmrHw_ID_t timerId, /* [ IN ] Timer Id */ 54 tmrHw_CAPABILITY_e capability /* [ IN ] Timer capability */ 55); 56 57/****************************************************************************/ 58/** 59* @brief Configures a periodic timer in terms of timer interrupt rate 60* 61* This function initializes a periodic timer to generate specific number of 62* timer interrupt per second 63* 64* @return On success: Effective timer frequency 65* On failure: 0 66* 67*/ 68/****************************************************************************/ 69tmrHw_RATE_t tmrHw_setPeriodicTimerRate(tmrHw_ID_t timerId, /* [ IN ] Timer Id */ 70 tmrHw_RATE_t rate /* [ IN ] Number of timer interrupt per second */ 71); 72 73/****************************************************************************/ 74/** 75* @brief Configures a periodic timer to generate timer interrupt after 76* certain time interval 77* 78* This function initializes a periodic timer to generate timer interrupt 79* after every time interval in milisecond 80* 81* @return On success: Effective interval set in mili-second 82* On failure: 0 83* 84*/ 85/****************************************************************************/ 86tmrHw_INTERVAL_t tmrHw_setPeriodicTimerInterval(tmrHw_ID_t timerId, /* [ IN ] Timer Id */ 87 tmrHw_INTERVAL_t msec /* [ IN ] Interval in mili-second */ 88); 89 90/****************************************************************************/ 91/** 92* @brief Configures a periodic timer to generate timer interrupt just once 93* after certain time interval 94* 95* This function initializes a periodic timer to generate a single ticks after 96* certain time interval in milisecond 97* 98* @return On success: Effective interval set in mili-second 99* On failure: 0 100* 101*/ 102/****************************************************************************/ 103tmrHw_INTERVAL_t tmrHw_setOneshotTimerInterval(tmrHw_ID_t timerId, /* [ IN ] Timer Id */ 104 tmrHw_INTERVAL_t msec /* [ IN ] Interval in mili-second */ 105); 106 107/****************************************************************************/ 108/** 109* @brief Configures a timer to run as a free running timer 110* 111* This function initializes a timer to run as a free running timer 112* 113* @return Timer resolution (count / sec) 114* 115*/ 116/****************************************************************************/ 117tmrHw_RATE_t tmrHw_setFreeRunningTimer(tmrHw_ID_t timerId, /* [ IN ] Timer Id */ 118 uint32_t divider /* [ IN ] Dividing the clock frequency */ 119) __attribute__ ((section(".aramtext"))); 120 121/****************************************************************************/ 122/** 123* @brief Starts a timer 124* 125* This function starts a preconfigured timer 126* 127* @return -1 - On Failure 128* 0 - On Success 129*/ 130/****************************************************************************/ 131int tmrHw_startTimer(tmrHw_ID_t timerId /* [ IN ] Timer id */ 132) __attribute__ ((section(".aramtext"))); 133 134/****************************************************************************/ 135/** 136* @brief Stops a timer 137* 138* This function stops a running timer 139* 140* @return -1 - On Failure 141* 0 - On Success 142*/ 143/****************************************************************************/ 144int tmrHw_stopTimer(tmrHw_ID_t timerId /* [ IN ] Timer id */ 145); 146 147/****************************************************************************/ 148/** 149* @brief Gets current timer count 150* 151* This function returns the current timer value 152* 153* @return Current downcounting timer value 154* 155*/ 156/****************************************************************************/ 157tmrHw_COUNT_t tmrHw_GetCurrentCount(tmrHw_ID_t timerId /* [ IN ] Timer id */ 158) __attribute__ ((section(".aramtext"))); 159 160/****************************************************************************/ 161/** 162* @brief Gets timer count rate 163* 164* This function returns the number of counts per second 165* 166* @return Count rate 167* 168*/ 169/****************************************************************************/ 170tmrHw_RATE_t tmrHw_getCountRate(tmrHw_ID_t timerId /* [ IN ] Timer id */ 171) __attribute__ ((section(".aramtext"))); 172 173/****************************************************************************/ 174/** 175* @brief Enables timer interrupt 176* 177* This function enables the timer interrupt 178* 179* @return N/A 180* 181*/ 182/****************************************************************************/ 183void tmrHw_enableInterrupt(tmrHw_ID_t timerId /* [ IN ] Timer id */ 184); 185 186/****************************************************************************/ 187/** 188* @brief Disables timer interrupt 189* 190* This function disable the timer interrupt 191* 192* @return N/A 193*/ 194/****************************************************************************/ 195void tmrHw_disableInterrupt(tmrHw_ID_t timerId /* [ IN ] Timer id */ 196); 197 198/****************************************************************************/ 199/** 200* @brief Clears the interrupt 201* 202* This function clears the timer interrupt 203* 204* @return N/A 205* 206* @note 207* Must be called under the context of ISR 208*/ 209/****************************************************************************/ 210void tmrHw_clearInterrupt(tmrHw_ID_t timerId /* [ IN ] Timer id */ 211); 212 213/****************************************************************************/ 214/** 215* @brief Gets the interrupt status 216* 217* This function returns timer interrupt status 218* 219* @return Interrupt status 220*/ 221/****************************************************************************/ 222tmrHw_INTERRUPT_STATUS_e tmrHw_getInterruptStatus(tmrHw_ID_t timerId /* [ IN ] Timer id */ 223); 224 225/****************************************************************************/ 226/** 227* @brief Indentifies a timer causing interrupt 228* 229* This functions returns a timer causing interrupt 230* 231* @return 0xFFFFFFFF : No timer causing an interrupt 232* ! 0xFFFFFFFF : timer causing an interrupt 233* @note 234* tmrHw_clearIntrrupt() must be called with a valid timer id after calling this function 235*/ 236/****************************************************************************/ 237tmrHw_ID_t tmrHw_getInterruptSource(void); 238 239/****************************************************************************/ 240/** 241* @brief Displays specific timer registers 242* 243* 244* @return void 245* 246*/ 247/****************************************************************************/ 248void tmrHw_printDebugInfo(tmrHw_ID_t timerId, /* [ IN ] Timer id */ 249 int (*fpPrint) (const char *, ...) /* [ IN ] Print callback function */ 250); 251 252/****************************************************************************/ 253/** 254* @brief Use a timer to perform a busy wait delay for a number of usecs. 255* 256* @return N/A 257*/ 258/****************************************************************************/ 259void tmrHw_udelay(tmrHw_ID_t timerId, /* [ IN ] Timer id */ 260 unsigned long usecs /* [ IN ] usec to delay */ 261) __attribute__ ((section(".aramtext"))); 262 263#endif /* _TMRHW_H */ 264