Path: blob/master/arch/arm/mach-bcmring/include/csp/tmrHw.h
10820 views
/*****************************************************************************1* Copyright 2004 - 2008 Broadcom Corporation. All rights reserved.2*3* Unless you and Broadcom execute a separate written software license4* agreement governing use of this software, this software is licensed to you5* under the terms of the GNU General Public License version 2, available at6* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").7*8* Notwithstanding the above, under no circumstances may you combine this9* software in any way with any other Broadcom software provided under a10* license other than the GPL, without Broadcom's express prior written11* consent.12*****************************************************************************/1314/****************************************************************************/15/**16* @file tmrHw.h17*18* @brief API definitions for low level Timer driver19*20*/21/****************************************************************************/22#ifndef _TMRHW_H23#define _TMRHW_H2425#include <csp/stdint.h>2627typedef uint32_t tmrHw_ID_t; /* Timer ID */28typedef uint32_t tmrHw_COUNT_t; /* Timer count */29typedef uint32_t tmrHw_INTERVAL_t; /* Timer interval */30typedef uint32_t tmrHw_RATE_t; /* Timer event (count/interrupt) rate */3132typedef enum {33tmrHw_INTERRUPT_STATUS_SET, /* Interrupted */34tmrHw_INTERRUPT_STATUS_UNSET /* No Interrupt */35} tmrHw_INTERRUPT_STATUS_e;3637typedef enum {38tmrHw_CAPABILITY_CLOCK, /* Clock speed in HHz */39tmrHw_CAPABILITY_RESOLUTION /* Timer resolution in bits */40} tmrHw_CAPABILITY_e;4142/****************************************************************************/43/**44* @brief Get timer capability45*46* This function returns various capabilities/attributes of a timer47*48* @return Numeric capability49*50*/51/****************************************************************************/52uint32_t tmrHw_getTimerCapability(tmrHw_ID_t timerId, /* [ IN ] Timer Id */53tmrHw_CAPABILITY_e capability /* [ IN ] Timer capability */54);5556/****************************************************************************/57/**58* @brief Configures a periodic timer in terms of timer interrupt rate59*60* This function initializes a periodic timer to generate specific number of61* timer interrupt per second62*63* @return On success: Effective timer frequency64* On failure: 065*66*/67/****************************************************************************/68tmrHw_RATE_t tmrHw_setPeriodicTimerRate(tmrHw_ID_t timerId, /* [ IN ] Timer Id */69tmrHw_RATE_t rate /* [ IN ] Number of timer interrupt per second */70);7172/****************************************************************************/73/**74* @brief Configures a periodic timer to generate timer interrupt after75* certain time interval76*77* This function initializes a periodic timer to generate timer interrupt78* after every time interval in millisecond79*80* @return On success: Effective interval set in mili-second81* On failure: 082*83*/84/****************************************************************************/85tmrHw_INTERVAL_t tmrHw_setPeriodicTimerInterval(tmrHw_ID_t timerId, /* [ IN ] Timer Id */86tmrHw_INTERVAL_t msec /* [ IN ] Interval in mili-second */87);8889/****************************************************************************/90/**91* @brief Configures a periodic timer to generate timer interrupt just once92* after certain time interval93*94* This function initializes a periodic timer to generate a single ticks after95* certain time interval in millisecond96*97* @return On success: Effective interval set in mili-second98* On failure: 099*100*/101/****************************************************************************/102tmrHw_INTERVAL_t tmrHw_setOneshotTimerInterval(tmrHw_ID_t timerId, /* [ IN ] Timer Id */103tmrHw_INTERVAL_t msec /* [ IN ] Interval in mili-second */104);105106/****************************************************************************/107/**108* @brief Configures a timer to run as a free running timer109*110* This function initializes a timer to run as a free running timer111*112* @return Timer resolution (count / sec)113*114*/115/****************************************************************************/116tmrHw_RATE_t tmrHw_setFreeRunningTimer(tmrHw_ID_t timerId, /* [ IN ] Timer Id */117uint32_t divider /* [ IN ] Dividing the clock frequency */118) __attribute__ ((section(".aramtext")));119120/****************************************************************************/121/**122* @brief Starts a timer123*124* This function starts a preconfigured timer125*126* @return -1 - On Failure127* 0 - On Success128*/129/****************************************************************************/130int tmrHw_startTimer(tmrHw_ID_t timerId /* [ IN ] Timer id */131) __attribute__ ((section(".aramtext")));132133/****************************************************************************/134/**135* @brief Stops a timer136*137* This function stops a running timer138*139* @return -1 - On Failure140* 0 - On Success141*/142/****************************************************************************/143int tmrHw_stopTimer(tmrHw_ID_t timerId /* [ IN ] Timer id */144);145146/****************************************************************************/147/**148* @brief Gets current timer count149*150* This function returns the current timer value151*152* @return Current downcounting timer value153*154*/155/****************************************************************************/156tmrHw_COUNT_t tmrHw_GetCurrentCount(tmrHw_ID_t timerId /* [ IN ] Timer id */157) __attribute__ ((section(".aramtext")));158159/****************************************************************************/160/**161* @brief Gets timer count rate162*163* This function returns the number of counts per second164*165* @return Count rate166*167*/168/****************************************************************************/169tmrHw_RATE_t tmrHw_getCountRate(tmrHw_ID_t timerId /* [ IN ] Timer id */170) __attribute__ ((section(".aramtext")));171172/****************************************************************************/173/**174* @brief Enables timer interrupt175*176* This function enables the timer interrupt177*178* @return N/A179*180*/181/****************************************************************************/182void tmrHw_enableInterrupt(tmrHw_ID_t timerId /* [ IN ] Timer id */183);184185/****************************************************************************/186/**187* @brief Disables timer interrupt188*189* This function disable the timer interrupt190*191* @return N/A192*/193/****************************************************************************/194void tmrHw_disableInterrupt(tmrHw_ID_t timerId /* [ IN ] Timer id */195);196197/****************************************************************************/198/**199* @brief Clears the interrupt200*201* This function clears the timer interrupt202*203* @return N/A204*205* @note206* Must be called under the context of ISR207*/208/****************************************************************************/209void tmrHw_clearInterrupt(tmrHw_ID_t timerId /* [ IN ] Timer id */210);211212/****************************************************************************/213/**214* @brief Gets the interrupt status215*216* This function returns timer interrupt status217*218* @return Interrupt status219*/220/****************************************************************************/221tmrHw_INTERRUPT_STATUS_e tmrHw_getInterruptStatus(tmrHw_ID_t timerId /* [ IN ] Timer id */222);223224/****************************************************************************/225/**226* @brief Indentifies a timer causing interrupt227*228* This functions returns a timer causing interrupt229*230* @return 0xFFFFFFFF : No timer causing an interrupt231* ! 0xFFFFFFFF : timer causing an interrupt232* @note233* tmrHw_clearIntrrupt() must be called with a valid timer id after calling this function234*/235/****************************************************************************/236tmrHw_ID_t tmrHw_getInterruptSource(void);237238/****************************************************************************/239/**240* @brief Displays specific timer registers241*242*243* @return void244*245*/246/****************************************************************************/247void tmrHw_printDebugInfo(tmrHw_ID_t timerId, /* [ IN ] Timer id */248int (*fpPrint) (const char *, ...) /* [ IN ] Print callback function */249);250251/****************************************************************************/252/**253* @brief Use a timer to perform a busy wait delay for a number of usecs.254*255* @return N/A256*/257/****************************************************************************/258void tmrHw_udelay(tmrHw_ID_t timerId, /* [ IN ] Timer id */259unsigned long usecs /* [ IN ] usec to delay */260) __attribute__ ((section(".aramtext")));261262#endif /* _TMRHW_H */263264265