Exemple #1
0
void main(void)
{  	
  unsigned int  channel = CHANNEL;
  unsigned char data = 0x07;
  
  // DBGU output configuration
  TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
  
  // Configuration PIT (Periodic Interrupt Timer)
  ConfigurePit();
  // Configuration TC (Timer Counter)
  ConfigureTc();
  // Configuration PIO (Paralell In and Out port), Init Interrupt on PIO
  ConfigureButtons();
  ConfigureLeds();
  // Configuration Radio Module nRF24L (PIO and SPI), ConfigureButtons must be executed before
  ConfigureNRF24L();
  ConfigureUSART0();
  ConfigureUSART1();
  //initialize proximity sensor
  ir_init();
  Global_Variable_Init();
  
  while(Timer0Tick<2); // wait until NRF24L01 power up
  nrf24l01_power_up(True);
  while(Timer0Tick<4); // wait until NRF24L01 stand by
  Timer0Tick = 0;
  //initialize the 24L01 to the debug configuration as RX and auto-ack disabled
  nrf24l01_initialize_debug(True, nrf_TX_RX_SIZE, False);
  nrf24l01_write_register(0x06, &data, 1);
  nrf24l01_set_as_rx(True);
  Delay_US(130);
  nrf24l01_set_rf_ch(channel);
  nrf24l01_flush_rx();
  Delay_US(300);
  
  while (1) { 
    if(Timer0Tick!=0){
      Timer0Tick = 0;
      Check_Battery(0);
      odometry(0);
      ProxRead_m();
      Send_Coord();
      Delay_US(10000);//give time for the coming message
      feedbackController(goalx, goaly, goaldist);      
    }
    Check_Wireless();
  }//while
}//main
Exemple #2
0
void main(void)
{
    char TempVar;

    // variable used for IMU chip Autotest
    unsigned char IMUAutotestResult;

    // structure used to store IMU data
    struct IMUData CurrentIMUData;

    //  variable for CAN TX FIFO buffer
    struct CANTxMsg TempCANTxMsg;

    //  variable for CAN RX FIFO buffer
    struct CANRxMsg TempCANRxMsg;

    
    


    //----------------------------------------------------
    //----------  CPU internal configurations: -----------
    //----------------------------------------------------

    CLRWDT();                                 // clear watchdog timer at startup

    /* Configure the oscillator for the CPU */
    ConfigureOscillator();
    __delay_ms(10);             // wait for Oscillator to be stabilized


    // configure CPU GPIO for IMU board
    ConfigureGPIO();

   
    //USART Initialize();
    ConfigureUSART1();
    ConfigureUSART2();

    
    // SPI initialize
    ConfigureSPI();
    
    //CAN controller Initialize
    ECANInitialize();
    //Set MASK and Filters for CAN
    ECANFiltersInit();

    // Timers configuration
    ConfigureTimers();

    
    //----------------------------------------------------
    //----------  Global variables initialisation --------
    //----------------------------------------------------

    // tick counter initialisation
    TickCounter.AccelTick_ms=0;         
    TickCounter.GyroTick_ms=1;
    TickCounter.MagnetTick_ms=2;

    // initialize CAN tx FIFO
    CANTxFifoInit();
    CANRxFifoInit();

    // initialise USART RX FIFO's
    USARTFifoInit ();


    //----------------------------------------------------
    //------  external peripheral configurations: --------
    //----------------------------------------------------

    __delay_ms(10);              // wait for reset to be released on external peripherals
    
    ISM_RESET = 0;               // release reset of ISM module

    IMUInitRegisters();         // init of BMX055 chip
    IMUAutotestResult=IMUAutotest();              // launch IMU autotest

       
    //----------------------------------------------------
    //----------      GSM startup delay        -----------
    //----------------------------------------------------

    GSM_RTS=1;
    for(char i=0;i<200;i++)
    {
        __delay_ms(10);
        CLRWDT();                                 // clear watchdog timer each loop

    }
    GSM_RTS=0;

    __delay_ms(10);
    __delay_ms(10);


    //----------------------------------------------------
    //----------    Ready to go in main loop:  -----------
    //----------    interrupts activation      -----------
    //----------------------------------------------------
    
    ConfigureInterrupts();

    LED1=1;                     // everything is initialized: enable the PWR/booted LED

    //----------------------------------------------------
    //----------     GSM dummy AT command      -----------
    //----------------------------------------------------

    USART1Write('A');
    USART1Write('T');
    USART1Write(0x0D);

    for(char i=0;i<10;i++)
    {
        __delay_ms(10);
    }

    //-----------------------------------------------------
    //-------------  infinite main loop ----------
    //----------------------------------------------------


    while(1)
    {

        //--------------------------------------------------------------------------------
        //-------------  periodic tasks occures according to TickCounter variable----------
        //--------------------------------------------------------------------------------

        if(TickCounter.AccelTick_ms>IMU_TICK_PERIOD)
        {
            CLRWDT();                                 // clear watchdog timer each real time cycles

            LED2=1;
            TickCounter.AccelTick_ms=0;                // reset IMU tick counter to 0
            CurrentIMUData = IMUUpdateData();        // update IMU data from sensor

            // send Accelerometer data to CAN Fifo
        
            TempCANTxMsg.data_TX[0]=(char)(CurrentIMUData.XAccelerationData>>8);      //fill data buffer
            TempCANTxMsg.data_TX[1]=(char)(CurrentIMUData.XAccelerationData);
            TempCANTxMsg.data_TX[2]=(char)(CurrentIMUData.YAccelerationData>>8);
            TempCANTxMsg.data_TX[3]=(char)(CurrentIMUData.YAccelerationData);
            TempCANTxMsg.data_TX[4]=(char)(CurrentIMUData.ZAccelerationData>>8);
            TempCANTxMsg.data_TX[5]=(char)(CurrentIMUData.ZAccelerationData);
            TempCANTxMsg.data_TX[6]=0;
            TempCANTxMsg.data_TX[7]=0;

            TempCANTxMsg.dataLen= ACCEL_DATA_MESSAGE_LEN;
            TempCANTxMsg.id = (CAN_MESSAGE_IMU_TYPE << 7 | CAN_DEVICE_ADRESS <<4 | ACCEL_DATA_MESSAGE_ADRESS );
            TempCANTxMsg.flags = ECAN_TX_STD_FRAME;

            if(!CANTxFifo.Fifofull)
                 PutCANTxFifo(TempCANTxMsg);

            LED2=0;

        }

        if(TickCounter.GyroTick_ms>IMU_TICK_PERIOD)
        {
            //LED2=1;
            TickCounter.GyroTick_ms=0;                // reset IMU tick counter to 0

            // send Gyro data to CAN Fifo
        
            TempCANTxMsg.data_TX[0]=(char)(CurrentIMUData.XGyroscopeData>>8);
            TempCANTxMsg.data_TX[1]=(char)(CurrentIMUData.XGyroscopeData);
            TempCANTxMsg.data_TX[2]=(char)(CurrentIMUData.YGyroscopeData>>8);
            TempCANTxMsg.data_TX[3]=(char)(CurrentIMUData.YGyroscopeData);
            TempCANTxMsg.data_TX[4]=(char)(CurrentIMUData.ZGyroscopeData>>8);
            TempCANTxMsg.data_TX[5]=(char)(CurrentIMUData.ZGyroscopeData);

            TempCANTxMsg.dataLen= GYRO_DATA_MESSAGE_LEN;
            TempCANTxMsg.id = (CAN_MESSAGE_IMU_TYPE << 7 | CAN_DEVICE_ADRESS <<4 | GYRO_DATA_MESSAGE_ADRESS );
            TempCANTxMsg.flags = ECAN_TX_STD_FRAME;

            if(!CANTxFifo.Fifofull)
                 PutCANTxFifo(TempCANTxMsg);

        }
Exemple #3
0
 void main(void)
{      
  unsigned int  channel = CHANNEL;
  unsigned char data = 0x07;
  unsigned char t1;
  unsigned char t2;
  unsigned int tmpcount = 0;
  unsigned char wl_data[10];
  unsigned char rs_line[20];
  unsigned char rs_data[10];
  unsigned char tmp_data[50];
  
  // DBGU output configuration
  TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
  
  // Configuration PIT (Periodic Interrupt Timer)
  ConfigurePit();
  // Configuration TC (Timer Counter)
  ConfigureTc();
  // Configuration PIO (Paralell In and Out port), Init Interrupt on PIO
  ConfigureButtons();
  ConfigureLeds();
  // Configuration Radio Module nRF24L (PIO and SPI), ConfigureButtons must be executed before
  ConfigureNRF24L();
  ConfigureUSART0();
  ConfigureUSART1();
  
  while(Timer1Tick<2); // wait until NRF24L01 power up
  nrf24l01_power_up(True);
  while(Timer1Tick<4); // wait until NRF24L01 stand by
  Timer1Tick = 0;
  //initialize the 24L01 to the debug configuration as RX and auto-ack disabled
  nrf24l01_initialize_debug(True, nrf_TX_RX_SIZE, False);
  nrf24l01_write_register(0x06, &data, 1);
  nrf24l01_set_as_rx(True);
  Delay_US(130);
  nrf24l01_set_rf_ch(channel);
  nrf24l01_flush_rx();
  Delay_US(300);

  reset_wl = 1;
  while (1) {
    if( nrf_Data > 0 ) {
      nrf_Data = 0;      
      for( t1 = 0; t1<8; t1++ ) {
        wl_data[t1] = nrfRxMessage.Data[t1];     
      }
      LED_Toggle(LED_Green);  
      writeByteSequence_8(wl_data);
    }
    
    if(messageUSART1){
      messageUSART1 = 0;
      pmsgRead(tmp_data);
      while (tmp_data[tmpcount]!='\n'){
        t1 = tmp_data[tmpcount];
        tmpcount++;
        if( t1 >= '0' && t1 <= '9' ) { // If character is 0-9 convert it to num
          if( count < 20) {
            rs_line[count] = t1-'0';
            count++;
          }
        }
        if( t1 >= 'A' && t1 <= 'F' ) { // If character A-F convert to 10-15
          if( count < 20) {
            rs_line[count] = t1-'A'+10;
            count++;
          }
        }        
      } 
      // If character is a line break send packet
      for( count = 0; count <10; count++ ) { // Convert from 16*4 to 8*8
        t1 = (rs_line[count*2])<<4;
        t2 = rs_line[count*2+1];
        rs_data[count] = t1 | t2;
      }
      count = 0;
      tmpcount = 0;     
      if( nrf_Transmission_Done == 1 ) {
        TX_packet_BASE(rs_data); // Send packet.
        LED_Toggle(LED_Yellow);
      }
    }//if msg flag has been raised      
  }//while 
}//main