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

📄 rtc.c

📁 WinCE5.0BSP for Renesas SH7770
💻 C
字号:
//
//  Copyright(C) Renesas Technology Corp. 2005. All rights reserved.
//
//  generic RTC code for ITS-DS7 Ver.0.8.0
//
//  FILE      : rtc.c
//  CREATED   : 2005.08.10
//  MODIFIED  : 
//  AUTHOR    : Renesas Technology Corp.
//  HARDWARE  : RENESAS ITS-DS7
//  HISTORY   : 
//              2005.08.10
//              - Created release code.
//                (based on SMDK2410/MAINSTONEII for WCE5.0)
//

//------------------------------------------------------------------------------
//
//  Module: rtc.c
//
//  Real-time clock (RTC) routines for the Renesas SH7770 processor.
//
#include <windows.h>
#include <nkintr.h>

#include "shx.h"
#include "sh7770.h"
#include "platform.h"
#include "ver_its_ds7.h"

#define	RTCFLG_FLG	0x0002

//------------------------------------------------------------------------------
//
//  Function:  OEMGetRealTime
//
//  Reads the current RTC value and returns a system time.
//
BOOL OEMGetRealTime(
    LPSYSTEMTIME lpst										// @parm pointer to memory to return current time
)
{
	USHORT	i,ii;
	ii = 0;

	do{
		// Data Read Command
		i = READ_REGISTER_USHORT(RTCSTART);

		// Infinite loop is prevanted when flg is not set to 1 
		if( ii++ >= 0xffff )	return FALSE; 

	// Check Carry Flag
	}while( (READ_REGISTER_USHORT(RTCFLG) & RTCFLG_FLG) );

	lpst->wMilliseconds = 0;			// Milli Seconds
	lpst->wSecond = READ_REGISTER_USHORT(RTCS) / 32;	// Second
	lpst->wMinute = READ_REGISTER_USHORT(RTCMN);	// Munite
	lpst->wHour   = READ_REGISTER_USHORT(RTCH);	// Hour
	lpst->wDayOfWeek = 0;				// Day of Week (not supported)
	lpst->wDay    = READ_REGISTER_USHORT(RTCD);	// Day
	lpst->wMonth  = READ_REGISTER_USHORT(RTCM);	// Month
	lpst->wYear   = READ_REGISTER_USHORT(RTCY) + 2000;	// Year

//	DEBUGMSG(1, (TEXT("OEMGetRealTime[%04d/%02d/%02d %02d:%02d:%02d]\r\n")	,lpst->wYear
//															,lpst->wMonth
//															,lpst->wDay
//															,lpst->wHour
//															,lpst->wMinute
//															,lpst->wSecond ));

	return TRUE;

}

//------------------------------------------------------------------------------
//
//  Function:  OEMSetRealTime
//
//  Updates the RTC with the specified system time.
//
BOOL OEMSetRealTime(
    LPSYSTEMTIME lpst									// @parm pointer to new time
)
{
//	DEBUGMSG(1, (TEXT("OEMSetRealTime[%04d/%02d/%02d %02d:%02d:%02d]\r\n")	,lpst->wYear
//															,lpst->wMonth
//															,lpst->wDay
//															,lpst->wHour
//															,lpst->wMinute
//															,lpst->wSecond ));

	// check value
	if ((lpst->wYear < 2000) ||
		(lpst->wYear > 2099) ||
		(lpst->wMonth < 1) ||
		(lpst->wMonth > 12) ||
		(lpst->wDay < 1) ||
		(lpst->wDay > 31) ||
		(lpst->wHour < 0) ||
		(lpst->wHour > 23) ||
		(lpst->wMinute < 0) ||
		(lpst->wMinute > 59) ||
		(lpst->wSecond < 0) ||
		(lpst->wSecond > 59)) {
		// Invalid time
//		DEBUGMSG(1, (TEXT("Invalid time not set RTC. %04d/%02d/%02d %02d:%02d:%02d\r\n"),lpst->wYear
//															,lpst->wMonth
//															,lpst->wDay
//															,lpst->wHour
//															,lpst->wMinute
//															,lpst->wSecond ));
		return FALSE;
	}

	// Set Realtime data
	WRITE_REGISTER_USHORT(RTCYSET, lpst->wYear - 2000);	// Year
	WRITE_REGISTER_USHORT(RTCMSET, lpst->wMonth);		// Month
	WRITE_REGISTER_USHORT(RTCDSET, lpst->wDay);			// Day
	WRITE_REGISTER_USHORT(RTCHSET, lpst->wHour);		// Hour
	WRITE_REGISTER_USHORT(RTCMNSET,lpst->wMinute);		// Minute
	WRITE_REGISTER_USHORT(RTCSSET, lpst->wSecond * 32);	// Second

	// Start RTC in changed time
	WRITE_REGISTER_USHORT(RTCSTART, 0xffff);

	return TRUE;
}

//------------------------------------------------------------------------------
//
//  Function:  OEMSetAlarmTime
//
//  Set the RTC alarm time.
//
BOOL OEMSetAlarmTime(
    LPSYSTEMTIME lpst	// @parm pointer to alarm time
)
{	
	// NOTE :
	// SH7770's RTC has not alarm function. therefore this function is not supported.

	return TRUE;
}

//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalInitRTC
//
//  This function is called by WinCE OS to initialize the time after boot.
//  Input buffer contains SYSTEMTIME structure with default time value.
//  If hardware has persistent real time clock it will ignore this value
//  (or all call).
//
BOOL OALIoCtlHalInitRTC(
    UINT32 code, VOID *pInpBuffer, UINT32 inpSize,
    VOID *pOutBuffer, UINT32 outSize, UINT32 *pOutSize) 
{
	SYSTEMTIME st;
	SYSTEMTIME defst = {2000,1,0,1,0,0,0,0};	// RTC default

    // The kernel has detected a cold-boot.  We probably need to reset our Real Time Clock
    if( inpSize >= sizeof(SYSTEMTIME) && pInpBuffer!=NULL ){
		OEMGetRealTime(&st);
		if ((st.wYear == defst.wYear) &&
			(st.wMonth == defst.wMonth) &&
			(st.wDay == defst.wDay) &&
			(st.wHour == defst.wHour) &&
			(st.wMinute == defst.wMinute) &&
			(st.wSecond == defst.wSecond)){
			//RTC initialized
            return OEMSetRealTime( (LPSYSTEMTIME)pInpBuffer );
		}
		return TRUE;
	}
    else
        return FALSE;
}

⌨️ 快捷键说明

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