cdms_i2c_hardware_test

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of standaloneworkingi2c_cdms by Team Fox

main.cpp

Committer:
lakshya
Date:
2016-04-19
Revision:
156:741ab5dd826d
Parent:
155:80e7c7ff8aaf
Child:
157:d99f525edc4c

File content as of revision 156:741ab5dd826d:

// TESTING PUSH PULL IN MAIN CPP

#include "mbed.h"

uint8_t rcv_isr = 0; // flag for interrupt

#define DEBUG 1
#define SDCARD 0
#define I2C_PL 0


#include "SimpleDMA.h"
#include "dmaSPIslave.h"
#include "rtos.h"
#include "mbed_debug.h"
#include "cassert"

#include "Structures.h"
#include "pinconfig.h"
#include "DefinitionsAndGlobals.h"
#include "crc.h"
#include "i2c.h"
#include "COM_SND_TM_functions.h"
#include "COM_SND_TM.h"
#include "cdms_sd.h"
//#include "CDMS_HK.h"
#include "OBSRS.h"
#include "adf.h"
#include "COM_RCV_TC.h"
#include "COM_MNG_TMTC.h"
#include "COM_POWER_ON_TX.h"
#include "COM_POWER_OFF_TX.h"
#include "Compression.h"
#include "ThreadsAndFunctions.h"
uint8_t TM[134];
//void set_sig(){gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);}

