Пример #1
0
int main(void){
  //while(1);
  wdt_disable();
  
  ///Configure the Torquer
  configure_torquer();
  char buf[100];
  uint16_t v;
    
  int ao;
  for(ao=0;ao<1;ao++) 
  _delay_ms(1000);  
    
  /// Initialise Interfaces - UART of Magnetometer and GPS and the SPI bus
  init_UART_MM();
  init_UART_GPS();
  init_SPI();
  init_TWI();
  
  send_preflight("Master\r", 7);
  
  ///Set Preflight pin as input
  cbi(DDR_PF, PIN_PF);
  
  ///* Switch on Global interrupts
  sei();
  
  ///Check if Preflight Pin is high
  while(1){
    
    ///* * Reset timer for 2 seconds
    timer_reset_two_sec();
    //get_HM_data();
    //send_preflight("Power\r", 6);
    
    
    ///* Preflight Checks
    if(0){
      ///* * Set the mode as preflight
      Mode = PREFLIGHT;
      /*slave_send(HM_DATA, "Hello", 5);
      _delay_ms(10);
      
      slave_send (BEGIN_TX_GS, NULL, 0);
      
      //power_up_peripheral(PCC);
      _delay_ms(10);
      
      ao = init_CC1020();
      
      if(ao) 
        send_preflight("CC Init\r", 8);
      else
        send_preflight("No Init\r", 8);
      while(1);*/
      /*power_up_peripheral(PGPS);
      while(1) {
        read_GPS();
      while(UCSR0B & _BV(RXCIE0));
      copy_gps_reading();
      sprintf(buf,"%ld %ld %ld\r", Current_state.gps.x/1000, Current_state.gps.y/1000, Current_state.gps.z/1000);
      
      send_preflight(buf, strlen(buf));
      sprintf(buf,"%ld %ld %ld\r", Current_state.gps.v_x/1000, Current_state.gps.v_y/1000, Current_state.gps.v_z/1000);
      
      send_preflight(buf, strlen(buf));
      _delay_ms(1000);
      }*/
      ///* * Magnetometer and Torquer test

	  ///* * Reading with one torquer on at once
      /*Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 10000;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 30000;
      Current_state.pwm.z_dir = 1;
      Current_state.pwm.z = 20000;
      send_preflight("Read\r", 5);
      set_PWM();*/
      while(1) {
        read_SS();
        //send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading));
        for(v = 0; v < 6; v++)
        {
          sprintf(buf,"%u\r", (uint16_t)(((float)Current_state.ss.reading[v])*1.6*100/4096));
          send_preflight(buf, strlen(buf));
          sprintf(buf,"%x\r", Current_state.ss.reading[v]);
          send_preflight(buf, strlen(buf));
          
      }
      _delay_ms(1000);
    }
	  ///* * Set Torquer values to zero
      reset_PWM();
      while(1)
        read_MM();

      read_GPS();
      send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading));
      
      ///* * Sunsensor test
      read_SS();
      send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading));

      ///* Health Montoring
      get_HM_data();
      send_preflight((char *)&Current_state.hm, sizeof(struct HM_data));
	  
      ///Communication Task
      comm();
	  
	  ///* * Wait for 2 seconds to get over
      timer_wait_reset();
    }

  ///Normal Mode
  
    else{
    
      ///* Set default mode of Satellite
      Mode = DETUMBLING;
      
      ///* initialise Timer
      Time = 0;
      
      ///Loop begins
      while(1){
        //Fuses Pain, Nominal Mode checking
        send_preflight("Loop\r", 5);
        control();
        send_preflight("Control\r", 8);
        //power();
        comm();
        send_preflight("Comm\r", 5);
        v = StackCount();
        sprintf(buf, "Stack = %d\r", v);
        send_preflight(buf, strlen(buf));
        v = get_free_memory();
        sprintf(buf, "Stack(Method 2) = %d\r", v);
        send_preflight(buf, strlen(buf));
        Time += FRAME_TIME;
        timer_wait_reset();
      }
    }
  }
  return 0;
}
Пример #2
0
int main(void){
  
  ///Configure the Torquer
  configure_torquer();
    
  _delay_ms(1000);  
  
  /// Initialise Interfaces - UART of Magnetometer and GPS and the SPI bus
  init_UART_MM();
  init_UART_GPS();
  init_SPI();
  init_TWI();
  
  ///Set Preflight pin as input
  cbi(DDR_PF, PIN_PF);
  
  ///* Switch on Global interrupts
  sei();
  
  ///Check if Preflight Pin is high
  while(1){
    
    ///* * Reset timer for 2 seconds
    timer_reset_two_sec();
    
    ///* Get Health Monitoring data
    get_HM_data();
    
    ///* Preflight Checks
    if(PORT_PF & _BV(PIN_PF)){
      ///* * Set the mode as preflight
      Mode = PREFLIGHT;
      
      
      send_preflight("Master\r", 7);
      
      ///* * GPS test
      read_GPS();
      while(UCSR0B & _BV(RXCIE0));
      send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading));

      ///* * Magnetometer and Torquer test

      ///* * Reading with no torquers on
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
      
	  ///* * Reading with one torquer on at once
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 32768;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 0;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 0;
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
  
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 0;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 32768;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 0;
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
      
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 0;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 0;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 32768;  
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));

	  ///* * Reading with one torquer on at once, in other direction
      Current_state.pwm.x_dir = 1;
      Current_state.pwm.x = 32768;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 0;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 0;
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
  
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 0;
      Current_state.pwm.y_dir = 1;
      Current_state.pwm.y = 32768;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 0;
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
      
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 0;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 0;
      Current_state.pwm.z_dir = 1;
      Current_state.pwm.z = 32768;  
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
	  
	  ///* * Set Torquer values to zero
      reset_PWM();


      ///* * Sunsensor test
      read_SS();
      send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading));

      ///* Health Montoring
      get_HM_data();
      send_preflight((char *)&Current_state.hm, sizeof(struct HM_data));
	  
      ///Communication Task
      comm();
	  
	  ///* * Wait for 2 seconds to get over
      timer_wait_reset();
    }

  ///Normal Mode
  
  else{
    
    ///* Set default mode of Satellite
    Mode = DETUMBLING;
    
    ///* initialise Timer
    Time = 0;
	 
    ///Loop begins
    while(!(PORT_PF & _BV(PIN_PF))){
      
      
  
      /**
      * * * * Task 2: Control codes
       * @ref control
       */
    
      
      control();
      
      /**
      * * * * Task 1: Communication with power uC through I2C. @ref power
      */
      power();

      

      /**
      * * * * Task 3: Communication check routine;
      * @ref comm
      */
      comm();
      
      wdt_disable();
      
      ///* * Increment the Timer
      Time += FRAME_TIME;
      
      ///* * Wait for 2 seconds to get over
      timer_wait_reset();
      
      }
    }
  }
  return 0;
}
Пример #3
0
int main(void)
{
	char array[40];
	char array1[40];
	char array2[40];
	
	DDRA = 0xF0;
	PORTA = 0xF0;
	_delay_ms(1000);
	PORTA = 0x00;
	_delay_ms(1000);
	PORTA = 0xF0;
	_delay_ms(1000);
	PORTA = 0x00;
	_delay_ms(1000);
	
	init_UART0();
  
	transmit_UART0('\r');
	transmit_UART0('\r');
	transmit_UART0('H');
	transmit_UART0('e');
	transmit_UART0('l');
	transmit_UART0('l');
	transmit_UART0('o');
	
	sprintf(array,"\t..This is IITB's Student Satellite...\r");
	transmit_string_UART0(array);

	sprintf(array1,"\tThis is HUSSAIN's OBC-Master code...");
	sprintf(array2,"\rCurrent GPS state is =\t");
		
/************************************************************/
	init_UART_GPS();
	
	///* Switch on Global interrupts
	sei();
  
    //uint8_t GPS_data[159];
    uint8_t temp;
/************************************************************/
	while(1)
    {
        
        while (!(UCSR0A & _BV(RXC0)));
        temp =  UDR0;
        transmit_UART0('A');

        
        
//        for (i=0;i<159;i++)
//        {
//            GPS_data[i] = receive_GPS();
//            
//        }
//        
//        for(i=0;i<4;i++)
//        {
//            temp = temp >> 8;
//            temp &= 0x00FFFFFF;
//            temp |= ((uint32_t) GPS_data[i])<<24;
//            
//        }
//        sprintf(array,"x = %lu \n",temp);
//        transmit_string_UART0(array);
        
        
    //process_GPS();
    //	read_GPS();
    //while(UCSR0B & _BV(RXCIE0));
    
//	send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading));
//	sprintf(array,"x = %lu \n",Current_state.gps.x);
//    transmit_string_UART0(array);
//        
//	sprintf(array,"y = %lu \n",Current_state.gps.y);
//    transmit_string_UART0(array);
//        
//	sprintf(array,"z = %lu \n",Current_state.gps.z);
//    transmit_string_UART0(array);

//	sprintf(array,"x = %x\n",Current_state.gps.x);transmit_string_UART0(array);
//	sprintf(array,"y = %x\n",Current_state.gps.y);transmit_string_UART0(array);
//	sprintf(array,"z = %x\n",Current_state.gps.z);transmit_string_UART0(array);	
	
//    sprintf(array,"%lu ",Current_state.gps.v_x);
//    transmit_string_UART0(array);
//        
//	sprintf(array,"%lu ",Current_state.gps.v_y);
//    transmit_string_UART0(array);
//        
//	sprintf(array,"%lu ",Current_state.gps.v_z);
//    transmit_string_UART0(array);
	
/************************************************************/
	}
	return 0;
}
Пример #4
0
int main(void) {
  
  init_UART_GPS();
  send_preflight("Slave", 5);
  
   /// Current state of satellite
  uint8_t frame[256];
  uint8_t transmission = 0, command;
  uint16_t crc, recv_crc;
  
  
  ///Disable Watchdog Timer
  wdt_disable();
  ///Initialise SPI as slave
  init_SPI_slave();
  
  ///EEPROM function to initialise I/O
  //ioinit();
  
  ///Initialise CC1020 DIO pins
  //cc1020_init_dio();
  
  ///Enable Global Interrupts
  sei();
  
  ///Main Loop for slave
  while (1)
  {
    if(process)
    {
      crc = calculate_crc_16((uint8_t *)message, t - (end_spi + sizeof(uint16_t)));
      memcpy((void *)&recv_crc, (void *)&(message[t - (end_spi + sizeof(uint16_t))]), sizeof(uint16_t));
      if(crc == recv_crc)
      {
        command = message[0];
        if(command == BEGIN_TX_COMM)
        {
          //transmission = IN;
          send_preflight("Recvcomm", 8);
          send_preflight((char *)message + 2, message[1]);
        }
        else if(command == BEGIN_TX_GS)
          transmission = GS;
        else if(command == END_TX)
        {
          SPI_transfer(ACK);
          transmission = 0;
        }
        else if(command == HM_DATA)
        {
          make_ax25_frame_from_data(frame, (uint8_t *)message + 2);
          write_frame_to_eeprom(frame);
        }
        else if(command == REAL_TIME)
          make_ax25_frame_from_data(frame, (uint8_t *)message + 2);
      }
      end_spi = 0;
      start_spi = 0;
      t = 0;
      process = 0;
    }
    
    if(transmission == GS)
    {
      read_frame_from_eeprom(frame);
      if(read_addr == write_addr)
        read_addr -= FRAME_SIZE;
        
      cc1020_transmit_packet(frame, FRAME_SIZE);
    }
    else if(transmission == IN)
      cc1020_transmit_packet(frame, FRAME_SIZE);
  }
  return 0;
}