?? lltimer.c
字號:
//--------------------------------------------------------------------------
// IP Stack
//--------------------------------------------------------------------------
// llTimer.c
//
// Interface to low-level Timer support
// (DSP/BIOS PRD Based Timing)
//
// Note: This driver requires that a 500ms DSP/BIOS PRD timer
// be added to the aplicatons CDB file, and set to call the
// function llTimerTick() exported by this module.
//
// Author: Michael A. Denio
// Copyright 1999, 2003 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <stkmain.h>
#include <clk.h>
//---------------------------------------------------------------------
// TIMER Functions
//---------------------------------------------------------------------
//
// This define is set to "1" to allow the timer to get down to 1mS
// accuracy by using the DSP/BIOS CLK low-resolution time.
// Set this define to "0" if the DSP/BIOS CLK is *not* based on 1mS
//
#define DSPBIOS_ENHANCED 1
//-----------------------
// Timer Device
//-----------------------
static UINT32 TimeStart; // Time of initialization
static UINT32 TimeS; // Time in seconds
static UINT32 TimeMS; // Time fraction in MS
static UINT32 LastCLKTime; // Last Time value returned from CLK function
static uint LastCLKValid; // Last Time value returned from CLK function
static int TimerOpen = 0; // Flag to know if we should be active
// This is the semaphore to signal when we have an event
static STKEVENT_Handle hEvent;
//--------------------------------------------------------------------
// llTimerTick()
//
// This task just counts HS Ticks as it is called from a DSP/BIOS
// PRD function running at 500ms.
//--------------------------------------------------------------------
void llTimerTick()
{
#ifdef USER_LED1
LED_TOGGLE( USER_LED1 );
#endif
if( TimerOpen )
{
#if DSPBIOS_ENHANCED
LastCLKTime = CLK_getltime();
LastCLKValid = 1;
#endif
TimeMS += 100;
if( TimeMS >= 1000 )
{
TimeS++;
TimeMS -= 1000;
}
STKEVENT_signal( hEvent, STKEVENT_TIMER, 1 );
}
}
//--------------------------------------------------------------------
// _llTimerInit()
//
// Initiate low-level timer support. Called with current time
// in seconds. Timer has a 130 year wrap, so starting time
// reference should be chosen with some care. The reference is
// irrelevant, but should be consisitent.
//--------------------------------------------------------------------
void _llTimerInit( STKEVENT_Handle h, UINT32 ctime )
{
hEvent = h;
TimeStart = TimeS = ctime;
TimeMS = 0;
TimerOpen = 1;
#if DSPBIOS_ENHANCED
LastCLKValid = 0;
#endif
}
//--------------------------------------------------------------------
// _llTimerShutdown()
//
// Shutdown low-level timer support
//--------------------------------------------------------------------
void _llTimerShutdown()
{
TimerOpen = 0;
}
//--------------------------------------------------------------------
// llTimerGetTime()
//
// Called to get the system time in S and optionally MS from bootup.
//--------------------------------------------------------------------
UINT32 llTimerGetTime( UINT32 *pMSFrac )
{
register uint mask,sec;
mask = OEMSysCritOn();
sec = TimeS;
if(pMSFrac)
{
#if DSPBIOS_ENHANCED
if( LastCLKValid )
*pMSFrac = TimeMS + (CLK_getltime() - LastCLKTime);
else
*pMSFrac = TimeMS;
#else
*pMSFrac = TimeMS;
#endif
}
OEMSysCritOff(mask);
return(sec);
}
//--------------------------------------------------------------------
// llTimerGetStartTime()
//
// Called to get the time in S at which the timer was initialized.
//--------------------------------------------------------------------
UINT32 llTimerGetStartTime()
{
return( TimeStart );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -