working version
Dependencies: mbed mbed-rtos SimpleDMA FreescaleIAP eeprom
Fork of CDMS_CODE_FM_28JAN2017 by
main.cpp
- Committer:
- samp1234
- Date:
- 2022-04-03
- Revision:
- 357:f3d48d62e00e
- Parent:
- 356:197c93dc2012
File content as of revision 357:f3d48d62e00e:
// 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();
INIT_EEPROM(); //changed Mar 2018
RESET_WATCHDOG();
if ((BAE_STATUS & 0x03) == 0x03)
{SW_OFF_BAE();}
uint8_t sd_stat_temp = SD_STATUS & 0x03;
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;
FCTN_CDMS_SD_INIT();/* sd card initialization*/
CDMS_RTC_DISABLE = 1;
//RTC_INIT_STATUS = test_buffer
if((CDMS_RTC_DISABLE & 0x01) == 1)
{
CDMS_RTC_ON();
}
if((RTC_INIT_STATUS & 0x01) != 1) //Joel
{
FCTN_CDMS_INIT_RTC();/* rtc initialization*/
//INIT_40mins
/*BAE_SW_EN_DS = 0; //DISABLE BAE
SD_SW_EN_DS = 0; //DISABLE SD
uint64_t ini_time = FCTN_CDMS_RD_RTC();
uint32_t T_check_ini = (((ini_time >> 7)& 0x00000FC0)>>6);
uint32_t T_diff = T_check_ini;
expired=0;
Ticker Sftw_Timer;
gPC.printf("\rGoing to start Ticker\n");
Sftw_Timer.attach(&int_acq1, 2500.0);
while (T_check_ini - T_diff < T_INI)
{
RESET_WATCHDOG();
wait_ms(10000);
ini_time = FCTN_CDMS_RD_RTC();
T_check_ini = (((ini_time >> 7)& 0x00000FC0)>>6);
gPC.printf("ini_time %d",T_check_ini);
if (expired == 1)
break;
}
BAE_SW_EN_DS = 1; //ENABLE BAE
SD_SW_EN_DS = 1; //ENABLE SD*/
}
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;
}
CDMS_RESET_COUNTER+=1;
WRITE_TO_EEPROM(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);
WRITE_TO_EEPROM(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;
test[2] = 0xF;
test[3] = 0xA0;
test[10] = 0xF;
test[11] = 0xA0;
test[18] = 0xF;
test[19] = 0xA0;
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);
//
//PL_wo_dma = new RtosTimer(payload_isr_fun_dma, osTimerPeriodic,(void * )NULL);
//gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);
//PL_wo_dma->stop();
//wait_ms(0.1);
//PL_wo_dma->start(6000);
/*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;
}
}
