Example #1
0
struct tm *Cyassl_MDK_gmtime(const time_t *c) 
{ 
    static struct tm date ; 

  	RTC_TIME_Type RTCFullTime;
	  RTC_GetFullTime (LPC_RTC, &RTCFullTime);

    date.tm_year = RTCFullTime.YEAR + 100 ;
    date.tm_mon = RTCFullTime.MONTH - 1 ;
    date.tm_mday = RTCFullTime.DOM ;
    date.tm_hour = RTCFullTime.HOUR ;
    date.tm_min = RTCFullTime.MIN ;
    date.tm_sec = RTCFullTime.SEC ;

    #if defined(DEBUG_CYASSL) 
    {
			  extern void CYASSL_MSG(char *msg) ;
        char msg[100] ;
        sprintf(msg, "Debug::Cyassl_KEIL_gmtime(DATE=/%4d/%02d/%02d TIME=%02d:%02d:%02d)\n",
        RTCFullTime.YEAR+2000,  RTCFullTime.MONTH, RTCFullTime.DOM,
        RTCFullTime.HOUR,  RTCFullTime.MIN,  RTCFullTime.SEC) ; 
        CYASSL_MSG(msg) ;   
    }
    #endif
    
    return(&date) ;
}
Example #2
0
extern "C" DWORD get_fattime()
{
	RTC_TIME_Type time;
	RTC_GetFullTime(LPC_RTC, &time);
	
	DWORD fattime = 0;
	fattime += ((time.YEAR - 1980) & 0x7f) << 25;
	fattime += time.MONTH << 21;
	fattime += time.DOM << 16;
	fattime += time.HOUR << 11;
	fattime += time.MIN << 5;
	fattime += time.SEC / 2;
	return fattime;
}
Example #3
0
void time_main(void *args) 
{
    char * datetime ;
	  int year ;
  	RTC_TIME_Type RTCFullTime;

    if( args == NULL || ((func_args *)args)->argc == 1) {  
		    RTC_GetFullTime (LPC_RTC, &RTCFullTime);
        printf("Date: %d/%d/%d, Time: %02d:%02d:%02d\n", 
             RTCFullTime.MONTH, RTCFullTime.DOM, RTCFullTime.YEAR+2000,  
             RTCFullTime.HOUR,  RTCFullTime.MIN,  RTCFullTime.SEC) ;              
    } else if(((func_args *)args)->argc == 3 && 
              ((func_args *)args)->argv[1][0] == '-' && 
              ((func_args *)args)->argv[1][1] == 'd' ) {

								datetime = ((func_args *)args)->argv[2];
        sscanf(datetime, "%d/%d/%d", 
             (int *)&RTCFullTime.MONTH, (int *)&RTCFullTime.DOM, &year) ;
        RTCFullTime.YEAR = year - 2000 ;   
				RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, RTCFullTime.MONTH);
        RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, RTCFullTime.YEAR);
        RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, RTCFullTime.DOM);       
    } else if(((func_args *)args)->argc == 3 && 
              ((func_args *)args)->argv[1][0] == '-' && 
              ((func_args *)args)->argv[1][1] == 't' ) {
		    RTC_GetFullTime (LPC_RTC, &RTCFullTime);
								datetime = ((func_args *)args)->argv[2];
        sscanf(datetime, "%d:%d:%d",            
            (int *)&RTCFullTime.HOUR, 
            (int *)&RTCFullTime.MIN, 
            (int *)&RTCFullTime.SEC
        ) ;
        RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, RTCFullTime.SEC);
        RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, RTCFullTime.MIN);
        RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, RTCFullTime.HOUR);
    } else printf("Invalid argument\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;
}
Example #5
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;
}
Example #6
0
static rt_err_t rt_rtc_control(rt_device_t dev, rt_uint8_t cmd, void *args)
{
    time_t *time;
    RTC_TIME_Type   RTC_TimeStructure;
	  
    struct tm time_temp;

    RT_ASSERT(dev != RT_NULL);
    memset(&time_temp, 0, sizeof(struct tm));

    switch (cmd)
    {
    case RT_DEVICE_CTRL_RTC_GET_TIME:
        time = (time_t *)args;

        /* Get the current Time */
		    RTC_GetFullTime(LPC_RTC,&RTC_TimeStructure);
        /* Years since 1900 : 0-99 range */
        time_temp.tm_year = RTC_TimeStructure.YEAR + 2000 - 1900;
        /* Months *since* january 0-11 : RTC_Month_Date_Definitions 1 - 12 */
        time_temp.tm_mon = RTC_TimeStructure.MONTH - 1;
        /* Day of the month 1-31 : 1-31 range */
        time_temp.tm_mday = RTC_TimeStructure.DOM;
        /* Hours since midnight 0-23 : 0-23 range */
        time_temp.tm_hour = RTC_TimeStructure.HOUR;
        /* Minutes 0-59 : the 0-59 range */
        time_temp.tm_min = RTC_TimeStructure.MIN;
        /* Seconds 0-59 : the 0-59 range */
        time_temp.tm_sec = RTC_TimeStructure.SEC;

        *time = mktime(&time_temp);
        break;

    case RT_DEVICE_CTRL_RTC_SET_TIME:
    {
        const struct tm* time_new;
        time = (time_t *)args;
        time_new = localtime(time);

        /* 0-99 range              : Years since 1900 */
        RTC_TimeStructure.YEAR = time_new->tm_year + 1900 - 2000;
        /* RTC_Month_Date_Definitions 1 - 12 : Months *since* january 0-11 */
        RTC_TimeStructure.MONTH = time_new->tm_mon + 1;
        /* 1-31 range : Day of the month 1-31 */
        RTC_TimeStructure.DOM = time_new->tm_mday;
        /* 1 - 7 : Days since Sunday (0-6) */
        RTC_TimeStructure.DOW = time_new->tm_wday + 1;
        /* 0-23 range : Hours since midnight 0-23 */
        RTC_TimeStructure.HOUR = time_new->tm_hour;
        /* the 0-59 range : Minutes 0-59 */
        RTC_TimeStructure.MIN = time_new->tm_min;
        /* the 0-59 range : Seconds 0-59 */
        RTC_TimeStructure.SEC = time_new->tm_sec;

        /* Set Current Time and Date */
				RTC_SetFullTime(LPC_RTC,&RTC_TimeStructure);
				RTC_WriteGPREG(LPC_RTC,0,FIRST_DATA);
    }
    break;
    }

    return RT_EOK;
}