Пример #1
0
/**********************************************************
                       MAIN
**********************************************************/
int	main (void) {

  static int vbat1; //battery_voltage (lowpass-filtered)

  init();
  buzzer(OFF);
  LL_write_init();
  PTU_init();
  ADC0triggerSampling(1<<VOLTAGE_1); //activate ADC sampling

  HL_Status.up_time=0;

  LED(1,ON);

  while(1)
  {
      if(mainloop_trigger)
      {
     	if(GPS_timeout<ControllerCyclesPerSecond) GPS_timeout++;
	  	else if(GPS_timeout==ControllerCyclesPerSecond)
	  	{
  	 		GPS_timeout=ControllerCyclesPerSecond+1;
	  		GPS_Data.status=0;
	  		GPS_Data.numSV=0;
	  	}

        //battery monitoring
        ADC0getSamplingResults(0xFF,adcChannelValues);
        vbat1=(vbat1*14+(adcChannelValues[VOLTAGE_1]*9872/579))/15;	//voltage in mV

		HL_Status.battery_voltage_1=vbat1;
        mainloop_cnt++;
		if(!(mainloop_cnt%10)) buzzer_handler(HL_Status.battery_voltage_1);

	    if(mainloop_trigger) mainloop_trigger--;
        mainloop();
      }
  }
  return 0;
}
Пример #2
0
/**********************************************************
 MAIN
 **********************************************************/
int main(void)
{

  static int vbat1, vbat2;
  int vbat;
  static int bat_cnt = 0, bat_warning = 1000;
  static char bat_warning_enabled = 1;

#ifdef GPS_BEEP
  static unsigned int gps_beep_cnt;
#endif

  IDISABLE;

  init();
  LL_write_init();
  beeper(OFF);

  HL_Status.up_time = 0;

  printf("\n\nProgramm is running ... \n");
  printf("Processor Clock Frequency: %d Hz\n", processorClockFrequency());
  printf("Peripheral Clock Frequency: %d Hz\n", peripheralClockFrequency());

  IENABLE;

  packetsTemp = packets;

  LED(1, ON);

  GPS_init_status = GPS_STARTUP;
//  GPS_init_status = GPS_NEEDS_CONFIGURATION;

  sdkInit();

  while (1)
  {
    if (mainloop_trigger > 0)
    {

      if (GPS_timeout < ControllerCyclesPerSecond)
        GPS_timeout++;
      else if (GPS_timeout == ControllerCyclesPerSecond)
      {
        GPS_timeout = ControllerCyclesPerSecond + 1;
        GPS_Data.status = 0;
        GPS_Data.numSV = 0;
//        if (GPS_init_status == GPS_STARTUP) //no GPS packet after startup
//        {
          GPS_init_status = GPS_NEEDS_CONFIGURATION;
//        }
      }

      mainloop_cnt++;
      if (++bat_cnt == 100)
        bat_cnt = 0;

      //battery monitoring
      vbat1 = (vbat1 * 29 + (ADC0Read(VOLTAGE_1) * 9872 / 579)) / 30; //voltage in mV //*9872/579

      HL_Status.battery_voltage_1 = vbat1;
      HL_Status.battery_voltage_2 = vbat2;

      vbat = vbat1;

      if (vbat < BATTERY_WARNING_VOLTAGE) //decide if it's really an empty battery
      {
        if (bat_warning < ControllerCyclesPerSecond * 2)
          bat_warning++;
        else
          bat_warning_enabled = 1;
      }
      else
      {
        if (bat_warning > 10)
          bat_warning -= 5;
        else
        {
          bat_warning_enabled = 0;
          beeper(OFF);//IOCLR1 = (1<<17);	//Beeper off
        }
      }
      if (bat_warning_enabled)
      {
        if (bat_cnt > ((vbat - 9000) / BAT_DIV))
          beeper(ON);//IOSET1 = (1<<17);	//Beeper on
        else
          beeper(OFF);//IOCLR1 = (1<<17);		//Beeper off
      }

#ifdef GPS_BEEP
      //GPS_Beep
      if((GPS_Data.status&0xFF)!=3) //no lock

      {
        gps_beep_cnt++;
        if(gps_beep_cnt>=1500) gps_beep_cnt=0;
        if(gps_beep_cnt<20) beeper(ON); //IOSET1 = (1<<17);	//Beeper on

        else if(gps_beep_cnt==40) beeper(OFF);// IOCLR1 = (1<<17); //Beeper off
      }
#endif

      if (mainloop_trigger)
        mainloop_trigger--;
      mainloop();
    }
  }
  return 0;
}
Пример #3
0
/**********************************************************
                       MAIN
**********************************************************/
int	main (void) {

  static int vbat1; //battery_voltage (lowpass-filtered)
  unsigned int TimerT1, TimerT2;

  init();
  buzzer(OFF);
  LL_write_init();

  //initialize AscTec Firefly LED fin on I2C1 (not necessary on AscTec Hummingbird or Pelican)
  I2C1Init();
  I2C1_setRGBLed(255,0,0);

	/* Initialize I2C controller. by Xun */
	I2CInit(I2CMASTER);

  ADC0triggerSampling(1<<VOLTAGE_1); //activate ADC sampling

  generateBuildInfo();

  HL_Status.up_time=0;

  LED(1,ON);

  ACISDK();	//AscTec Communication Interface: publish variables, set callbacks, etc.

  //update parameters stored by ACI:
  //...

  PTU_init();	//initialize camera PanTiltUnit
#ifdef MATLAB
  //ee_read((unsigned int*)&matlab_params); //read params from eeprom
  onboard_matlab_initialize(); //initialize matlab code
#endif

  while(1)
  {
      if(mainloop_trigger)
      {
      	TimerT1 =  T0TC;
     	if(GPS_timeout<ControllerCyclesPerSecond) GPS_timeout++;
	  	else if(GPS_timeout==ControllerCyclesPerSecond)
	  	{
  	 		GPS_timeout=ControllerCyclesPerSecond+1;
	  		GPS_Data.status=0;
	  		GPS_Data.numSV=0;
	  	}

        //battery monitoring
        ADC0getSamplingResults(0xFF,adcChannelValues);
        vbat1=(vbat1*14+(adcChannelValues[VOLTAGE_1]*9872/579))/15;	//voltage in mV

		HL_Status.battery_voltage_1=vbat1;
        mainloop_cnt++;
		if(!(mainloop_cnt%10)) buzzer_handler(HL_Status.battery_voltage_1);

	    if(mainloop_trigger) mainloop_trigger--;
        mainloop();
        // CPU Usage calculation
        TimerT2 = T0TC;
        if (mainloop_trigger)
        {
        	HL_Status.cpu_load = 1000;
        	mainloop_overflows++;
        }
        else if (TimerT2 < TimerT1)
        	HL_Status.cpu_load = (T0MR0 - TimerT1 + TimerT2)*1000/T0MR0; // load = "timer cycles" / "timer cycles per controller cycle" * 1000
        else
        	HL_Status.cpu_load = (TimerT2 - TimerT1)*1000/T0MR0; // load = "timer cycles" / "timer cycles per controller cycle" * 1000
      }

  }
  return 0;
}