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

📄 rtc_test.c

📁 s3c24a0固件测试代码 ? ? ? ? ?啊 
💻 C
字号:
//====================================================================
// File Name : RTC_test.c
// Function  : S3C2410 RTC Test Program
// Program   : Shin, On Pil (SOP)
// Date      : May 06, 2002
// Version   : 0.0
// History
//   0.0 : Programming start (March 11, 2002) -> SOP
///////////////////////////////////////////////
// File Name : 24a0RTC.c
// Function  : S3C24a0 RTC Test Program
// Program   : Oh, Woo Seok (SOP)
// Date      : April 14, 2003
// Version   : 0.0
// History
//   0.0 : Programming start (April 14, 2003) -> 337
// 
//====================================================================

#include "option.h"
#include "24a0addr.h"
#include "24a0lib.h"
#include "RTC_test.h"

char *day[8] = {" ","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
volatile int isRtcInt, isInit = 2;              //April 01, 2002 SOP
//volatile unsigned int sec_tick;

void * rtc_func[][2]=
{
	(void *)Display_Rtc,				"RTC time setting	",
	(void *)Test_Rtc_Alarm,			"RTC Alarm Test	",
	(void *)Test_Rtc_Tick,			"RTC Tick INT Test ",
	(void *)RndRst_Rtc,				"RTC Round Reset ",
	0,0
};

void Ch10_RTC(void)
{
	int i;
	
	Uart_Printf("Menu of RTC function\n");
	// Wait until memory stick is inserted.
	
	while(1) {
		RTCSubMessage();
		Uart_Printf("\nSelect(-1 to exit): ");
		i = Uart_GetIntNum();
		//Uart_Printf("IN:%d.\n\n", i);
		if(i==-1) break;
		
		if(i>=0 && (i<(sizeof(rtc_func)/4)) ) 
	    	( (void (*)(void)) (rtc_func[i][0]) )();	// execute selected function.
	}

}

void RTCSubMessage(void)
{
	int i;
	
	
	i=0;	
	Uart_Printf("\n\n");
	while(1)
	{   //display menu
	    Uart_Printf("%2d:%s",i,rtc_func[i][1]);
	    i++;
	    if((int)(rtc_func[i][0])==0)
	    {
			Uart_Printf("\n");
			break;
	    }
	    if((i%4)==0) Uart_Printf("\n");
	}
}

//=======================================
//Period = (n + 1) / 128 second
//   n : Tick time count value (1~127)
//=======================================
//********************[ Display_Rtc ]*********************************
void Display_Rtc(void)
{
//    int year,tmp;
    	int year,tmp,key;                   
    	int month,date,weekday,hour,min,sec;

    	Uart_Printf("[ Display RTC Test ]\n");
    	Uart_Printf("0. RTC Initialize     1. RTC Time Setting    2. Only RTC Display\n\n");
    	Uart_Printf("Selet : ");
    	key = Uart_GetIntNum();
    	Uart_Printf("\n\n");
    
    	isInit = key;

    	if(isInit == 0)
    	{
        	Rtc_Init();
        	isInit = 2;
    	}
    
    	else if(isInit == 1)
    	{
        	Rtc_TimeSet();
        	isInit = 2;        
    	}

    	rRTCCON = 0x01;    //No reset, Merge BCD counters, 1/32768, RTC Control enable
	  Uart_Printf("rtcrst = %08x\n",rRTCRST);


	
    	while(!Uart_GetKey())
    	{    
        	while(1)
        	{
            		if(rBCDYEAR==0x99) 
                		year = 0x1999;
            		else 
                		year    = 0x2000 + rBCDYEAR;
            			month   = rBCDMON;
            			weekday = rBCDDAY;
            			date    = rBCDDATE;
            			hour    = rBCDHOUR;
            			min     = rBCDMIN;
            			sec     = rBCDSEC;
            
            			if(sec!=tmp)                //Same time is not display
            			{
                			tmp = sec;
                		break;
            			}         

        	}
      	Uart_Printf("%2x : %2x : %2x  %10s,  %2x/%2x/%4x\n",hour,min,sec,day[weekday],month,date,year);
        //Uart_Printf("%2x : %2x : %2x  %9s,  %2x/%2x/%4x     rBCDDATE = %x, weekday= %x\n",hour,min,sec,day[weekday],month,date,year,rBCDDATE,weekday);        
    	}
    	rRTCCON = 0x0; //No reset, Merge BCD counters, 1/32768, RTC Control disable(for power consumption)
}

//***********************[ RndRst_Rtc ]*********************************
//Round boundary 30, 40 or 50 Sec
//For example, when the current time is 23:37:47 and the round baundary is selected to 40 sec,
//the round reset changes the current time is 23:38:00.
void RndRst_Rtc(void)
{
    	int year;
    	int month,date,weekday,hour,min,sec,tmp;

    // modified by ows
    	rGPCON_L=rGPCON_L&~(3<<0)|(2<<0);      //GP0=EINT0
    	rEXTINTC0=rEXTINTC0&~(7<<0)|(2<<0);  //EINT0=falling edge triggered

    	if(isInit==0)
    	{
        	Rtc_Init();
        	isInit = 1;
    	}

    	rRTCCON = 0x01;    //No reset, Merge BCD counters, 1/32768, RTC Control enable
    	Uart_Printf("Press any key to exit.\n\n");
    	Uart_Printf("Press EINT0 key to test round reset.\n");

    	// modified by ows
    	rINTMSK=rINTMSK&~(BIT_EINT0_2);
    	rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT0);

    	pISR_EINT0_2 = (unsigned int)EINT0_int;
    
    	while(!Uart_GetKey())
    	{
        	while(1)
        	{
            		if(rBCDYEAR == 0x99) 
                	year = 0x1999;
           	 	else 
                	year    = 0x2000 + rBCDYEAR;
            	  	month   = rBCDMON;
                	weekday = rBCDDAY;
                	date    = rBCDDATE;
                	hour    = rBCDHOUR;
                	min     = rBCDMIN;
                	sec     = rBCDSEC;
            
            		if(sec!=tmp)
            		{
                	tmp = sec;
                	break;
            		}
        	}      
        	Uart_Printf("%2x : %2x : %2x  %10s,  %2x/%2x/%4x\n",hour,min,sec,day[weekday],month,date,year);
    	}
    	rRTCCON = 0x0;   //No reset, Merge BCD counters, 1/32768, RTC Control disable
}

