📄 timer.c
字号:
//**********************************************************************
//
// Filename: timer.c
//
// Description: Routines dealing with the timer.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to
// use this source code. For a copy of the EULA, please see the
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved
//
//**********************************************************************
#include <windows.h>
#include <nkintr.h>
#include <hwdefs.h>
#include <clocks.h>
#include <debugtimer.h>
extern void EnterStandbyMode();
//
// ISRs set this flag to indicate an interrupt has occurred
//
volatile BOOL fInterruptFlag;
volatile DWORD PerfCountValueSinceTick=0;
//
// counts per reschedule
//
extern DWORD dwReschedIncrement;
//****************************************************************************
// CPUEnterIdle
//****************************************************************************
// Put the cpu into a low-power state. If none is available, loop on a
// flag that gets set by ISRs.
//
//
void CPUEnterIdle(DWORD dwIdleParam)
{
// volatile ULONG ulTemp;
fInterruptFlag = FALSE;
// ulTemp = *CSC_STBY;
// EnterStandbyMode( );
INTERRUPTS_ON();
while (!fInterruptFlag)
{
// Just sit here. Any interrupt will bump us out.
//
// Execute halt command here.
//
}
}
//****************************************************************************
// CPUGetSysTimerCountMax
//****************************************************************************
// Determine the maximum delay for a given request within the limits of the
// hardware
//
DWORD CPUGetSysTimerCountMax(DWORD dwIdleMSecRequested)
{
if (dwIdleMSecRequested > IDLE_MAX_MS)
{
//
// Our timer isn't capable of idling more than IDLE_MAX_MS milliseconds.
// We'll have to break the sleep time into reasonable chunks.
//
return IDLE_MAX_MS;
}
return dwIdleMSecRequested;
}
//****************************************************************************
// SetSysTimerInterval
//****************************************************************************
// Set a timer to a specific tick count instead of the time in milliseconds.
//
//
void SetSysTimerInterval(DWORD dwTicks)
{
// Program the new timer value
//
*TIM_TIMER1CONTROL = TIMERCONTROL_CLKSEL | TIMERCONTROL_MODE ;
*TIM_TIMER1LOAD = dwTicks;
*TIM_TIMER1CONTROL = TIMERCONTROL_CLKSEL | TIMERCONTROL_MODE |
TIMERCONTROL_ENABLE;
// RETAILMSG(1, (TEXT("%d\r\n"),dwCount));
}
//****************************************************************************
// CPUSetSysTimerCount
//****************************************************************************
// Set the new period for the timer in milliseconds.
//
//
void CPUSetSysTimerCount(DWORD dwIdleMSec)
{
DWORD dwTicks;
//
// Determine the number of ticks required for the number of milliseconds
// requested
//
dwTicks = dwIdleMSec * RESCHED_INCREMENT;
//
// Program the new timer value
//
*TIM_TIMER1CONTROL = TIMERCONTROL_CLKSEL | TIMERCONTROL_MODE ;
*TIM_TIMER1LOAD = dwTicks;
*TIM_TIMER1CONTROL = TIMERCONTROL_CLKSEL | TIMERCONTROL_MODE |
TIMERCONTROL_ENABLE;
}
//****************************************************************************
// CPUClearSysTimerIRQ
//****************************************************************************
// Return TRUE if a timer IRQ was pending, false otherwise.
// Clear the interrupt if pending.
//
BOOL CPUClearSysTimerIRQ(void)
{
BOOL bReturnValue;
bReturnValue = (*VIC1_RAWINTR & INT1_TIMER1);
if(bReturnValue)
{
*TIM_TIMER1CLEAR = 0;
}
//
// Return if an interrupt was pending.
//
return(bReturnValue);
}
//****************************************************************************
// PerfCountFreq
//****************************************************************************
// This function returns the frequency of the timer used by PerfCountSinceTick
// and PerfCountFreq.
//
DWORD PerfCountFreq()
{
//
// Need to change this to the 1 us debug timer.
//
return OEM_CLOCK_FREQ;
}
//****************************************************************************
// PerfCountSinceTick
//****************************************************************************
// Counter value based on the current high-performance counter
// for the system.
//
DWORD PerfCountSinceTick()
{
// DWORD intstatus = (*VIC1_RAWINTR | INT1_TIMER1);
DWORD dwCount;
// if an interrupt is pending we have gone past the count limit
/*if(intstatus )
{
//
// We don't really know how long we are overdue, so just return one
// tick's worth of counts
//
dwCount = dwReschedIncrement;
}
else */
{
//
// Timer counts down, so calculate the number of ticks elapsed.
//
dwCount = dwReschedIncrement - *TIM_TIMER1VALUE;
}
return dwCount + PerfCountValueSinceTick;
}
//****************************************************************************
// InitTimer
//****************************************************************************
// Initialize the scheduling timer.
//
//
void InitClock(void)
{
//
// Initialize and start scheduler timer. Initialize the clock to
// 508Khz, Perodic mode.
//
dwReschedIncrement =RESCHED_INCREMENT;
*TIM_TIMER1LOAD = dwReschedIncrement; //508*RESCHED_PERIOD;//dwReschedIncrement;
*TIM_TIMER1CONTROL = TIMERCONTROL_CLKSEL | TIMERCONTROL_MODE |
TIMERCONTROL_ENABLE;
// *TIM_TIMER3CONTROL = TIMERCONTROL_CLKSEL |
// TIMERCONTROL_ENABLE;
*TIM_DEBUGVALUEHIGH = 0;
*TIM_DEBUGVALUEHIGH = DEBUGVALUEHIGH_ENABLE;
}
/* EOF board.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -