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

📄 timer.c

📁 wince 下的bsp测试wince_bspSMDK2440_L35T32.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
/*++
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) 2001. Samsung Electronics, co. ltd  All rights reserved.

Module Name:  

Abstract:

    Platform dependent PCMCIA initialization functions

rev:
	2002.4.11	: RTC function work (Hyojoon KIM, zzartto@samsung.com)
	2002.4.3	: first S3C2410 version (SOC)
	
	2002.2.5	: timer related bug fixups (kwangyoon LEE, kwangyoon@samsung.com)
				  prevent timer round-up
					- CPUSetSysTimerCount()
					- CPUClearSysTimerIRQ()
					- CPUGetSysTimerCountElapsed()
	2002.1.29	: bug fixups (kwangyoon LEE, kwangyoon@samsung.com)
					- PerfCountFreq()
					- PerfCountSinceTick()
					- CPUSetSysTimerCount()
					- CPUClearSysTimerIRQ()
					- CPUGetSysTimerCountElapsed()
					- CPUGetSysTimerCountMax()
	2002.1.28	: CE.NET initial port (kwangyoon LEE, kwangyoon@samsung.com)

Notes: 
--*/

#include <windows.h>
#include <nkintr.h>

#include <S2440.h>

extern DWORD CurMSec;
extern DWORD DiffMSec;
DWORD dwReschedIncrement;
DWORD OEMCount1ms;
static volatile DWORD dwCurReschedIncr;
void EnterSlowMode();
void ExitSlowMode();

extern void MMU_WaitForInterrupt(void);

unsigned __int64 RealTimeBias = 0;  // Number of 100-nanosecond intervals since
                                    // January 1, 1601. 
DWORD AlarmTime = 0;    			// Alarm Off at startup

volatile BOOL fInterruptFlag;
volatile BOOL fSlowInterruptFlag;
unsigned int saveREFRESH;

//------------------------------------------------------------------------------
//
// When this is called we will set up GPIO<1> to be a falling edge interrupt  
// InitClock sets up the OS timer to int via match reg 0 on the IRQ level
// an int is requested in 1ms from now.
//
// Interrupts are disable when this is called. check with Thomas.
//
//------------------------------------------------------------------------------
void 
InitClock(void) 
{
    volatile PWMreg *s2440PWM =(PWMreg *)PWM_BASE;
    volatile INTreg *s2440INT = (INTreg *)INT_BASE;  
    DWORD ttmp;  


	// Timer4 as OS tick and disable it first.
    s2440INT->rINTMSK |= BIT_TIMER4;		// Mask timer4 interrupt.
    s2440INT->rSRCPND = BIT_TIMER4;			// Clear pending bit
    s2440INT->rINTPND = BIT_TIMER4;

	// Operating clock : PCLK=101500000 (101.5 Mhz)    
	// IMPORTANT : MUST CHECK S2440.H DEFINITIONS !!!!
	s2440PWM->rTCFG1  = 0x8080;	//;;; SHL
	s2440PWM->rTCFG0 &= ~(0xff << 8);		/* Prescaler 1's Value			*/
	s2440PWM->rTCFG0 |= (PRESCALER << 8);	// prescaler value=15
	
	/* Timer4 Divider field clear */
	s2440PWM->rTCFG1 = 0x11111;	// ;;; SHL
	s2440PWM->rTCFG1 &= ~(0xf << 16);
	
#if( SYS_TIMER_DIVIDER == D2 )
	  	s2440PWM->rTCFG1  |=  (D1_2   << 16);		/* 1/2							*/
#elif ( SYS_TIMER_DIVIDER == D4 )
		s2440PWM->rTCFG1  |=  (D1_4   << 16);		/* 1/4							*/
#elif ( SYS_TIMER_DIVIDER == D8 )
	  	s2440PWM->rTCFG1  |=  (D1_8   << 16);		/* 1/8							*/
#elif ( SYS_TIMER_DIVIDER == D16 )
	  	s2440PWM->rTCFG1  |=  (D1_16   << 16);		/* 1/16							*/
#endif
	s2440PWM->rTCNTB4 = RESCHED_INCREMENT;	//((RESCHED_PERIOD * OEM_CLOCK_FREQ) / 1000)  	
	ttmp = s2440PWM->rTCON & (~(0xf << 20));

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

    // Number of timer counts for reschedule interval
    dwReschedIncrement = RESCHED_INCREMENT;

	// Set OEM timer count for 1 ms
    OEMCount1ms = OEM_COUNT_1MS;
    
    // Set OEM clock frequency
    OEMClockFreq = OEM_CLOCK_FREQ;

    s2440INT->rINTMSK &= ~BIT_TIMER4;		

    return;
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD 
GetTimerPeriod(void) 
{
    return RESCHED_PERIOD;
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#define FROM_BCD(n)		((((n) >> 4) * 10) + ((n) & 0xf))

// NOTE: The RTC on the SMDK2440 isn't battery-backed so RTC settings will be lost
// when power is removed.
//
BOOL 
OEMGetRealTime(LPSYSTEMTIME lpst) 
{
#if 0
	volatile RTCreg *s2440RTC = (RTCreg *)RTC_BASE;

	do
	{
		lpst->wYear			= FROM_BCD(s2440RTC->rBCDYEAR) + 2000 ;
		lpst->wMonth		= FROM_BCD(s2440RTC->rBCDMON   & 0x1f);
		lpst->wDay			= FROM_BCD(s2440RTC->rBCDDAY   & 0x3f);

		lpst->wDayOfWeek	= (s2440RTC->rBCDDATE - 1);
	
		lpst->wHour			= FROM_BCD(s2440RTC->rBCDHOUR  & 0x3f);
		lpst->wMinute		= FROM_BCD(s2440RTC->rBCDMIN   & 0x7f);
		lpst->wSecond		= FROM_BCD(s2440RTC->rBCDSEC   & 0x7f);
		lpst->wMilliseconds	= 0;
	}
	while(!(lpst->wSecond));

	return(TRUE);
#else
	volatile RTCreg *s2440RTC; 

	s2440RTC = (RTCreg *)RTC_BASE;
    
	//RETAILMSG(1, (_T("OEMGetRealTime\r\n")));
    
	// enable RTC control
//	s2440RTC->rRTCCON = 0x1;
	lpst->wMilliseconds = 0;
    
	lpst->wSecond    = FROM_BCD(s2440RTC->rBCDSEC & 0x7f);
	lpst->wMinute	 = FROM_BCD(s2440RTC->rBCDMIN & 0x7f);
	lpst->wHour	 = FROM_BCD(s2440RTC->rBCDHOUR& 0x3f);
	lpst->wDayOfWeek = (s2440RTC->rBCDDATE - 1);
	lpst->wDay	 = FROM_BCD(s2440RTC->rBCDDAY & 0x3f);
	lpst->wMonth	 = FROM_BCD(s2440RTC->rBCDMON & 0x1f);
	// lpst->wYear	 = (2000 + s2440RTC->rBCDYEAR) ; 
	lpst->wYear	 = FROM_BCD(s2440RTC->rBCDYEAR) + 2000 ; 

	if ( lpst->wSecond == 0 )
	{
		lpst->wSecond    = FROM_BCD(s2440RTC->rBCDSEC & 0x7f);
		lpst->wMinute	 = FROM_BCD(s2440RTC->rBCDMIN & 0x7f);
		lpst->wHour		 = FROM_BCD(s2440RTC->rBCDHOUR& 0x3f);
		lpst->wDayOfWeek = (s2440RTC->rBCDDATE - 1);
		lpst->wDay		 = FROM_BCD(s2440RTC->rBCDDAY & 0x3f);
		lpst->wMonth	 = FROM_BCD(s2440RTC->rBCDMON & 0x1f);
		lpst->wYear = (2000 + s2440RTC->rBCDYEAR) ; 
	}
	// disable RTC control
//	s2440RTC->rRTCCON = 0;

	return TRUE;
#endif
	
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#define TO_BCD(n)		((((n) / 10) << 4) | ((n) % 10))

// NOTE: The RTC on the SMDK2440 isn't battery-backed so RTC settings will be lost
// when power is removed.
//
BOOL
OEMSetRealTime(LPSYSTEMTIME lpst) 
{
#if 0
	volatile RTCreg *s2440RTC = (RTCreg *)RTC_BASE;
 
	// Enable RTC control.
	//
	s2440RTC->rRTCCON |= 1;

	s2440RTC->rBCDSEC  = (unsigned char)TO_BCD(lpst->wSecond );
	s2440RTC->rBCDMIN  = (unsigned char)TO_BCD(lpst->wMinute );
	s2440RTC->rBCDHOUR = (unsigned char)TO_BCD(lpst->wHour   );

	s2440RTC->rBCDDATE = (unsigned char)(lpst->wDayOfWeek + 1);

	s2440RTC->rBCDDAY  = (unsigned char)TO_BCD(lpst->wDay    );
	s2440RTC->rBCDMON  = (unsigned char)TO_BCD(lpst->wMonth  );
	s2440RTC->rBCDYEAR = (unsigned char)TO_BCD((lpst->wYear % 100));

	RETAILMSG(1,(TEXT("OEMSetRealTime: Year: %x, Month: %x, Day: %x, Hour: %x, Minute: %x, second: %x rcnr=%Xh\n"), \
   		s2440RTC->rBCDYEAR, s2440RTC->rBCDMON,s2440RTC->rBCDDAY, s2440RTC->rBCDHOUR, s2440RTC->rBCDMIN,s2440RTC->rBCDSEC,s2440RTC->rRTCCON));

	// Disable RTC control.
	//
	s2440RTC->rRTCCON &= ~1;
	
	return(TRUE);
#else
	volatile RTCreg *s2440RTC = (RTCreg *)RTC_BASE;
 	static int firsttime = 0;

	// enable RTC control
	s2440RTC->rRTCCON =  0x1;

	s2440RTC->rBCDSEC  = (unsigned char)TO_BCD(lpst->wSecond );
	s2440RTC->rBCDMIN  = (unsigned char)TO_BCD(lpst->wMinute );
	s2440RTC->rBCDHOUR = (unsigned char)TO_BCD(lpst->wHour   );

	s2440RTC->rBCDDATE = (unsigned char)(lpst->wDayOfWeek + 1);

	if ( firsttime == 0 )
	{
		lpst->wYear = 2003;	lpst->wMonth = 1;	lpst->wDay = 1;
		firsttime = 1;
	}

	s2440RTC->rBCDDAY  = (unsigned char)TO_BCD(lpst->wDay    );
	s2440RTC->rBCDMON  = (unsigned char)TO_BCD(lpst->wMonth  );
	s2440RTC->rBCDYEAR = (unsigned char)TO_BCD((lpst->wYear % 100));

	RETAILMSG(1,(TEXT("OEMSetRealTime: 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));
	RETAILMSG(1,(TEXT("OEMSetRealTime(register): Year: %x, Month: %x, Day: %x, Hour: %x, Minute: %x, second: %x rcnr=%Xh\n"), \
   		s2440RTC->rBCDYEAR, s2440RTC->rBCDMON,s2440RTC->rBCDDAY, s2440RTC->rBCDHOUR, s2440RTC->rBCDMIN,s2440RTC->rBCDSEC,s2440RTC->rRTCCON));

	// disable RTC control
	s2440RTC->rRTCCON = 0; //&= ~0x1;
	
	// Just certify heart bit
//	timer_cnt = 0;

	return TRUE;
#endif	
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL 

⌨️ 快捷键说明

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