//************************[ Test_Rtc_Alarm ]******************************

#define GPCONM_AVAIL (TRUE)
void Test_Rtc_Alarm(void)  
{
	int save_GPCON_U, save_GPCON_M,save_GPDAT, save_rGPUP;
    	Uart_Printf("[ RTC Alarm Test for S3C24A0 ]\n");
    	Uart_Printf("%2x[sec] : %2x[min] \n",rBCDSEC,rBCDMIN);
    	Uart_Printf("[ alarmed after 5second! \n");

    	Rtc_Init();


    	save_GPCON_M= rGPCON_M;
    	save_GPCON_U= rGPCON_U;	
    	save_GPDAT= rGPDAT;
    	save_rGPUP= rGPPU;    

		

#if GPCONM_AVAIL
	rGPCON_M |= (3<<6);   // check GPIO14 (SMC_INT in circuit)
#else
	rGPCON_U |= (3<<18); // check GPIO28 (XuCTSn1 in circuit)
#endif


    	rRTCCON  = 0x01;                    //No reset, Merge BCD counters, 1/32768, RTC Control enable
    	rALMYEAR = TESTYEAR2 ;
    	rALMMON  = TESTMONTH2;
    	rALMDATE= TESTDATE2  ;
    	rALMHOUR = TESTHOUR2 ;
    	rALMMIN  = TESTMIN2  ;
    	rALMSEC  = TESTSEC2 + 5; 
	
    	isRtcInt = 0;
    	pISR_RTC = (unsigned int)Rtc_Int;
    	rRTCALM  = 0x7f;                    //Global,Year,Month,Day,Hour,Minute,Second alarm enable
    	rRTCCON  = 0x0;                     //No reset, Merge BCD counters, 1/32768, RTC Control disable
    	rINTMSK  = ~(BIT_RTC);

    	while(isRtcInt==0);
    
    	rINTMSK = BIT_ALLMSK;

    	Uart_Printf("[ RTC Alarm Test OK ]\n");
	

     rGPCON_U  = save_GPCON_U;
     rGPCON_M = save_GPCON_M;	
     rGPDAT 	= save_GPDAT;
     rGPPU 	= save_rGPUP;    			

	
    	rRTCCON = 0x0;  //RTC  Control disable(for power consumption), 1/32768, Normal(merge), No reset
}

//************************[ Rtc_Init ]*********************************
void Rtc_Init(void)
{
    	rRTCCON  = rRTCCON  & ~(0xf)  | 0x1;            //No reset, Merge BCD counters, 1/32768, RTC Control enable
    
    	rBCDYEAR = rBCDYEAR & ~(0xff) | TESTYEAR;
    	rBCDMON  = rBCDMON  & ~(0x1f) | TESTMONTH;
    	rBCDDATE = rBCDDATE & ~(0x3f) | TESTDATE;         
    	rBCDDAY  = rBCDDAY  & ~(0x7)  | TESTDAY;       //SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
    	rBCDHOUR = rBCDHOUR & ~(0x3f) | TESTHOUR;
    	rBCDMIN  = rBCDMIN  & ~(0x7f) | TESTMIN;
    	rBCDSEC  = rBCDSEC  & ~(0x7f) | TESTSEC;
    
    	rRTCCON  = 0x0;             //No reset, Merge BCD counters, 1/32768, RTC Control disable    
}

