samp Srinivasan / Mbed 2 deprecated CDMS_CODE_FROM13JAN2017

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

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 #define DEBUG 1
00006 
00007 #include "SimpleDMA.h"
00008 #include "dmaSPIslave.h"
00009 #include "rtos.h"
00010 #include "mbed_debug.h"
00011 void rx_read();
00012 #include "Structures.h"
00013 #include "pinconfig.h"
00014 #include "DefinitionsAndGlobals.h"
00015 #include "crc.h"
00016 #include "i2c.h"
00017 #include "COM_SND_TM_functions.h"
00018 #include "Flash.h"
00019 #include "cdms_rtc.h"
00020 #include "COM_SND_TM.h"
00021 #include "cdms_sd.h"
00022 #include "common_functions.h"
00023 #include "RESET_functions.h"
00024 #include "CDMS_PL.h"
00025 #include "CDMS_HK.h"
00026 #include "adf.h"
00027 #include "COM_RCV_TC.h"
00028 #include "FMS_all.h"
00029 #include "Compression.h"
00030 #include "COM_MNG_TMTC.h"
00031 #include "COM_POWER_OFF_TX.h"
00032 #include "COM_POWER_ON_TX.h"
00033 #include "OBSRS.h"
00034 #include "ThreadsAndFunctions.h"
00035 #include "TEST_PL.h"
00036 
00037 int main()
00038 {    
00039     
00040     //RELAY SWITCHING 
00041     
00042     
00043     RF_SW_CNTRL_BCN = 1;
00044     Thread::wait(25);
00045     RF_SW_CNTRL_BCN = 0;
00046     PYLD_DFF = 1;
00047     
00048     for(int i= 0; i< 10 ; i++)
00049     {PYLD_DFF_CLK = !PYLD_DFF_CLK;
00050     wait_us(10);} 
00051     
00052     CDMS_I2C_GPIO = 0; 
00053     PL_I2C_GPIO = 0; 
00054     
00055     RX1M.baud(1200);
00056     gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;
00057     gRX_HEAD_DATA_NODE->next_node = NULL;
00058     gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;
00059     gRX_COUNT = 0;
00060     RX1M.attach(&rx_read, Serial::RxIrq);
00061     
00062    gPC.baud(1200);//changed for bypassing COM
00063    
00064     
00065     //Base_tm *tm_ptr = NULL;
00066     //SET_BCN_STANDBY(tm_ptr);
00067     //gPC.puts("set Bcn off\r\n");
00068     
00069     // COMMON SPI
00070     spi.format(8,0);
00071     spi.frequency(500000);
00072 
00073     SD_SW_EN_DS = 0; 
00074     wait(1);
00075     SD_SW_EN_DS = 1;
00076     wait(1);
00077     // SD CARD
00078     cs_sd = 1;
00079     gCS_RTC = 1;
00080     gCS_ADF = 1;
00081     
00082     
00083     FCTN_CDMS_INIT_RTC();/* rtc initialization*/
00084     FCTN_CDMS_SD_INIT();/* sd card initialization*/
00085     
00086     CDMS_RESET_COUNTER++;
00087     FCTN_CDMS_WR_FLASH(17,CDMS_RESET_COUNTER);
00088     TIME_LATEST_CDSMS_RESET = FCTN_CDMS_RD_RTC() >> 7;
00089     FCTN_CDMS_WR_FLASH(8,TIME_LATEST_CDSMS_RESET);
00090     
00091     uint8_t test[512];
00092     for(int i =0; i<512; i++)
00093         test[i] = 0;
00094     disk_write(test,80000);
00095     //SD_MNG_SECT = SD_LIB_BLK_CURRENT;
00096     FCTN_SD_MNGR();
00097 
00098     #if DEBUG
00099     gPC.puts("welcome to mng_tmtc\r\n");
00100     #endif
00101     
00102     #if DEBUG
00103     gPC.puts("allocating threads\r\n");
00104     #endif
00105     
00106     //DMA iobject decalaration
00107     gPAY_SPI = new dmaSPISlave(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS);
00108     
00109     // COM_POWER_ON_TX();
00110     
00111     // COM_MNG_TMTC THREAD
00112     gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN);
00113     gCOM_MNG_TMTC_THREAD->set_priority(osPriorityRealtime);
00114     
00115     gHK_THREAD = new Thread(FCTN_CDMS_HK_MAIN);
00116    // gHK_THREAD->set_priority(osPriorityHigh);
00117      gHK_THREAD->set_priority(osPriorityNormal);
00118     
00119     gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
00120     gSCIENCE_THREAD->set_priority(osPriorityHigh);
00121     
00122     #if DEBUG
00123     gPC.puts("completed allocating threads\r\n");
00124     #endif 
00125     
00126     master.frequency(400000);
00127     
00128     HK_counter = new RtosTimer(hk_isr, osTimerPeriodic,(void * )NULL);
00129     gHK_THREAD->signal_set(HK_SIGNAL);
00130    HK_counter->start(10000);
00131     
00132     sys_reset_cdms_timer = new RtosTimer(sys_pwr_reset, osTimerPeriodic, (void * )NULL);
00133     sys_reset_cdms_timer->start(cdms_reset_timeout);
00134 
00135     //PL_wo_dma = new RtosTimer(payload_isr_fun_dma, osTimerPeriodic,(void * )NULL);
00136     //PL_wo_dma->start(6000);
00137     //gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);
00138     
00139     /*Timeout flipper;
00140     flipper.attach(BAE_TC,31);*/
00141     
00142     /*while(1){
00143     gPC.printf("PL_TC sending\r\n");
00144     
00145     Base_tm *tm_ptr = new Long_tm;
00146     PL_TC(tm_ptr);
00147     wait(1);
00148     }
00149     gPC.printf("PL_TC sent");*/
00150     //test_pl_main();
00151     while(true){
00152         Thread::wait(osWaitForever);
00153          gLEDG = !gLEDG;
00154     }
00155 }