void verifyHK_DATA()
{
    /*hk_verify[0]=TM[26];
    hk_verify[1]=TM[27];
    hk_verify[2]=TM[28];
    hk_verify[3]=TM[29];*/
   
   //float input=5.4332;
        uint8_t output[4];
    uint8_t output1[4];
   // assert(sizeof(float) == sizeof(uint32_t));
   // uint32_t* temp = reinterpret_cast<uint32_t*>(&input);
 
    //float* output1 = reinterpret_cast<float*>(temp);

   // printf("\n\r %f  ", input);
   // std::cout << "\n\r uint32 \t"<<*temp << std::endl;
 
  /*  output[0] =(uint8_t )(((*temp)>>24)&0xFF);
    output[1] =(uint8_t ) (((*temp)>>16)&0xFF);
    output[2] =(uint8_t ) (((*temp)>>8)&0xFF); 
    output[3] =(uint8_t ) ((*temp) & 0xFF);           // verify the logic 
    */
    //printf("\n\r inside %d %d %d %d", output[3],output[2],output[1],output[0]);
    //std:: cout << "\n\r uint8  inside " << output[3] << '\t' << output[2] << '\t' << output[1] << '\t' << output[0] <<std::endl; 
    
    /*convertion back or recheck code*/
    
    output[0] =TM[42];
    output[1] =TM[43];
    output[2] =TM[44]; 
    output[3] =TM[45];           // verify the logic 
  
   //printf("\n\rthe value is 26\t %x\n",TM[38]);
     //                       printf("\n\rthe value is  27\t%x\n",TM[39]);
       //                      printf("\n\rthe value is 28\t%x\n",TM[40]);
         //                     printf("\n\rthe value is 29\t%x\n",TM[41]); 

  
    
    uint32_t input_stage1=0x00000000;
    output1[0]=(uint32_t)(output[0]);
    output1[1]=(uint32_t)(output[1]);
    output1[2]=(uint32_t)(output[2]);
    output1[3]=(uint32_t)(output[3]);
    
    //input_stage1=output[3]+(output[2]*(0x100))+(output[1]*(0x10000))+(output[0]*(0x1000000));
    input_stage1=(output1[0]<<24) | (output1[1]<<16) | (output1[2]<<8) | (output1[3]);
    
    
    assert(sizeof(float) == sizeof(uint32_t));
    float* temp1 = reinterpret_cast<float*>(&input_stage1);
    
    printf("\n\r the value is: %f \n",*temp1);
   
   
//___________________________________________________-   
   /*
    float input =5.4367;
    //uint32_t tem;
    uint8_t Tmm[4];
        assert(sizeof(float) == sizeof(uint32_t));
    uint32_t* tem = reinterpret_cast<uint32_t*>(&input);

    Tmm[0] =(uint8_t )(((*tem)>>24)&0xFF);
    Tmm[2] =(uint8_t ) (((*tem)>>16)&0xFF);
    Tmm[1] =(uint8_t ) (((*tem)>>8)&0xFF);
    Tmm[3] =(uint8_t ) ((*tem) & 0xFF); 
    
    
    uint8_t output1[4];    
    //uint32_t input_stage1=0x00000000;
    output1[0]=(uint32_t)(Tmm[0]);
    output1[1]=(uint32_t)(Tmm[1]);
    output1[2]=(uint32_t)(Tmm[2]);
    output1[3]=(uint32_t)(Tmm[3]);
    
    
    //input_stage1=output[3]+(output[2]*(0x100))+(output[1]*(0x10000))+(output[0]*(0x1000000));
    uint32_t input_stage1=(output1[0]<<24) | (output1[1]<<16) | (output1[2]<<8) | (output1[3]);
    
    
    //assert(sizeof(float) == sizeof(uint32_t));
    float* value = reinterpret_cast<float*>(&input_stage1);
    printf("\n\rthe actual value: %f\n",input);
    printf("\n\r the value is: %f \n",&value);
    */
}
int main()
{
    CDMS_I2C_GPIO = 0;   
    
    //gLEDR = 1;
    
    // ******************INITIALISATIONS START******************
    // COM RX
    RX1M.baud(1200);
    gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;
    gRX_HEAD_DATA_NODE->next_node = NULL;
    gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;
    gRX_COUNT = 0;
//    gRX_CURRENT_PTR = gRX_CURRENT_DATA_NODE->values;
    RX1M.attach(&rx_read, Serial::RxIrq);
    
    #if I2c
    //I2C to Payload    (depends on pl interrupt design)
    PYLD_I2C_Int.rise(&isr_pyldtm);
    
    #endif
    master.frequency(400000);
    // DEBUG
    //gPC.puts("welcome to mng_tm_tc\r\n");
    gPC.baud(9600);
    
    // COMMON SPI
   // spi.format(8,0);
//    spi.frequency(1000000);
//
//    // SD CARD
//    cs_sd = 1;
//    gCS_RTC = 1;
//    gCS_ADF = 1;
//    
//    //FCTN_CDMS_INIT_RTC();/* rtc initialization*/
//    #if SDCARD
//    FCTN_CDMS_SD_INIT();/* sd card initialization*/
//    #endif
//    
//    #if DEBUG
//    gPC.puts("welcome to mng_tmtc\r\n");
//    #endif
//    
//    // COM_MNG_TMTC THREAD
//    gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN);
//    gCOM_MNG_TMTC_THREAD->set_priority(osPriorityAboveNormal);
//    #if DEBUG
//    gPC.puts("allocating threads\r\n");
//    #endif
//    #if SDCARD
//    gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
//   // gPC.puts("step one complete\r\n");
//    gSCIENCE_THREAD->set_priority(osPriorityBelowNormal);
//    #endif
//    
//    #if DEBUG
//    gPC.puts("competed allocating threads\r\n");
//    #endif
//      
    // *******************INITIALISATIONS END********************
    
    //RtosTimer gCDMS_HK_TIMER(FCTN_CDMS_HK_MAIN, osTimerPeriodic);
    //gCDMS_HK_TIMER.start(5000);
   
    uint8_t TC[11] = {0x1, 0x60, 0x81, 0x34, 0x01, 0x0, 0x0, 0x0, 0x0, 0x1d, 0xd9};
    /*tc[2]=62,tc[3]=00*/
    //uint8_t hk_verify[4];
    printf("\n\r sending tc\n");
    printf("\n\rservicetype:servicesubtype = %x \n PID's =%x \n",TC[2],TC[3]);
    //while(1)
    //{
        //if(ii)
        //{
                //TC[11] = {0x1, 0x60, 0x61, 0x15, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1d, 0xd9};
                wait(10);
                FCTN_I2C_WRITE((char*)TC,TC_SHORT_SIZE);
            
                wait(1); //TimeOut instead of wait
                if(BAE_I2C_GPIO == 1)
                {
                    
                   // printf("receiving...\r\n");
                    FCTN_I2C_READ((char*)TM,TM_LONG_SIZE);
                    //printf("%s", tm_pointer->TM_string);
                }
                else
                {
                    gPC.printf("bae_INTR NOT HIGH");
                }
                
                
                /* Code to verify HK DATA  */
                verifyHK_DATA();
                
                
                
        //}
        //else
        //{
                /*TC[11] = {0x1, 0x60, 0x81, 0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1d, 0xd9};
                wait(10);
                FCTN_I2C_WRITE((char*)TC,TC_SHORT_SIZE);
            
                wait(1); //TimeOut instead of wait
                if(BAE_I2C_GPIO == 1)
                {
                    
                   // printf("receiving...\r\n");
                    FCTN_I2C_READ((char*)TM,TM_LONG_SIZE);
                    //printf("%s", tm_pointer->TM_string);
                }
                else
                {
                    gPC.printf("bae_INTR NOT HIGH");
                }*/
        //}
        
   //}
    while(true){
        Thread::wait(osWaitForever);
        //state = gCOM_MNG_TMTC_THREAD->get_state() + '0';
         gLEDG = !gLEDG;
        //gPC.putc(state); 
    }
}