Beispiel #1
0
static void System_Time_Init(void)
{
	/* 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 06:45:00PM, 2011-03-25
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, 45);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, 15);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 3);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 2014);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 30);

	return;
}
Beispiel #2
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);

}
Beispiel #3
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("}");
}
Beispiel #4
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;
}
Beispiel #5
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;
}
/*********************************************************************//**
 * @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;
}
Beispiel #8
0
int main(void) {
	//Variable Declarations
	initSolenoid();										/* initialize solenoid valve */
	TIM_TIMERCFG_Type timerCfg;
	initTimeStruct();
	RTC_TIME_Type* watertime = malloc(sizeof(RTC_TIME_Type));
	uint8 fed = 0;
	uint8 watered = 0;
	watertime->HOUR = 5;
	watertime->MIN = 0;

	//Initialize timer0 for delays
	TIM_ConfigStructInit(TIM_TIMER_MODE, &timerCfg);	/* initialize timer config struct */
	TIM_Init(LPC_TIM0, TIM_TIMER_MODE, &timerCfg);		/* initialize timer0 */

	//Initialize Real Time Clock
	RTC_Init(LPC_RTC);
	RTC_Cmd(LPC_RTC, ENABLE);
	RTC_ResetClockTickCounter(LPC_RTC);

	// Initialize Peripherals
	INIT_SDRAM();										/* initialize SDRAM */
	servoInit();										/* initialize FSR servo motor for panning camera */
	initStepper();										/* initialize stepper motor for dispensing food */
	initFSR();											/* initialize force sensitive resistor circuit for food and water full signals */
	initWiFi(AUTO_CONNECT);								/* initialize WiFi module -- must be attached*/

	audio_initialize();
	audio_reset();
	//audio_test();
	audio_setupMP3();

	int i = 0, retval;
	uint32 length;										/* length variable for photo */
	printf("Entering while loop\n\r");
	//audio_storeVoice();
	// Enter an infinite loop
    while(1) {

    	if(STATE == DISPENSING_FOOD){
    	    printf("Entering food dispense state\n\r");
    	    /* Execute commands to dispense food */
    	    //spinUntilFull();
    	    spinStepper(300);
    	    reverseSpin(250);
    	    STATE = CONNECTED;
    	}

    	if(STATE == DISPENSING_WATER){
    		printf("Entering water dispense state\n\r");
    		/* Execute commands to dispense water */
    		fillWater();
    		STATE = CONNECTED;
    	   	}

    	if(STATE == CAPTURING){
   	 		printf("Entering camera taking state\n\r");
   	 		/* Initialize camera and set it up to take a picture */
   	 		if(cameraInit())
   	 			printf("Camera not initialized!\n\r");
   	 		retval = stopFrame();
   	 		length = getBufferLength();
   	 		printf("length: %i\n\r", length);

   	 		/* Send length to Android application */
   	 		int temp_len = length;
   	 		while(temp_len){
   	 			uart1PutChar(temp_len % 10);
   	 			temp_len = temp_len / 10;
   	 		}

   	 		/* Send photo and finish set up */
   	 		getAndSendPhoto(length);
   	 		resumeFrame();
   	 		STATE = CONNECTED;
  	   	}

   	    if(STATE == TALKING1){
   	    	audio_playVoice(1);
   	    	STATE = CONNECTED;
	    }

   	    if(STATE == TALKING2){
   	    	audio_playVoice(2);
   	    	STATE = CONNECTED;
	    }

   	    if(STATE == TALKING3){
   	    	audio_playVoice(3);
   	    	STATE = CONNECTED;
	    }

   	    if(STATE == PAN_LEFT){
   	    	/* Execute commands to pan servo left */
   	    	panServo(LEFT);
       		STATE = CONNECTED;
   	    }

   	    if(STATE == PAN_RIGHT){
   	    	/* Execute commands to pan servo right */
   	    	panServo(RIGHT);
       		STATE = CONNECTED;
   	    }

   	    if(STATE == SCHEDULING){
       		/* Execute commands to schedule a feeding time */
       		STATE = CONNECTED;
   	    }

   	    /* Scheduling */
   	    RTC_GetFullTime(LPC_RTC, time);
   	    //Fill water bowl at predetermined time
   	    if (time->HOUR == watertime->HOUR + 1 && watered == 1)
   	    	watered = 0;
   	    if (watertime->HOUR == time->HOUR && watertime->MIN < time->MIN && watered == 0)
   	    {
   	    	fillWater();
   	    	watered = 1;
   	    }
   	    //Feed dog on schedule if any cannot feed dog two consecutive hours
   	    for(i = 0; i < scheduled_feeds; i++)
   	    {
			if (time->HOUR == feedtime[i]->HOUR + 1 && fed == 1)
				fed = 0;
			if (feedtime[i]->HOUR == time->HOUR && feedtime[i]->MIN < time->MIN && fed == 0)
			{
				spinUntilFull();
				fed = 1;
			}
   	    }
    }
    return 0;
}