Esempio n. 1
0
/******************************************************************************
* Outline       : HardwareSetup
* Description   : Configures the YRDK initial hardware settings.  
*                 The YRRDK board was designed by partner Future 
*                 Designs Inc. (www.teamfdi.com).
*                 Debugging is accomplished through the Segger 
*                 J-Link Lite OB solution (www.segger.com) 
* Argument      : none
* Return value  : none
******************************************************************************/
void HardwareSetup(void)
{
    ConfigureOperatingFrequency();
    ConfigureOutputPorts();
    ConfigureInterrupts();
    EnablePeripheralModules();
}
Esempio n. 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);

        }