예제 #1
0
void RTC_time_Init(void){
//	_DBG("{");
	// Init RTC module
	RTC_Init(LPC_RTC);
	// Disable RTC interrupt
    NVIC_DisableIRQ(RTC_IRQn);
    NVIC_SetPriority(RTC_IRQn, 8); // set according to main.c
	RTC_Cmd(LPC_RTC, ENABLE);
	update_time();
//	RTC_CalibCounterCmd(LPC_RTC, DISABLE);

//	RTC_WriteGPREG(LPC_RTC, 4, 0x55);//force clock set

    //Set time if no data in GPREG
    if (!(RTC_ReadGPREG(LPC_RTC, 4)==(0xaa)))
    {
//    	xprintf(INFO "Setting time to" " (%s:%d)\n",_F_,_L_);//_DBG("[INFO]-Set time");_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");
    	xprintf(INFO "Setting time to %s %s" " (%s:%d)\n",__DATE__,__TIME__,_F_,_L_);//_DBG("[INFO]-Set time");_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");
//    	delay_ms(1000);
//    	_DBG("[INFO]-__DATE__=");_DBG(__DATE__);_DBG(", __TIME__=");_DBG(__TIME__);_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");
		// Enable rtc (starts increase the tick counter and second counter register)
		RTC_ResetClockTickCounter(LPC_RTC);
		//				 yyyy  mm  dd  Dom Dow  ss  mm  hh  st
//		RTC_time_SetTime(2012,  6, 11, 1,  163, 10, 50, 20, 00);
		RTC_set_default_time_to_compiled();
		RTC_WriteGPREG(LPC_RTC, 4, 0xaa);
    }
///*
	yearlyCheck();
	weeklyCheck();
	dailyCheck();
	hourlyCheck();
	minutelyCheck();
	secondlyCheck();
	RTC_print_time();
//*/

//	time_t seconds;

//	  seconds = time (NULL);
//	uint8_t test[56];
//	  xprintf ("{testing} %ld hours since January 1, 1970\r\n", Getunix());
//	  scanf (test);

    // Enable 1 sec interrupt
	RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
    // Enable RTC interrupt
    NVIC_EnableIRQ(RTC_IRQn);
//    _DBG(".");
//    _DBG("}");
}
예제 #2
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* In this example:
	 * Suppose that the RTC need periodically adjust after each 5 second.
	 * And the time counter need by incrementing the counter by 2 instead of 1
	 * We will observe timer counter after calibration via serial display
	 */
	// Init RTC module
	RTC_Init(LPC_RTC);

	/* Enable rtc (starts increase the tick counter and second counter register) */
	RTC_ResetClockTickCounter(LPC_RTC);
	RTC_Cmd(LPC_RTC, ENABLE);

	//Set current time = 0
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);

	/* Setting Timer calibration
	 * Calibration value =  5s;
	 * Direction = Forward calibration
	 * So after each 5s, calibration logic can periodically adjust the time counter by
	 * incrementing the counter by 2 instead of 1
	 */
	RTC_CalibConfig(LPC_RTC, 5, RTC_CALIB_DIR_FORWARD);
	RTC_CalibCounterCmd(LPC_RTC, ENABLE);

	/* Set the CIIR for second counter interrupt*/
	RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);

    /* Enable RTC interrupt */
    NVIC_EnableIRQ(RTC_IRQn);

    /* Loop forever */
    while(1);
    return 1;
}
예제 #3
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* Initialize and configure RTC */
	RTC_Init(LPC_RTC);

	RTC_ResetClockTickCounter(LPC_RTC);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);

	/* Set alarm time = 5s.
	 * So, after each 5s, RTC will generate and wake-up system
	 * out of Deep PowerDown mode.
	 */
	RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 5);

	RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, DISABLE);
	/* Set the AMR for 5s match alarm interrupt */
	RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
	RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM);

	_DBG_("Press '1' to enter system in Deep PowerDown mode");
	while(_DG !='1');

	RTC_Cmd(LPC_RTC, ENABLE);
	NVIC_EnableIRQ(RTC_IRQn);

	_DBG_("Enter Deep PowerDown mode...");
	_DBG_("Wait 5s, RTC will wake-up system...\n\r");

	// Enter target power down mode
	CLKPWR_DeepPowerDown();

	while(1);
	return 1;
}
// Inicializa módulo RTC
void rtc_init(void) {

	RTC_Init(LPC_RTC);
	CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCRTC, ENABLE);

	// Configura RTC para interrumpir cada 1 segundo
	RTC_CntIncrIntConfig(LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);

	// Limpia las interrupciones del RTC
	RTC_ClearIntPending(LPC_RTC, RTC_INT_COUNTER_INCREASE);

	// Habilita las interrupciones del RTC en NVIC
	NVIC_EnableIRQ((IRQn_Type) RTC_IRQn);

	// Habilita el módulo RTC --> comienza a contar el tiempo
	RTC_Cmd(LPC_RTC, ENABLE);

	NVIC_SetPriority((IRQn_Type) RTC_IRQn, 6);
}
예제 #5
0
static void init_RTC() 
{	
		/* Enable GPIO register interface clock                                     */
		LPC_CCU1->CLK_M4_GPIO_CFG     |= 1;
		while (!(LPC_CCU1->CLK_M4_GPIO_STAT   & 1)) ;
	
    /* RTC Block section ------------------------------------------------------ */
    /* Init RTC module */
    RTC_Init(LPC_RTC);

    /* Set ALARM time for second */
    RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 30);

    /* Set the AMR for 30s match alarm interrupt */
    RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);

    /* Set the CIIR for minute counter interrupt*/
    RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_MINUTE, ENABLE);

    /* Enable rtc (starts increase the tick counter and second counter register) */
    RTC_Cmd(LPC_RTC, ENABLE);
				
}
예제 #6
0
/*********************************************************************//**
 * @brief       c_entry: Main program body
 * @param[in]   None
 * @return      None
 **********************************************************************/
