working version

Dependencies:   mbed mbed-rtos SimpleDMA FreescaleIAP eeprom

Fork of CDMS_CODE_FM_28JAN2017 by samp Srinivasan

main.cpp

Committer:
samp1234
Date:
2018-02-10
Revision:
356:197c93dc2012
Parent:
355:a5e72222ff26
Child:
357:f3d48d62e00e

File content as of revision 356:197c93dc2012:

// TESTING PUSH PULL IN MAIN CPP

#include "mbed.h"
//#include "eeprom.h"

#define DEBUG 1

#include "SimpleDMA.h"
#include "dmaSPIslave.h"
#include "rtos.h"
#include "mbed_debug.h"
void rx_read();
#include "Structures.h"
#include "pinconfig.h"
#include "DefinitionsAndGlobals.h"
#include "crc.h"
#include "i2c.h"
//#include "EEPROM.h"
#include "Flash.h"
#include "COM_SND_TM_functions.h"
#include "cdms_rtc.h"
#include "COM_SND_TM.h"
#include "cdms_sd.h"
#include "common_functions.h"
#include "RESET_functions.h"
#include "CDMS_PL.h"
#include "CDMS_HK.h"
#include "adf.h"
#include "COM_RCV_TC.h"
#include "FMS_all.h"
#include "Compression.h"
#include "COM_MNG_TMTC.h"
#include "COM_POWER_OFF_TX.h"
#include "COM_POWER_ON_TX.h"
#include "OBSRS.h"
#include "ThreadsAndFunctions.h"
//#include "TEST_PL.h"

int main()
{    
   
    //RELAY SWITCHING 
    
    
    RF_SW_CNTRL_BCN = 1;
    Thread::wait(25);
    RF_SW_CNTRL_BCN = 0;
    PYLD_DFF = 1;
    
    for(int i= 0; i< 10 ; i++)
    {PYLD_DFF_CLK = !PYLD_DFF_CLK;
    wait_us(10);} 
    
    CDMS_I2C_GPIO = 0; 
    PL_I2C_GPIO = 0; 
    
    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;
    RX1M.attach(&rx_read, Serial::RxIrq);
    
   gPC.baud(1200);//changed for bypassing COM
   
    
    //Base_tm *tm_ptr = NULL;
    //SET_BCN_STANDBY(tm_ptr);
    //gPC.puts("set Bcn off\r\n");
    
    // COMMON SPI
    spi.format(8,0);
    spi.frequency(500000);
    FLASH_INI();        
    if ((BAE_STATUS & 0x03) == 0x03)
    {SW_OFF_BAE();}
    uint8_t sd_stat_temp = SD_STATUS & 0x03;                        //Joel
    SD_CARD_fromuC_ENA3 = 0; 
    SD_CARD_fromISO_ENA4 = 0;
    SD_SW_EN_DS = 0; 
    wait(1);
    SD_CARD_fromuC_ENA3 = 1; 
    SD_CARD_fromISO_ENA4 = 1;
    SD_SW_EN_DS = 1;
        
    wait(1);
    // SD CARD
    cs_sd = 1;
    gCS_RTC = 1;
    gCS_ADF = 1;
    
    //CDMS_RTC_DISABLE = 1;
    if((CDMS_RTC_DISABLE & 0x01) == 1)
    {
      CDMS_RTC_ON();
    }
    if((RTC_INIT_STATUS & 0x01) != 1)                  //Joel
     {
        FCTN_CDMS_INIT_RTC();/* rtc initialization*/
     }
    FCTN_CDMS_SD_INIT();/* sd card initialization*/
    if(sd_stat_temp ==  DEVICE_DISABLED)
    {
        SD_STATUS = sd_stat_temp;
    //    SD_STATUS = 0x03;
        SD_SW_EN_DS = 0;
    }
    else if(sd_stat_temp == DEVICE_OC_FAULT)
    {
        SD_STATUS = sd_stat_temp;
    }
   // INIT_EEPROM(); // added by samp
    CDMS_RESET_COUNTER+=1;
    FCTN_CDMS_WR_FLASH(7,CDMS_RESET_COUNTER);
    gPC.printf("\n\r%d\n",CDMS_RESET_COUNTER);
    TIME_LATEST_CDSMS_RESET = FCTN_CDMS_RD_RTC() >> 7;
    FCTN_CDMS_WR_FLASH(8,TIME_LATEST_CDSMS_RESET);
    
   // gPC.printf("%d \n", READ_FROM_EERPOM(8));
    //uint8_t test[512];
  
    //for(int i =0; i<512; i++)
    //    test[i] = 0;
    //disk_write(test,80000);

    SD_MNG_SECT = SD_LIB_BLK_CURRENT;

    FCTN_SD_MNGR();

    #if DEBUG
    gPC.puts("welcome to mng_tmtc\r\n");
    #endif
    
    #if DEBUG
    gPC.puts("allocating threads\r\n");
    #endif
    
    //DMA iobject decalaration
    gPAY_SPI = new dmaSPISlave(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS);
    
    // COM_POWER_ON_TX();
    
    // COM_MNG_TMTC THREAD
    gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN);
    gCOM_MNG_TMTC_THREAD->set_priority(osPriorityRealtime);
    
    gHK_THREAD = new Thread(FCTN_CDMS_HK_MAIN);
   // gHK_THREAD->set_priority(osPriorityHigh);
     gHK_THREAD->set_priority(osPriorityNormal);
    
    gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
    gSCIENCE_THREAD->set_priority(osPriorityHigh);
    
    #if DEBUG
    gPC.puts("completed allocating threads\r\n");
    #endif 
    
    master.frequency(400000);
    
    HK_counter = new RtosTimer(hk_isr, osTimerPeriodic,(void * )NULL);
    gHK_THREAD->signal_set(HK_SIGNAL);
   HK_counter->stop();
   wait_ms(0.1);
   HK_counter->start(10000);
  // HK_counter->start(10000);
    
    sys_reset_cdms_timer = new RtosTimer(sys_pwr_reset, osTimerPeriodic, (void * )NULL);
    sys_reset_cdms_timer->start(cdms_reset_timeout);

    //PL_wo_dma = new RtosTimer(payload_isr_fun_dma, osTimerPeriodic,(void * )NULL);
    //PL_wo_dma->start(6000);
    //gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);
    
    /*Timeout flipper;
    flipper.attach(BAE_TC,31);*/
    
    /*while(1){
    gPC.printf("PL_TC sending\r\n");
    
    Base_tm *tm_ptr = new Long_tm;
    PL_TC(tm_ptr);
    wait(1);
    }
    gPC.printf("PL_TC sent");*/
    //test_pl_main();
    while(true){
        Thread::wait(osWaitForever);
         gLEDG = !gLEDG;
    }
}