I2C code testing

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE_pl123 by Siva ram

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // TESTING PUSH PULL IN MAIN CPP
00002 
00003 #include "mbed.h"
00004 
00005 char PL_I2C_DATA[150];//Payload i2c array
00006 uint8_t rcv_isr = 0; // flag for interrupt
00007 
00008 #define DEBUG 0
00009 #define SDCARD 0
00010 #define I2C_PL 1
00011 
00012 
00013 #include "SimpleDMA.h"
00014 #include "dmaSPIslave.h"
00015 #include "rtos.h"
00016 #include "mbed_debug.h"
00017 
00018 #include "Structures.h"
00019 #include "pinconfig.h"
00020 #include "DefinitionsAndGlobals.h"
00021 #include "crc.h"
00022 #include "i2c.h"
00023 #include "COM_SND_TM_functions.h"
00024 #include "COM_SND_TM.h"
00025 #include "cdms_sd.h"
00026 //#include "CDMS_HK.h"
00027 #include "OBSRS.h"
00028 #include "adf.h"
00029 #include "COM_RCV_TC.h"
00030 #include "COM_MNG_TMTC.h"
00031 #include "COM_POWER_ON_TX.h"
00032 #include "COM_POWER_OFF_TX.h"
00033 #include "Compression.h"
00034 #include "ThreadsAndFunctions.h"
00035 
00036 //void set_sig(){gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);}
00037 
00038 char pia1 [13] ;
00039 
00040 void INIT_TC_TEMP (void)
00041 {
00042     int i;
00043     uint16_t CRC_VALUE = 0 ;
00044     
00045     pia1[0]    = 123  ;
00046     pia1[1]    = 0x00 ;
00047     pia1[2]    = 0x81 ;
00048     pia1[3]    = 0xD0 ;
00049     pia1[4]    = 0x00 ;
00050     pia1[5]    = 0x00 ;
00051     pia1[6]    = 0x00 ;
00052     pia1[7]    = 0x00 ;
00053     pia1[8]    = 0x00 ;
00054     CRC_VALUE  = crc16_gen1(pia1,9); 
00055     pia1[9]    = (char)((CRC_VALUE >> 8) & 0xff);
00056     pia1[10]   = (char)((CRC_VALUE >> 0) & 0xff);
00057     
00058                 for(i = 0; i < 13 ; i++)
00059             {
00060                 PL_I2C_DATA[i]= 0;
00061             }
00062     
00063     
00064 }
00065 
00066 int main()
00067 {
00068     //gLEDR = 1;
00069     
00070     // ******************INITIALISATIONS START******************
00071     // COM RX
00072     RX1M.baud(1200);
00073     gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;
00074     gRX_HEAD_DATA_NODE->next_node = NULL;
00075     gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;
00076     gRX_COUNT = 0;
00077 //    gRX_CURRENT_PTR = gRX_CURRENT_DATA_NODE->values;
00078     RX1M.attach(&rx_read, Serial::RxIrq);
00079     
00080     
00081     //I2C to Payload    (depends on pl interrupt design)
00082     PYLD_I2C_Int.rise(&isr_pyldtm);
00083     
00084     
00085     // DEBUG
00086     //gPC.puts("welcome to mng_tm_tc\r\n");
00087     gPC.baud(115200);
00088     
00089     // COMMON SPI
00090     spi.format(8,0);
00091     spi.frequency(1000000);
00092 
00093     // SD CARD
00094     cs_sd = 1;
00095     gCS_RTC = 1;
00096     gCS_ADF = 1;
00097     
00098     //FCTN_CDMS_INIT_RTC();/* rtc initialization*/
00099     #if SDCARD
00100     FCTN_CDMS_SD_INIT();/* sd card initialization*/
00101     #endif
00102     
00103     #if DEBUG
00104     gPC.puts("welcome to mng_tmtc\r\n");
00105     #endif
00106     
00107     // COM_MNG_TMTC THREAD
00108     gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN);
00109     gCOM_MNG_TMTC_THREAD->set_priority(osPriorityAboveNormal);
00110     #if DEBUG
00111     gPC.puts("allocating threads\r\n");
00112     #endif
00113     #if SDCARD
00114     gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
00115    // gPC.puts("step one complete\r\n");
00116     gSCIENCE_THREAD->set_priority(osPriorityBelowNormal);
00117     #endif
00118     
00119     #if DEBUG
00120     gPC.puts("competed allocating threads\r\n");
00121     #endif
00122       
00123     // *******************INITIALISATIONS END********************
00124     
00125     //RtosTimer gCDMS_HK_TIMER(FCTN_CDMS_HK_MAIN, osTimerPeriodic);
00126     //gCDMS_HK_TIMER.start(5000);
00127     
00128     /*starting the thread with signal*/
00129 //    set_sig();
00130     
00131     /*Calculating Stack used*/
00132     
00133     int state;
00134     /*while (true) { 
00135     Thread::wait(500); 
00136     state = gSCIENCE_THREAD->get_state(); 
00137     //gPC.printf("Thread state %d\r\n", state); 
00138     if(state == Thread::Inactive) 
00139     {delete gSCIENCE_THREAD;
00140     break;}
00141     }*/
00142     INIT_TC_TEMP();
00143     master.frequency(400000);
00144     int i =0 ;
00145     char test[1] ;
00146     test[0] = 7;
00147     
00148     while(true){
00149         Thread::wait(osWaitForever);
00150         //state = gCOM_MNG_TMTC_THREAD->get_state() + '0';
00151          gLEDG = !gLEDG;
00152         //gPC.putc(state); 
00153     }
00154 }