void c_entry (void)
{
    uint32_t pre_secval = 0, inc = 0, calib_cnt = 0;
    /* Initialize debug via UART0
     * – 115200bps
     * – 8 data bit
     * – No parity
     * – 1 stop bit
     * – No flow control
     */
    debug_frmwrk_init();

    // print welcome screen
    print_menu();

    /* In this example:
     * Suppose that the RTC need periodically adjust after each 5 second.
     * And the time counter need by incrementing the counter by 2 instead of 1
     * We will observe timer counter after calibration via serial display
     */
    // Init RTC module
    RTC_Init(LPC_RTC);

    /* Enable rtc (starts increase the tick counter and second counter register) */
    RTC_ResetClockTickCounter(LPC_RTC);
    RTC_Cmd(LPC_RTC, ENABLE);

    //Set current time = 0
    RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);

    /* Setting Timer calibration
     * Calibration value =  6s;
     * Direction = Forward calibration
     * So after each 6s, calibration logic can periodically adjust the time counter by
     * incrementing the counter by 2 instead of 1
     */
    RTC_CalibConfig(LPC_RTC, 6, RTC_CALIB_DIR_FORWARD);
    RTC_CalibCounterCmd(LPC_RTC, ENABLE);

    /* Set the CIIR for second counter interrupt*/
    RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);

    /* Enable RTC interrupt */
    NVIC_EnableIRQ(RTC_IRQn);

    /* Loop forever */
    while(1)
    {
        if(pre_secval != secval)
        {   
            if(pre_secval > secval)
                inc = 60 + secval - pre_secval;
            else
                inc = secval - pre_secval; 
            if(inc > 1)
            {
               _DBG ("Second: "); _DBD(secval); _DBG("--> Increase ");_DBD(inc); _DBG(" after ");_DBD(calib_cnt);_DBG(" seconds");
                _DBG_(""); 
                calib_cnt = 0;
            }   
            else
            {
                _DBG ("Second: "); _DBD(secval);  _DBG_(""); 
                calib_cnt++;
            }
            pre_secval = secval;
        }
    }
}
/*********************************************************************//**
 * @brief		c_entry: Main RTC program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	RTC_TIME_Type RTCFullTime;

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* RTC Block section ------------------------------------------------------ */
	// Init RTC module
	RTC_Init(LPC_RTC);

    /* Disable RTC interrupt */
    NVIC_DisableIRQ(RTC_IRQn);
    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(RTC_IRQn, ((0x01<<3)|0x01));

	/* Enable rtc (starts increase the tick counter and second counter register) */
	RTC_ResetClockTickCounter(LPC_RTC);
	RTC_Cmd(LPC_RTC, ENABLE);
	RTC_CalibCounterCmd(LPC_RTC, DISABLE);

	/* Set current time for RTC */
	// Current time is 8:00:00PM, 2009-04-24
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, 20);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 4);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 2009);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 24);

	/* Set ALARM time for second */
	RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 10);

	// Get and print current time
	RTC_GetFullTime (LPC_RTC, &RTCFullTime);
	_DBG( "Current time set to: ");
	_DBD((RTCFullTime.HOUR)); _DBG (":");
	_DBD ((RTCFullTime.MIN)); _DBG (":");
	_DBD ((RTCFullTime.SEC)); _DBG("  ");
	_DBD ((RTCFullTime.DOM)); _DBG("/");
	_DBD ((RTCFullTime.MONTH)); _DBG("/");
	_DBD16 ((RTCFullTime.YEAR)); _DBG_("");

	_DBG("Second ALARM set to ");
	_DBD (RTC_GetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND));
	_DBG_("s");

	/* Set the CIIR for second counter interrupt*/
	RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
	/* Set the AMR for 10s match alarm interrupt */
	RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);

    /* Enable RTC interrupt */
    NVIC_EnableIRQ(RTC_IRQn);

    /* Loop forever */
    while(1);
    return 1;
}