timer.c
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 90 行
C
90 行
/*++
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.
Copyright (c) 1995, 1996, 1997 Microsoft Corporation
Module Name:
timer.c
Abstract:
Notes:
--*/
#include <windows.h>
#include <nkintr.h>
#include <alt_def.h>
#include <vrc5074.h>
#include "timer.h"
extern void InitMIPSClock();
extern UINT TimerISR();
void InitClockTimer2()
{
PVRC5074_CONTROL pVrc5074 = (PVRC5074_CONTROL) (KSEG1_BASE | VRC5074_BASE);
//RETAILMSG (1, (TEXT("T2CTRL.Lo address = 0x%x\r\n"), &pVrc5074->T2CTRL.Lo));
//RETAILMSG (1, (TEXT("T2CTRL.Hi address = 0x%x\r\n"), &pVrc5074->T2CTRL.Hi));
//RETAILMSG (1, (TEXT("T2CNTR.Lo address = 0x%x\r\n"), &pVrc5074->T2CNTR.Lo));
//RETAILMSG (1, (TEXT("PERIOD_INC = 0x%x\r\n"), PERIOD_INC));
pVrc5074->T2CTRL.Hi = 0x00; // Stop the timer.
pVrc5074->T2CTRL.Lo = PERIOD_INC; // This gives 1 ms !!!
pVrc5074->T2CNTR.Lo = PERIOD_INC; // Start counting from here.
pVrc5074->T2CTRL.Hi = 0x01; // Let's boogie now...
// Enable timer2 interrupt.
//RETAILMSG (1, (TEXT("INTCTRL.Lo address = 0x%x\r\n"), pVrc5074->INTCTRL.Lo));
pVrc5074->INTCTRL.Lo = pVrc5074->INTCTRL.Lo | 0x08000000;
}
void InitClock(void)
{
// HookInterrupt(4, (void *)TimerISR);
// InitMIPSClock();
}
int GetTimerPeriod(void)
{
return(CPURTCSHORT_PERIOD);
}
// Return a better than 25 ms resolution...
DWORD SC_GetTickCount(void)
{
PVRC5074_CONTROL pVrc5074 = (PVRC5074_CONTROL) (KSEG1_BASE | VRC5074_BASE);
DWORD dwBaseMs, dwCurCount, dwTickCount;
do
{
dwBaseMs = *(volatile unsigned long *)AddrCurMSec;
dwCurCount = pVrc5074->T2CNTR.Lo;
}
while ((dwBaseMs != *(volatile unsigned long *)AddrCurMSec));
// Not forgeting that counter counts down.
dwCurCount = PERIOD_INC - dwCurCount;
// Up to date mSecond = *AddrCurMSec + dwCurCount adjusted to ms unit.
dwTickCount = dwBaseMs + (dwCurCount * CPURTCSHORT_PERIOD) / PERIOD_INC;
return dwTickCount;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?