Example #1
0
static void setupHardware(void) {
	// Se configuran los perifericos por defecto
	SystemInit();

	// Se inicializa las task de comunicaciones
//	taskPcCommunicationInit();

	semSdCardAccess = xSemaphoreCreateMutex();
	xSemaphoreGive(semSdCardAccess);

	// SD Card
	LPC_GPIO0->FIODIR |= 1<<22;
	LPC_GPIO0->FIOCLR |= 1<<22;

	LPC_SC->PCLKSEL0 &= ~(3<<2);
	LPC_SC->PCLKSEL0 |= 1<<2;

	/*
	 * Default values for the SPI clock
	 * Use 400 kHz during init and 1 MHz during data transfer
	 *
	 * These values are believed to be reasonably safe values.
	 */
	SetSPIClocks(KHZ(400), MHZ(1));

	f_mount(0, &fs);

	LPC_GPIO2->FIODIR |= (1<<0); // red
	LPC_GPIO2->FIODIR |= (1<<1); // green

	LPC_GPIO2->FIOCLR = (1<<0); // red
	LPC_GPIO2->FIOCLR = (1<<1); // green


	RTC_Init(LPC_RTC);

	/* 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, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 12);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 2012);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 19);

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

}
Example #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();

	/* 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;
}
Example #3
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);
				
}
Example #4
0
/*---------------------------------------------------------------------------------------------------------*/
void RTC_AlarmAndWakeupTest(void)
{
    printf("# Set RTC Current Date/Time is: 2012/07/10 13:10:55. \n");
    printf("# Set RTC Alarm Date/Time is:   2012/07/10 13:11:07. \n");
    printf("# System enter to Power Down on RTC Date/Time 2012/07/10 13:10:55; \n");
    printf("                and waken-up on RTC Date/Time 2012/07/10 13:11:07. \n");
    printf("Press any key to start test ... \n\n");
    getchar();

    /* Wait RTC Register Access Enable */
    RTC_WaitAccessEnable();

    /* Set RTC Current Date/Time */
    RTC_SetCurrentCalendar(12, 7, 10);
    RTC_SetCurrentTime(13, 10, 55);
    _RTC_SET_DWR(RTC_DWR_TUESDAY);

    /* Set RTC Alarm Date/Time */
    RTC_SetAlarmCalendar(12, 7, 10);
    RTC_SetAlarmTime(13, 11, 7);

    /* Wait RTC Register Access Enable */
    RTC_WaitAccessEnable();

    /* Check if RTC Current Date/Time are ok except [SEC] data */
    if ((_RTC_GET_YEAR() != 12) || (_RTC_GET_MON() != 7)  || (_RTC_GET_DAY() != 10) ||
        (_RTC_GET_HOUR() != 13)  || (_RTC_GET_MIN() != 10))
    {
        printf("Set RTC Current Date/Time fail. \n\n");
        return ;
    }

    /* Check if RTC current Date/Time are ok */
    if ((_RTC_GET_ALARM_YEAR() != 12) || (_RTC_GET_ALARM_MON() != 7)  || (_RTC_GET_ALARM_DAY() != 10) ||
        (_RTC_GET_ALARM_HOUR() != 13)  || (_RTC_GET_ALARM_MIN() != 11) || (_RTC_GET_ALARM_SEC() != 7))
    {
        printf("Set RTC Alarm Date/Time fail. \n\n");
        return ;
    }

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

    /* Enable RTC Alarm Interrupt */
    _RTC_ALARM_INT_ENABLE();      

    printf("Cunnret Date/Time is 2012/07/10 13:10:55 and system enter to Power Down. \n");    

    g_u8IsRTCAlarmINT = 0;

    /* System enter to Power Down */
    PowerDownFunction();

    while (g_u8IsRTCAlarmINT == 0);

    printf("System waken-up and current Date/Time is %d/%02d/%02d %02d:%02d:%02d. \n",
            (2000+_RTC_GET_YEAR()), _RTC_GET_MON(), _RTC_GET_DAY(), _RTC_GET_HOUR(), _RTC_GET_MIN(), _RTC_GET_SEC());

    /* Disable RTC NVIC */
    NVIC_DisableIRQ(RTC_IRQn);

    /* Disable RTC Alarm Interrupt */
    _RTC_ALARM_INT_DISABLE();

    printf("\n");
}
/*********************************************************************//**
 * @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;
}