/*H***************************************************************************** * * $Archive:: $ * $Revision:: $ * $Date:: $ * $Author:: $ * * DESCRIPTION: contains the timing functions for the TMS320C5410 DSP. * * GLOBALS * * PUBLIC FUNCTIONS: * * PRIVATE FUNCTIONS: * * USAGE/LIMITATIONS: * * NOTES: * * AUTHOR: Patrick Cresap, 2000 * *H***************************************************************************/ #define timer5410_c /*---- compilation control switches ----------------------------------------*/ /***************************************************************************** * INCLUDE FILES *****************************************************************************/ /*---- system and platform files -------------------------------------------*/ /*---- program files -------------------------------------------------------*/ #include "timer5410.h" /***************************************************************************** * EXTERNAL REFERENCE *****************************************************************************/ /*---- data declarations ---------------------------------------------------*/ extern CLOCK_STRUCT clock; /*---- function prototypes -------------------------------------------------*/ /***************************************************************************** * PUBLIC DECLARATIONS *****************************************************************************/ /*-- Interrupt macros-------------------------------------------------*/ #define GLOBAL_INT_ENABLE asm( " rsbx intm ") /* enables interrupts*/ #define GLOBAL_INT_DISABLE asm( " ssbx intm ") /* disable interrupts*/ /***************************************************************************** * PRIVATE DECLARATIONS *****************************************************************************/ /*---- context -------------------------------------------------------------*/ /*---- data declarations ---------------------------------------------------*/ /*---- function prototypes -------------------------------------------------*/ /*---- macros --------------------------------------------------------------*/ /***************************************************************************** * PUBLIC FUNCTION DEFINITIONS *****************************************************************************/ /*F*************************************************************************** * NAME: void C5XX_TimerInit( int TintPeriod ) * * DESCRIPTION: * Initializes the C5XX timer. * * NOTES: You must stop the timer before changing period or values and then * restart it. *F***************************************************************************/ void C5XX_TimerInit( int TintPeriod ) { /*-- Stop the timer, set prd and TCR, start the timer -----------------*/ *TCR = TSS; *PRD = TintPeriod; *TCR = TDDR0 | TDDR3 | TCR_SOFT; *TCR |= TRB; } /*F*************************************************************************** * NAME: void time ( void ) * * DESCRIPTION: * A basic timing function that counts milliseconds, seconds, minutes, and * hours. * NOTES: Only counts to 24 hours, 59 mins, 59 secs, then resets. * *F***************************************************************************/ void time ( void ) { clock.millisecond++; if (clock.millisecond == 1000) { clock.millisecond = 0; clock.second++; } if (clock.second == 60) { clock.second = 0; clock.minute++; } if (clock.minute == 60) { clock.minute = 0; clock.hour++; } if (clock.hour == 24) { clock.hour = 0; } } /*F*************************************************************************** * NAME: void set_time(void) * * DESCRIPTION: * sets the time by incrementing by the number of timer interrupts there are * * NOTES: * writes outside ofinterrupt *F***************************************************************************/ void set_time(void) { while (clock.tick) { time(); GLOBAL_INT_DISABLE; clock.tick--; GLOBAL_INT_ENABLE; } }