⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.c

📁 wince 下的bsp测试wince_bspSMDK2440_L35T32.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
OEMSetAlarmTime(LPSYSTEMTIME lpst) 
{
	volatile INTreg *s2440INT = (INTreg *)INT_BASE;		// for alarm 030818
	volatile RTCreg *s2440RTC = (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,s2440RTC->rRTCCON));

	if ( !lpst ||			// for alarm 030818
		(lpst->wSecond > 59)   ||  // 0 - 59
		(lpst->wMinute > 59)   ||  // 0 - 59
		(lpst->wHour > 23)     ||  // 0 - 23
		(lpst->wDayOfWeek > 6) ||  // 0 - 6, Sun:0, Mon:1, ...
		(lpst->wDay > 31)      ||  // 0 - 31
		(lpst->wMonth > 12)    ||  // 1 - 12, Jan:1, Feb:2, ...
		(lpst->wMonth == 0)    ||
		(lpst->wYear < 2000)   ||  // We have a 100 year calander (2 BDC digits) with 
		(lpst->wYear > 2099)       // a leap year generator hard-wired to year 2000.
	)
	return FALSE;    

	s2440RTC->rRTCCON = (1 << 0);					/* RTC Control Enable 			*/
    
	s2440RTC->rALMSEC  = (unsigned char)TO_BCD(lpst->wSecond );
	s2440RTC->rALMMIN  = (unsigned char)TO_BCD(lpst->wMinute );
	s2440RTC->rALMHOUR = (unsigned char)TO_BCD(lpst->wHour   );

	s2440RTC->rALMDAY  = (unsigned char)TO_BCD(lpst->wDay    );
	s2440RTC->rALMMON  = (unsigned char)TO_BCD(lpst->wMonth  );
	s2440RTC->rALMYEAR = (unsigned char)TO_BCD((lpst->wYear % 100));

	s2440RTC->rRTCALM = 0x7f;	// for alarm 030818

	s2440RTC->rRTCCON = (0 << 0);					/* RTC Control Disable			*/

	// for alarm 030818
	s2440INT->rSRCPND  =  BIT_RTC;     /* RTC Alarm Interrupt Clear */
	s2440INT->rINTPND  =  BIT_RTC;
	s2440INT->rINTMSK &= ~BIT_RTC;     /* RTC Alarm Enable    */
 
	return TRUE;
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD
PerfCountFreq()
{
    return (OEMClockFreq);
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD
PerfCountSinceTick()
{
    volatile PWMreg *s2440PWM;
    DWORD dwCount;

    s2440PWM = (PWMreg *)PWM_BASE;

    dwCount= ((DWORD)s2440PWM->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 *s2440PWM;

    s2440PWM = (PWMreg *)PWM_BASE;
	
    dwCurReschedIncr = dwCountdownMSec * OEMCount1ms;
    dwMatch = dwCurReschedIncr;

	s2440PWM->rTCNTB4 = dwMatch;

	ttmp = s2440PWM->rTCON & (~(0xf << 20));

	s2440PWM->rTCON = ttmp | (2 << 20);		/* update TCVNTB4, stop					*/
	s2440PWM->rTCON = ttmp | (1 << 20);		/* one-shot mode,  start				*/
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL
CPUClearSysTimerIRQ(
    void
    )
{
	volatile INTreg *s2440INT; 
	BOOL fPending;
	DWORD intstatus;
	    
	s2440INT = (INTreg *)INT_BASE;
		
	intstatus = s2440INT->rSRCPND;

	if ((intstatus & (BIT_TIMER4)) != 0) {
		s2440INT->rSRCPND = BIT_TIMER4;        
		s2440INT->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 *s2440PWM;
	DWORD dwTick, dwCount;

    s2440PWM = (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)s2440PWM->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 * s2440CLKPW = (CLKPWRreg *)CLKPWR_BASE;
	static volatile IOPreg    * s2440IOP   = (IOPreg    *)IOP_BASE;
	
	fInterruptFlag = FALSE;
	INTERRUPTS_ON();

	s2440IOP->rGPFDAT &= ~(1 << 5);
	s2440CLKPW->rCLKCON |=  (1 << 2);		/* Enter IDLE Mode                              */
	while (!fInterruptFlag) {}					/* Wait until S3C2440X enters IDLE mode         */
	s2440CLKPW->rCLKCON &= ~(1 << 2);		/* turn-off IDLE bit.                           */
											/* Any interrupt will wake up from IDLE mode    */
	s2440IOP->rGPFDAT |= (1 << 5);
}


// 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  100
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD
CPUGetSysTimerCountMax(
    DWORD dwIdleMSecRequested
    )
{
    if (dwIdleMSecRequested > IDLE_MAX_MS) {
        return IDLE_MAX_MS;
    }
    return dwIdleMSecRequested;
}

void EnterSlowMode()
{
	static volatile CLKPWRreg * s2440CLKPW  = (CLKPWRreg *)CLKPWR_BASE;
	static volatile IOPreg    * s2440IOP    = (IOPreg    *)IOP_BASE;
	static volatile MEMreg	  * s2440MemReg = (MEMreg      *)MEMCTRL_BASE;

	//RETAILMSG(1,(TEXT("EnterSlowMode \r\n")));
	fSlowInterruptFlag = TRUE;
	s2440IOP->rGPFDAT &= ~(1 << 7);

	//FCLK=FIN/1, SLOW mode, MPLL=off, UPLL=off
	s2440CLKPW->rCLKSLOW |= (1<<4)|(1<<5)|(1<<7);
	saveREFRESH = s2440MemReg->rREFRESH;
	s2440MemReg->rREFRESH=(1<<23)|(unsigned int)(2048+1-12*15.6);
	//Trp=2clk, Trc=4clk
}

void ExitSlowMode()
{
	static volatile CLKPWRreg * s2440CLKPW  = (CLKPWRreg *)CLKPWR_BASE;
	static volatile IOPreg    * s2440IOP    = (IOPreg    *)IOP_BASE;
	static volatile MEMreg	  * s2440MemReg = (MEMreg      *)MEMCTRL_BASE;
//	int i;

	//RETAILMSG(1,(TEXT("ExitSlowMode \r\n")));
	fSlowInterruptFlag = FALSE;

	s2440CLKPW->rCLKSLOW = 0|(1<<4)|(0<<5);// PLL on, MPLL=on
	//for ( i = 0; i < 2048; i++); //S/W MPLL lock-time
	s2440CLKPW->rCLKSLOW = 0|(0<<4)|(0<<5);// NORMAL mode, PLL=on, MPLL=on
	s2440MemReg->rREFRESH = saveREFRESH;

	s2440IOP->rGPFDAT |= (1 << 7);
}


void SetSysTimerInterval(DWORD dwTicks)
{
    volatile PWMreg *s2440PWM = (PWMreg *)PWM_BASE;
    volatile INTreg *s2440INT = (INTreg *)INT_BASE;  
    DWORD dwTimerTemp;  

	// Mask and clear timer interrupt.
	//
    s2440INT->rINTMSK |= BIT_TIMER4;
    s2440INT->rSRCPND  = BIT_TIMER4;
    s2440INT->rINTPND  = BIT_TIMER4;

	// Change number of timer ticks in the period.
	//
	s2440PWM->rTCNTB4 = dwTicks;
	dwTimerTemp = s2440PWM->rTCON & (~(0xf << 20));

	s2440PWM->rTCON = dwTimerTemp | (2 << 20);	// Update TCVNTB4 and stop.
	s2440PWM->rTCON = dwTimerTemp | (1 << 20);	// One-shot mode and start.

	// Unmask the timer interrupt.
	//
    s2440INT->rINTMSK &= ~BIT_TIMER4;		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -