FM

Dependencies:   SimpleDMA eeprom mbed-rtos mbed FreescaleIAP

Fork of CDMS_CODE by shubham c

main.cpp

Committer:
Piasiv1206
Date:
2016-03-12
Revision:
138:6fcbbaf19284
Parent:
136:8074893cd24e

File content as of revision 138:6fcbbaf19284:

// 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 1


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

#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"

//void set_sig(){gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);}

char pia1 [13] ;

void INIT_TC_TEMP (void)
{
    int i;
    uint16_t CRC_VALUE = 0 ;
    
    pia1[0]    = 123  ;
    pia1[1]    = 0xff ;
    pia1[2]    = 0x81 ;
    pia1[3]    = 0xD0 ;
    pia1[4]    = 0x00 ;
    pia1[5]    = 0x00 ;
    pia1[6]    = 0x00 ;
    pia1[7]    = 0x00 ;
    pia1[8]    = 0x00 ;
    CRC_VALUE  = 0 ;
    pia1[9]    = (char)((CRC_VALUE >> 8) & 0xff);
    pia1[10]   = (char)((CRC_VALUE >> 0) & 0xff);
    
                for(i = 0; i < 13 ; i++)
            {
                PL_I2C_DATA[i]= 0;
            }
    
    
}

int main()
{
    //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);
    
    
    //I2C to Payload    (depends on pl interrupt design)
    PYLD_I2C_Int.rise(&isr_pyldtm);
    
    
    // DEBUG
    //gPC.puts("welcome to mng_tm_tc\r\n");
    gPC.baud(115200);
    
    // 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);
    
    /*starting the thread with signal*/
//    set_sig();
    
    /*Calculating Stack used*/
    
    int state;
    /*while (true) { 
    Thread::wait(500); 
    state = gSCIENCE_THREAD->get_state(); 
    //gPC.printf("Thread state %d\r\n", state); 
    if(state == Thread::Inactive) 
    {delete gSCIENCE_THREAD;
    break;}
    }*/
    INIT_TC_TEMP();
    int i =0 ;
    char test[1] ;
    test[0] = 7;
    while(1)
    {
        //test[0] = gPC.getc();
        gPC.printf("Wriring to I2C\n\r");
        
        wait(10);
        
        master.write(addr_pl|0x00,pia1,11);
        
        if(rcv_isr == 1)
        {
            for(i = 0; i < 13 ; i++)
            {
                gPC.printf("%d\r\n",PL_I2C_DATA[i]);
                PL_I2C_DATA[i] = 0 ;
            }
            rcv_isr = 0;
        }
        
    }
    
    while(true){
        Thread::wait(osWaitForever);
        //state = gCOM_MNG_TMTC_THREAD->get_state() + '0';
         gLEDG = !gLEDG;
        //gPC.putc(state); 
    }
}