Exemplo n.º 1
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;
}
Exemplo n.º 2
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;
        }
    }
}