📄 timer.c
字号:
s2410RTC->rALMSEC = (unsigned char)TO_BCD(lpst->wSecond );
s2410RTC->rALMMIN = (unsigned char)TO_BCD(lpst->wMinute );
s2410RTC->rALMHOUR = (unsigned char)TO_BCD(lpst->wHour );
s2410RTC->rALMDAY = (unsigned char)TO_BCD(lpst->wDay );
s2410RTC->rALMMON = (unsigned char)TO_BCD(lpst->wMonth );
s2410RTC->rALMYEAR = (unsigned char)TO_BCD((lpst->wYear % 100));
s2410RTC->rRTCALM = 0x7f;
s2410RTC->rRTCCON = (0 << 0); /* RTC Control Disable */
s2410INT->rSRCPND = BIT_RTC; /* RTC Alarm Interrupt Clear */
if (s2410INT->rINTPND & BIT_RTC) s2410INT->rINTPND = BIT_RTC;
s2410INT->rINTMSK &= ~BIT_RTC; /* RTC Alarm Enable */
return TRUE;
}
#if 0
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL
OEMSetAlarmTime(LPSYSTEMTIME lpst)
{
volatile RTCreg *s2410RTC = (RTCreg *)RTC_BASE;
RETAILMSG(1,(TEXT("OEMSetAlarmTime: Year: %u, Month: %u, Day: %u, Hour: %u, Minute: %u, second: %u rcnr=%Xh\n"),
lpst->wYear, lpst->wMonth,lpst->wDay, lpst->wHour, lpst->wMinute,lpst->wSecond,s2410RTC->rRTCCON));
s2410RTC->rRTCCON = (1 << 0); /* RTC Control Enable */
s2410RTC->rALMSEC = (unsigned char)TO_BCD(lpst->wSecond );
s2410RTC->rALMMIN = (unsigned char)TO_BCD(lpst->wMinute );
s2410RTC->rALMHOUR = (unsigned char)TO_BCD(lpst->wHour );
s2410RTC->rALMDAY = (unsigned char)TO_BCD(lpst->wDay );
s2410RTC->rALMMON = (unsigned char)TO_BCD(lpst->wMonth );
s2410RTC->rALMYEAR = (unsigned char)TO_BCD((lpst->wYear % 100));
s2410RTC->rRTCCON = (0 << 0); /* RTC Control Disable */
return TRUE;
}
#endif
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD
PerfCountFreq()
{
return (OEMClockFreq);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD
PerfCountSinceTick()
{
volatile PWMreg *s2410PWM;
DWORD dwCount;
s2410PWM = (PWMreg *)PWM_BASE;
dwCount= ((DWORD)s2410PWM->rTCNTO4);
// Note: if dwCount is negative, the counter went past the match point. The math
// still works since it accounts for the dwReschedIncr time plus the time past
// the match.
return dwCurReschedIncr - dwCount;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
CPUSetSysTimerCount(
DWORD dwCountdownMSec
)
{
DWORD dwMatch, ttmp;
volatile PWMreg *s2410PWM;
s2410PWM = (PWMreg *)PWM_BASE;
dwCurReschedIncr = dwCountdownMSec * OEMCount1ms;
dwMatch = dwCurReschedIncr;
s2410PWM->rTCNTB4 = dwMatch;
ttmp = s2410PWM->rTCON & (~(0xf << 20));
s2410PWM->rTCON = ttmp | (2 << 20); /* update TCVNTB4, stop */
s2410PWM->rTCON = ttmp | (1 << 20); /* one-shot mode, start */
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL
CPUClearSysTimerIRQ(
void
)
{
volatile INTreg *s2410INT;
BOOL fPending;
DWORD intstatus;
s2410INT = (INTreg *)INT_BASE;
intstatus = s2410INT->rSRCPND;
if ((intstatus & (BIT_TIMER4)) != 0) {
s2410INT->rSRCPND = BIT_TIMER4;
s2410INT->rINTPND = BIT_TIMER4;
fPending = TRUE;
} else {
fPending = FALSE;
}
return fPending;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD
CPUGetSysTimerCountElapsed(
DWORD dwTimerCountdownMSec,
volatile DWORD *pCurMSec,
DWORD *pPartialCurMSec,
volatile ULARGE_INTEGER *pCurTicks
)
{
volatile PWMreg *s2410PWM;
DWORD dwTick, dwCount;
s2410PWM = (PWMreg *)PWM_BASE;
dwTick = dwTimerCountdownMSec * OEMCount1ms;
// If timer IRQ pending, a full resched period elapsed
if (CPUClearSysTimerIRQ( )) {
*pCurMSec += dwTimerCountdownMSec;
pCurTicks->QuadPart += dwTick;
return dwTimerCountdownMSec;
}
// No timer IRQ pending, calculate how much time has elapsed
dwCount= ((DWORD)s2410PWM->rTCNTO4);
if (dwCount > dwTick) {
// This is an error case. Recover gracefully.
dwCount = dwTick;
} else {
dwCount = dwTick - dwCount;
}
pCurTicks->QuadPart += dwCount;
dwCount += *pPartialCurMSec;
*pPartialCurMSec = dwCount % OEMCount1ms;
*pCurMSec += (dwCount /= OEMCount1ms);
return dwCount;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
extern void CPUEnterIdleMode(void);
extern void OEMWriteDebugLED(WORD wIndex, DWORD dwPattern);
void
CPUEnterIdle()
{
static volatile CLKPWRreg * s2410CLKPW = (CLKPWRreg *)CLKPWR_BASE;
static volatile IOPreg * s2410IOP = (IOPreg *)IOP_BASE;
static volatile UART0reg * s2410UART0 = (UART0reg *)UART0_BASE;
static volatile UART2reg * s2410UART2 = (UART2reg *)UART2_BASE;
fInterruptFlag = FALSE;
INTERRUPTS_ON();
if ( !(s2410UART0->rUFSTAT & 0x3ff) && !(s2410UART2->rUFSTAT & 0x3ff) ) /* Check UART FIFO */
{
if (!fSlowInterruptFlag)
{
s2410IOP->rGPFDAT &= ~(1 << 5);
// s2410CLKPW->rCLKCON |= (1 << 2); /* Enter IDLE Mode */
MMU_WaitForInterrupt();
}
while (!fInterruptFlag) {} /* Wait until S3C2410X enters IDLE mode */
if (!fSlowInterruptFlag)
{
// s2410CLKPW->rCLKCON &= ~(1 << 2); /* turn-off IDLE bit. */
/* Any interrupt will wake up from IDLE mode */
s2410IOP->rGPFDAT |= (1 << 5);
}
}
else
{
while (!fInterruptFlag) {} /* Wait until S3C2410X enters IDLE mode */
}
}
// Maximum idle is fixed a 1 ms because the PIT has to count down to 0 before reloading
// the new countdown value.
#define IDLE_MAX_MS 10 // 100
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD
CPUGetSysTimerCountMax(
DWORD dwIdleMSecRequested
)
{
if (dwIdleMSecRequested > IDLE_MAX_MS) {
return IDLE_MAX_MS;
}
return dwIdleMSecRequested;
}
void EnterSlowMode()
{
static volatile CLKPWRreg * s2410CLKPW = (CLKPWRreg *)CLKPWR_BASE;
static volatile IOPreg * s2410IOP = (IOPreg *)IOP_BASE;
static volatile MEMreg * s2410MemReg = (MEMreg *)MEMCTRL_BASE;
//RETAILMSG(1,(TEXT("EnterSlowMode \r\n")));
fSlowInterruptFlag = TRUE;
s2410IOP->rGPFDAT &= ~(1 << 7);
//FCLK=FIN/1, SLOW mode, MPLL=off, UPLL=off
s2410CLKPW->rCLKSLOW |= (1<<4)|(1<<5)|(1<<7);
saveREFRESH = s2410MemReg->rREFRESH;
s2410MemReg->rREFRESH=(1<<23)|(unsigned int)(2048+1-12*15.6);
//Trp=2clk, Trc=4clk
}
void ExitSlowMode()
{
static volatile CLKPWRreg * s2410CLKPW = (CLKPWRreg *)CLKPWR_BASE;
static volatile IOPreg * s2410IOP = (IOPreg *)IOP_BASE;
static volatile MEMreg * s2410MemReg = (MEMreg *)MEMCTRL_BASE;
// int i;
//RETAILMSG(1,(TEXT("ExitSlowMode \r\n")));
fSlowInterruptFlag = FALSE;
s2410CLKPW->rCLKSLOW = 0|(1<<4)|(0<<5);// PLL on, MPLL=on
//for ( i = 0; i < 2048; i++); //S/W MPLL lock-time
s2410CLKPW->rCLKSLOW = 0|(0<<4)|(0<<5);// NORMAL mode, PLL=on, MPLL=on
s2410MemReg->rREFRESH = saveREFRESH;
s2410IOP->rGPFDAT |= (1 << 7);
}
void SetSysTimerInterval(DWORD dwTicks)
{
volatile PWMreg *s2410PWM = (PWMreg *)PWM_BASE;
volatile INTreg *s2410INT = (INTreg *)INT_BASE;
DWORD dwTimerTemp;
// Mask and clear timer interrupt.
//
s2410INT->rINTMSK |= BIT_TIMER4;
s2410INT->rSRCPND = BIT_TIMER4;
s2410INT->rINTPND = BIT_TIMER4;
// Change number of timer ticks in the period.
//
s2410PWM->rTCNTB4 = dwTicks;
dwTimerTemp = s2410PWM->rTCON & (~(0xf << 20));
s2410PWM->rTCON = dwTimerTemp | (2 << 20); // Update TCVNTB4 and stop.
s2410PWM->rTCON = dwTimerTemp | (1 << 20); // One-shot mode and start.
// Unmask the timer interrupt.
//
s2410INT->rINTMSK &= ~BIT_TIMER4;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -