Exemple #1
0
void debug_output(SensorPair sensor) {
  if (DBG_LEVEL >= 2) {
    _DBG_("##################");
    if(sensorSide == 1) {
        _DBG("Left Front:");_DBD16(sensor.FrontSensor);_DBG_("");
        _DBG("Left Rear:");_DBD16(sensor.RearSensor);_DBG_("");
     }
     else if (sensorSide == 2) {
      _DBG("Right Front:");_DBD16(sensor.FrontSensor);_DBG_("");
      _DBG("Right Rear:");_DBD16(sensor.RearSensor);_DBG_("");
    }
  }
}
Exemple #2
0
void exec_loop(void)
{
#if 0
	uint16_t i = 0;
	while(1)
	{
		while(!g_run)
			chirpService();

		setup0();
		while(g_run)
		{
			loop0();
			i++;
			if (i%50==0)
			{
				_DBD16(i); _DBG("\n");
			}
		}
		// set variable to indicate we've stopped
		g_running = 0;
	}
#endif
#if 1
	while(1)
	{
		while(!g_run)
			chirpService();
		 	
		setup0();
		while(g_run)
		{
			loop0();
			chirpService();
		}
		// set variable to indicate we've stopped
		g_running = 0;
	}
#endif
}
Exemple #3
0
void RTC_print_time(void){
	char buffer[100];
    time_t rawtime;
    struct tm * timeinfo;


//	xprintf(INFO "%d/%d/%d %d:%d:%d" " (%s:%d)\n",GetDOM(),GetM(),GetY(),GetHH(),GetMM(),GetSS(),_F_,_L_);
	time( &rawtime );
    timeinfo = localtime ( &rawtime );
	strftime(buffer,90,"%d/%m/%Y %I:%M:%S%p WOY:%U DOY:%j",timeinfo);
	xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_);
//	xprintf(INFO "%d/%d/%d %d:%d:%d" " (%s:%d)\n",_F_,_L_);
//	xprintf(INFO "Unix: %d" " (%s:%d)\n",time2.unix,_F_,_L_);

//	xprintf(INFO "Sunrise: %d" " (%s:%d)\n",time2.sunrise_unix,_F_,_L_);
	timeinfo = localtime ( &time2.sunrise_unix );
	strftime(buffer,80,"Sunrise: %I:%M:%S%p.",timeinfo);
	xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_);

//	xprintf(INFO "Sunset: %d" " (%s:%d)\n",time2.sunset_unix,_F_,_L_);
	timeinfo = localtime ( &time2.sunset_unix );
	strftime(buffer,80,"Sunset: %I:%M:%S%p.",timeinfo);
	xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_);

//	xprintf(INFO "Noon: %d" " (%s:%d)\n",time2.noon_unix,_F_,_L_);
	timeinfo = localtime ( &time2.noon_unix );
	strftime(buffer,80,"Noon: %I:%M:%S%p.",timeinfo);
	xprintf(INFO "%s" " (%s:%d)\n", buffer,_F_,_L_);

	xprintf(INFO "It's %s" " (%s:%d)\n",time2.day_night ? "Night time" : "Day time" ,_F_,_L_);
//	xprintf(INFO "Day/Night: %d" " (%s:%d)\n",time2.day_night,_F_,_L_);
	xprintf(INFO "DST begin: %d end: %d" " (%s:%d)\n",time2.DST_begin_calculated,time2.DST_end_calculated,_F_,_L_);


#if 0
	_DBG("[INFO]-Date=");
	_DBD(GetDOM());
	_DBG("/");
	_DBD(GetM());
	_DBG("/");
	_DBD16(GetY());
	_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");

	_DBG("[INFO]-Time=");
	_DBD(GetHH());
	_DBG(":");
	_DBD(GetMM());
	_DBG(":");
	_DBD(GetSS());
	_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");

	_DBG("[INFO]-Unix: ");
	_DBD32(time2.unix);
	_DBG("  Sunrise: ");
	_DBD32(time2.sunrise_unix);
	_DBG("  Sunset: ");
	_DBD32(time2.sunset_unix);
	_DBG("  Noon: ");
	_DBD32(time2.noon_unix);
	_DBG("  Day/Night: ");
	_DBD(time2.day_night);
	_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");

	_DBG("[INFO]-DST begin: ");
	_DBD32(time2.DST_begin_calculated);
	_DBG("  end: ");
	_DBD32(time2.DST_end_calculated);
	_DBG(" (");_DBG(__FILE__);_DBG(":");_DBD16(__LINE__);_DBG(")\r\n");