//************************[ Rtc_TimeSet ]*********************************
void Rtc_TimeSet(void)
{
    	int syear,smonth,sdate,shour,smin,ssec;
    	int sday;

    	Uart_Printf("[ RTC Time Setting ]\n");
    	Rtc_Init();         //RTC Initialize
    	Uart_Printf("RTC Time Initialized ...\n");
    
    	Uart_Printf("Year (Two digit the latest)[0x??] : ");
    	syear = Uart_GetIntNum();
    
    	Uart_Printf("Month                      [0x??] : ");
    	smonth = Uart_GetIntNum();

    	Uart_Printf("\n1:Sunday  2:Monday  3:Thesday  4:Wednesday  5:Thursday  6:Friday  7:Saturday\n");
    	Uart_Printf("Day of the week                   : ");
    	sday = Uart_GetIntNum();
	
    	Uart_Printf("Date                      [0x??] : ");
    	sdate = Uart_GetIntNum();
          
    
    	Uart_Printf("Hour                       [0x??] : ");
    	shour = Uart_GetIntNum();
    
    	Uart_Printf("Minute                     [0x??] : ");
    	smin = Uart_GetIntNum();
    
    	Uart_Printf("Second                     [0x??] : ");
    	ssec = Uart_GetIntNum();
    
    	rRTCCON  = rRTCCON  & ~(0xf)  | 0x1;            //No reset, Merge BCD counters, 1/32768, RTC Control enable
    
    	rBCDYEAR = rBCDYEAR & ~(0xff) | syear;
    	rBCDMON  = rBCDMON  & ~(0x1f) | smonth;
    	rBCDDAY  = rBCDDAY  & ~(0x7)  | sday;           //SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
    	rBCDDATE = rBCDDATE & ~(0x3f) | sdate;
    	rBCDHOUR = rBCDHOUR & ~(0x3f) | shour;
    		rBCDMIN  = rBCDMIN  & ~(0x7f) | smin;
    	rBCDSEC  = rBCDSEC  & ~(0x7f) | ssec;
    
    	rRTCCON  = 0x0;    //No reset, Merge BCD counters, 1/32768, RTC Control disable    
}

//************************[ Test_Rtc_Tick ]****************************
void Test_Rtc_Tick(void)
{
    	Uart_Printf("[ RTC Tick interrupt(1 sec) test for S3C24A0 ]\n");
    	Uart_Printf("Press any key to exit.\n"); 
    	Uart_Printf("\n");  
        
    	pISR_TICK = (unsigned)Rtc_Tick;

    	rINTMSK   &= ~(BIT_TIC); 
    	rRTCCON   = 0x0;            //No reset[3], Merge BCD counters[2], BCD clock select XTAL[1], RTC Control disable[0]
    	rTICINT    = (1<<7) + 127;   //Tick time interrupt enable, Tick time count value 127
                                //Period = (n + 1) / 128 second    n:Tick time count value(1~127)
    	Uart_Getch();
    
    	rINTMSK   = BIT_ALLMSK;
    	rRTCCON   = 0x0;            //No reset[3], Merge BCD counters[2], BCD clock select XTAL[1], RTC Control disable[0]
}


//-----------------------------------------------------------------------
void __irq EINT0_int(void)
{
    	rEINTMASK=rEINTMASK|(BIT_EINTPEND_EINT0);
    	rINTMSK=rINTMSK|(BIT_EINT0_2);
    	ClearPending(BIT_EINT0_2);
    	rEINTPEND=BIT_EINTPEND_EINT0;
    	Uart_Printf("EINT0 interrupt is requested for RTC round RESET !\n");

	 rRTCRST = (1<<3) | 3;   //Round second reset enable, over than 30 sec


}

//-----------------------------------------------------------------------
void __irq EINT9_int(void)
{
    	rEINTMASK=rEINTMASK|(BIT_EINTPEND_EINT0);
    	rINTMSK=rINTMSK|(BIT_EINT7_10);
    	ClearPending(BIT_EINT0_2);
    	rEINTPEND=BIT_EINTPEND_EINT0;
    	Uart_Printf("EINT9 interrupt is requested for RTC round RESET !\n");

	 rRTCRST = (1<<3) | 3;   //Round second reset enable, over than 30 sec


}

//-----------------------------------------------------------------------
void __irq Rtc_Int(void)
{
	ClearPending(BIT_RTC);


    	Uart_Printf("RTC Alarm Interrupt O.K.\n");
    	isRtcInt = 1;  
}

void __irq Rtc_Tick(void)
{
	unsigned int sec_tick,f1;
	ClearPending(BIT_TIC);

	
	//sec_tick = sec_tick+1;
	//Uart_Printf("sec tick is .............................%d\n",_SEC_TICK);
    	//if(_SEC_TICK == 1) _Frame_Rate1 = _FRAME_NUM;
    	//if(_SEC_TICK == 10){ 	_Frame_Rate2 = _FRAME_NUM;
    	//if(sec_tick == 9) _Frame_Rate1 = _FRAME_NUM;
    	//if(sec_tick == 10){ 	_Frame_Rate2 = _FRAME_NUM;
    	//rINTMSK |= BIT_TIC; // INT_POST_LCD Disable		
    	//rRTCCON   = 0x0;            //No reset[3], Merge BCD counters[2], BCD clock select XTAL[1], RTC Control disable[0]
       //}					
	//_SEC_TICK = sec_tick;

}

⌨️ 快捷键说明

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