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

📄 testrtc.c

📁 pxa27x下rtc程序
💻 C
字号:
#include <stdio.h>
#include "regsdef.h"
#include "utils.h"
#include "XsCp15.h"
#include "xsIntCtrlApi.h"

static volatile int ints;

static void RtcIrqHandler(void *dummy)
{
	UINT rtsr = RTSR;
	
	if(rtsr & (1<<0))	//AL
		ints |= 1;
	if(rtsr & (1<<4))	//RDAL1
		ints |= 2;
	if(rtsr & (1<<8))	//SWAL1
		ints |= 4;
	if(rtsr & (1<<13))	//PIAL
		ints |= 8;
	
	RTSR = rtsr;
}

static int TestTimerAlarm(void)
{
	UINT val, tm;
	
	val = RCNR + 2;
	RTAR  = val;
	RTSR |= (1<<2) | (1<<0);
	
	tm = 400;
	do {
		DM_WaitMs(10);
		tm--;
	} while(!(ints&1) && tm);
	RTSR &= ~(1<<2);
	
	return (tm!=0);
}

static int TestWristwatch(void)
{
	UINT tm;
	int i;
	
	RYCR = (2005<<9) | (11<<5) | (16);
	RDCR = (3<<20) | (4<<17) | (13<<12) | (30<<6) | (30);
	DM_WaitMs(100);
	printf("Current date: %d-%d-%d, time: %d:%d:%d\r\n",
			(RYCR>>9)&0xfff, (RYCR>>5)&0xf, RYCR&0x1f,
			(RDCR>>12)&0x1f, (RDCR>>6)&0x3f, RDCR&0x3f);
	
	RYAR1 = (2005<<9) | (11<<5) | (16);
	RDAR1 = (3<<20) | (4<<17) | (13<<12) | (30<<6) | (35);
	RTSR |= (1<<5) | (1<<4);
	
	for (i=0; i<5; i++)
	{
		tm = 100;
		do {
			DM_WaitMs(10);
			tm--;
		} while(!(ints&2) && tm);
		printf("Current date: %d-%d-%d, time: %d:%d:%d\r\n",
			(RYCR>>9)&0xfff, (RYCR>>5)&0xf, RYCR&0x1f,
			(RDCR>>12)&0x1f, (RDCR>>6)&0x3f, RDCR&0x3f);
	}
	RTSR &= ~(1<<5);
	return (tm!=0);
}

static int TestStopWatch(void)
{
	UINT tm;
	
	//RTSR &= ~(1<<12);
	SWAR1 = (0<<19) | (0<<13) | (2<<7) | 0;	//set 2 seconds and reset SWCR
	RTSR |= (1<<12) | (1<<9) | (1<<8);
	DM_WaitMs(10);
	printf("SWCR = 0x%08x\r\n", SWCR);
	
	tm = 400;
	do {
		DM_WaitMs(10);
		tm--;
	} while(!(ints&4) && tm);
	RTSR &= ~((1<<12) | (1<<9));
	
	printf("SWCR = 0x%08x\r\n", SWCR);
	
	return (tm!=0);
}

static int TestPeriodic(void)
{
	UINT tm;
	
	//RTSR &= ~(1<<15);
	PIAR = 2000;	//set 2 seconds and reset RTCPICR
	RTSR |= (1<<15) | (1<<14) | (1<<13);
	DM_WaitMs(1);
	printf("PICR = 0x%08x\r\n", RTCPICR);
	
	tm = 4000;
	do {
		DM_WaitMs(1);
		tm--;
	} while(!(ints&8) && tm);
	RTSR &= ~((1<<15) | (1<<14));
	
	printf("PICR = 0x%08x\r\n", RTCPICR);
	
	return (tm!=0);
}

void TestRtc(void)
{
	ints = 0;
	
	if(XsIcRegisterHandler (XSIC_RTC_ALRM_SGNL, RtcIrqHandler, 0)) {
		printf("Register RTC interrupt handler error!\r\n");
		return ;
	}

	XsIcEnableIrqDeviceInt(XSIC_RTC_ALRM_SGNL);
		
	printf("Test RTC timer...\r\n");
	printf("%s\r\n", TestTimerAlarm() ? "success" : "fail");
	printf("Test wristwatch...\r\n");
	printf("%s\r\n", TestWristwatch() ? "success" : "fail");
	printf("Test stop watch...\r\n");
	printf("%s\r\n", TestStopWatch() ? "success" : "fail");
	printf("Test periodic...\r\n");
	printf("%s\r\n", TestPeriodic() ? "success" : "fail");	

	XsIcDisableIrqDeviceInt(XSIC_RTC_ALRM_SGNL);
	XsIcUnRegisterHandler (XSIC_RTC_ALRM_SGNL);
//	return 0;
}

⌨️ 快捷键说明

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