#endif
}
/*********************************************************************//**
 * @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;
}
Exemple #5
0
/*********************************************************************//**
 * @brief		c_entry: Main TIMER program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
	TIM_TIMERCFG_Type TIM_ConfigStruct;
	TIM_MATCHCFG_Type TIM_MatchConfigStruct;
	uint8_t idx;
	uint16_t tem;
	uint32_t freq1, freq2;

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

	// print welcome screen
	print_menu();
	while(1)
	{
		// Select frequency for channel1 (MAT0.0)
		idx=0;freq1=0;tem=0;
		while(idx<3)
		{
			if(idx==0)
			_DBG("\n\rPlease input frequency for channel1 (from 1 to 999 hz):");
			tem = _DG;
			switch(tem)
			{
			case '0':case'1':case '2':case '3':case '4':case '5':case '6':case '7':case'8':case '9':
				tem = tem - 0x30;
				idx++;
				if(idx==1) tem = tem * 100;
				else if (idx==2) tem = tem * 10;
				freq1 = freq1 + tem;
				if(idx==3)_DBD16(freq1);
				tem = 0;
				break;
			default:
				_DBG("...Please input digits from 0 to 9 only!");
				idx = 0; tem = 0; freq1 = 0;
				break;
			}
		}
		idx=0;freq2=0;tem=0;
		while(idx<3)
		{
			if(idx==0)
			_DBG("\n\rPlease input frequency for channel2 (from 1 to 999 hz):");
			tem = _DG;
			switch(tem)
			{
			case '0':case'1':case '2':case '3':case '4':case '5':case '6':case '7':case'8':case '9':
				tem = tem - 0x30;
				idx++;
				if(idx==1) tem = tem * 100;
				else if (idx==2) tem = tem * 10;
				freq2 = freq2 + tem;
				if(idx==3)_DBD16(freq2);
				tem = 0;
				break;
			default:
				_DBG("...Please input digits from 0 to 9 only!");
				idx = 0; tem = 0; freq2 = 0;
				break;
			}
		}
		// Configure P1.28 as MAT0.0
		PinCfg.Funcnum = 3;
		PinCfg.OpenDrain = 0;
		PinCfg.Pinmode = 0;
		PinCfg.Portnum = 1;
		PinCfg.Pinnum = 28;
		PINSEL_ConfigPin(&PinCfg);
		// Configure P0.6 as MAT2.0
		PinCfg.Funcnum = 3;
		PinCfg.OpenDrain = 0;
		PinCfg.Pinmode = 0;
		PinCfg.Portnum = 0;
		PinCfg.Pinnum = 6;
		PINSEL_ConfigPin(&PinCfg);

		// Initialize timer, prescale count time of 1uS
		TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
		TIM_ConfigStruct.PrescaleValue	= 1;
		TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
		TIM_Init(LPC_TIM2, TIM_TIMER_MODE,&TIM_ConfigStruct);

		// use channel 0, MR0
		TIM_MatchConfigStruct.MatchChannel = 0;
		// Disable interrupt when MR0 matches the value in TC register
		TIM_MatchConfigStruct.IntOnMatch   = FALSE;
		//Enable reset on MR0: TIMER will reset if MR0 matches it
		TIM_MatchConfigStruct.ResetOnMatch = TRUE;
		//Stop on MR0 if MR0 matches it
		TIM_MatchConfigStruct.StopOnMatch  = FALSE;
		//Toggle MR0.0 pin if MR0 matches it
		TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_TOGGLE;
		// Set Match value
		TIM_MatchConfigStruct.MatchValue   = 500000/freq1;
		TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct);

		// Set Match value
		TIM_MatchConfigStruct.MatchValue   = 500000/freq2;
		TIM_ConfigMatch(LPC_TIM2,&TIM_MatchConfigStruct);

		TIM_Cmd(LPC_TIM0,ENABLE);
		TIM_Cmd(LPC_TIM2,ENABLE);
		_DBG("\n\rGenerating two different frequency signals..");
		_DBG("\n\rPress ESC if you want to terminate and choose other frequencies");
		while(_DG!=27);
		TIM_DeInit(LPC_TIM0);
		TIM_DeInit(LPC_TIM2);
	}
	return (1);
}