www.pudn.com > BIOS-S3C2410.rar > rtctest.c


#include "def.h" 
#include "2410addr.h" 
#include "2410lib.h" 
#include "rtcapi.h" 
#include "alarm.h" 
#include "timer.h" 
 
static volatile int AlarmWake; 
 
static void AlarmNotify(void) 
{ 
	AlarmWake = 1; 
} 
 
static void RtcTestCheck(U32 i) 
{	 
	static cnt = 10; 
	 
	if(!--cnt) { 
		 
		ReleaseBiosTimerEvent(i); 
	} 
} 
 
void RtcTest(void) 
{ 
	DATETIME_T dt; 
	U32 i;	 
	 
	EnableModuleClock(CLOCK_RTC); 
	 
	RtcGetDate(&dt); 
	RequestBiosTimerEvent(1); 
 
	printf("Set date is %4d-%2d-%2d week %d, time is %2d:%2d:%2d\n",  
			dt1.year, dt1.month, dt1.day, dt1.week, dt1.hour, dt1.minute, dt1.second); 
	RtcSetDate(&dt1); 
	 
	OpenAlarm(AlarmNotify); 
	 
	AlarmSetDate(&dt2); 
	getalr = AlarmGetDate(&dt1); 
		 
	printf("Set alarm and enter idle mode...\n"); 
	AlarmWake = 0; 
	rCLKCON	|= 1<<2;		//enter IDLE mode 
	 
	for(i=0; i<10; i++);	 
	 
	rCLKCON &= ~(1<<2);		//manual clear	 
	 
	CloseAlarm(); 
 
	printf("Wakeup from idle mode by alarm test %s\n", AlarmWake?"success":"fail"); 
	 
	if(getalr) 
		printf("alarm time = %4d-%2d-%2d %2d:%2d:%2d\n", dt1.year, dt1.month, dt1.day, dt1.hour, dt1.minute, dt1.second); 
	else 
		puts("Get alarm time fail\n"); 
	 
	RtcGetDate(&dt1); 
	printf("Now date is %4d-%2d-%2d week %d, time is %2d:%2d:%2d", 
			dt1.year, dt1.month, dt1.day, dt1.week, dt1.hour, dt1.minute, dt1.second);	 
}