CDMS code for testing sbc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Committer:
chaithanyarss
Date:
Sun Jul 03 09:47:05 2016 +0000
Revision:
216:570251b23c7b
Parent:
214:867de6d350fa
Child:
218:c63cdba0550f
Reset added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shreeshas95 7:fcd26c28411d 1 // TESTING PUSH PULL IN MAIN CPP
shreeshas95 0:f016e9e8d48b 2 #include "mbed.h"
ee12b079 98:fd99ddc0e0a1 3
ee12b079 99:efde3df6cd94 4 #define DEBUG 1
ee12b079 98:fd99ddc0e0a1 5
shreeshas95 101:bece931236a2 6 #include "SimpleDMA.h"
shreeshas95 101:bece931236a2 7 #include "dmaSPIslave.h"
shreeshas95 0:f016e9e8d48b 8 #include "rtos.h"
shreeshas95 1:a0055b3280c8 9 #include "mbed_debug.h"
chaithanyarss 216:570251b23c7b 10
shreeshas95 0:f016e9e8d48b 11 #include "Structures.h"
shreeshas95 103:b55559925dc1 12 #include "pinconfig.h"
shreeshas95 0:f016e9e8d48b 13 #include "DefinitionsAndGlobals.h"
shreeshas95 0:f016e9e8d48b 14 #include "crc.h"
chaithanyarss 216:570251b23c7b 15 #include "cdms_rtc.h"
chaithanyarss 216:570251b23c7b 16 #include "cdms_sd.h"
shreeshas95 103:b55559925dc1 17 #include "i2c.h"
shreeshas95 1:a0055b3280c8 18 #include "COM_SND_TM_functions.h"
shreeshas95 1:a0055b3280c8 19 #include "COM_SND_TM.h"
krishanprajapat 117:bfdc807f3d3c 20 #include "common_functions.h"
ee12b079 210:f4acf895b598 21 #include "RESET_functions.h"
ee12b079 210:f4acf895b598 22 #include "CDMS_HK.h"
chaithanyarss 216:570251b23c7b 23 #include "OBSRS.h"
shreeshas95 1:a0055b3280c8 24 #include "adf.h"
shreeshas95 0:f016e9e8d48b 25 #include "COM_RCV_TC.h"
chaithanyarss 216:570251b23c7b 26 #include "Flash.h"
ee12b079 210:f4acf895b598 27 #include "FMS_all.h"
ee12b079 210:f4acf895b598 28 #include "CDMS_PL.h"
shreeshas95 0:f016e9e8d48b 29 #include "COM_MNG_TMTC.h"
chaithanyarss 216:570251b23c7b 30 #include "COM_POWER_ON_TX.h"
aniruddhv 214:867de6d350fa 31 #include "COM_POWER_OFF_TX.h"
ee12b079 96:4ca92f9775e0 32 #include "Compression.h"
shreeshas95 0:f016e9e8d48b 33 #include "ThreadsAndFunctions.h"
ee12b079 210:f4acf895b598 34 #include "TEST_PL.h"
shreeshas95 0:f016e9e8d48b 35
chaithanyarss 216:570251b23c7b 36 void CDMS_INIT();
chaithanyarss 216:570251b23c7b 37
ee12b079 185:3b3cd96a7811 38 #define PL_TC(tm_ptr){\
ee12b079 185:3b3cd96a7811 39 Base_tc *beacon_tc = new Short_tc;\
ee12b079 185:3b3cd96a7811 40 beacon_tc->next_TC = NULL;\
ee12b079 185:3b3cd96a7811 41 PUTshort_or_long(beacon_tc,SHORT_TC_CODE);\
ee12b079 185:3b3cd96a7811 42 PUTcrc_pass(beacon_tc,0x1);\
ee12b079 185:3b3cd96a7811 43 PUTexec_status(beacon_tc,0);\
ee12b079 185:3b3cd96a7811 44 beacon_tc->TC_string[0] = 0x01;\
ee12b079 185:3b3cd96a7811 45 beacon_tc->TC_string[1] = 0xE0;\
ee12b079 185:3b3cd96a7811 46 beacon_tc->TC_string[2] = 0x81;\
ee12b079 185:3b3cd96a7811 47 beacon_tc->TC_string[3] = 0xD0;\
ee12b079 185:3b3cd96a7811 48 beacon_tc->TC_string[4] = 0x00;\
ee12b079 185:3b3cd96a7811 49 beacon_tc->TC_string[5] = 0;\
ee12b079 185:3b3cd96a7811 50 beacon_tc->TC_string[6] = 0;\
ee12b079 185:3b3cd96a7811 51 beacon_tc->TC_string[7] = 0;\
ee12b079 185:3b3cd96a7811 52 beacon_tc->TC_string[8] = 0;\
ee12b079 185:3b3cd96a7811 53 uint16_t crc16 = crc16_gen(beacon_tc->TC_string, 9);\
ee12b079 185:3b3cd96a7811 54 beacon_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\
ee12b079 185:3b3cd96a7811 55 beacon_tc->TC_string[10] = (crc16 & 0x00FF);\
ee12b079 185:3b3cd96a7811 56 tm_ptr = FCTN_CDMS_RLY_TMTC(beacon_tc);\
ee12b079 185:3b3cd96a7811 57 }
ee12b079 199:9f03d6ca94c9 58 #define OBSRS_TC(tm_ptr){\
ee12b079 199:9f03d6ca94c9 59 Base_tc *beacon_tc = new Short_tc;\
ee12b079 199:9f03d6ca94c9 60 beacon_tc->next_TC = NULL;\
ee12b079 199:9f03d6ca94c9 61 PUTshort_or_long(beacon_tc,SHORT_TC_CODE);\
ee12b079 199:9f03d6ca94c9 62 PUTcrc_pass(beacon_tc,0x1);\
ee12b079 199:9f03d6ca94c9 63 PUTexec_status(beacon_tc,0);\
ee12b079 199:9f03d6ca94c9 64 beacon_tc->TC_string[0] = 0x01;\
ee12b079 199:9f03d6ca94c9 65 beacon_tc->TC_string[1] = 0x20;\
ee12b079 199:9f03d6ca94c9 66 beacon_tc->TC_string[2] = 0xf2;\
ee12b079 199:9f03d6ca94c9 67 beacon_tc->TC_string[3] = 0x00;\
ee12b079 199:9f03d6ca94c9 68 beacon_tc->TC_string[4] = 0x00;\
ee12b079 199:9f03d6ca94c9 69 beacon_tc->TC_string[5] = 0;\
ee12b079 199:9f03d6ca94c9 70 beacon_tc->TC_string[6] = 2;\
ee12b079 199:9f03d6ca94c9 71 beacon_tc->TC_string[7] = 0;\
ee12b079 199:9f03d6ca94c9 72 beacon_tc->TC_string[8] = 2;\
ee12b079 199:9f03d6ca94c9 73 uint16_t crc16 = crc16_gen(beacon_tc->TC_string, 9);\
ee12b079 199:9f03d6ca94c9 74 beacon_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\
ee12b079 199:9f03d6ca94c9 75 beacon_tc->TC_string[10] = (crc16 & 0x00FF);\
ee12b079 199:9f03d6ca94c9 76 Base_tm *tm_ptr_head = NULL;\
ee12b079 199:9f03d6ca94c9 77 get_call_sign(tm_ptr_head);\
ee12b079 199:9f03d6ca94c9 78 Base_tm *put_tm_here = NULL;\
ee12b079 199:9f03d6ca94c9 79 /*execute_obsrs(current_TC, put_tm_here)*/\
ee12b079 199:9f03d6ca94c9 80 /*read_TC(current_TC);*/\
ee12b079 199:9f03d6ca94c9 81 execute_OBSRS_TC(beacon_tc);\
ee12b079 199:9f03d6ca94c9 82 gPC.puts("enter_adf\r\n");\
ee12b079 199:9f03d6ca94c9 83 transmit_adf;\
ee12b079 199:9f03d6ca94c9 84 gPC.puts("exit_adf\r\n");\
ee12b079 199:9f03d6ca94c9 85 }
chaithanyarss 216:570251b23c7b 86
chaithanyarss 216:570251b23c7b 87 void CDMS_INIT()
chaithanyarss 216:570251b23c7b 88 {
chaithanyarss 216:570251b23c7b 89 CDMS_INIT_STATUS = 1;
chaithanyarss 216:570251b23c7b 90
chaithanyarss 216:570251b23c7b 91 spi.format(8,0);
chaithanyarss 216:570251b23c7b 92 spi.frequency(1000000);
chaithanyarss 216:570251b23c7b 93
chaithanyarss 216:570251b23c7b 94 cs_sd = 1;
chaithanyarss 216:570251b23c7b 95 gCS_RTC = 1;
chaithanyarss 216:570251b23c7b 96 gCS_ADF = 1;
chaithanyarss 216:570251b23c7b 97
chaithanyarss 216:570251b23c7b 98 FCTN_CDMS_INIT_RTC();
chaithanyarss 216:570251b23c7b 99 FCTN_CDMS_SD_INIT();
chaithanyarss 216:570251b23c7b 100
chaithanyarss 216:570251b23c7b 101 }
chaithanyarss 216:570251b23c7b 102
shreeshas95 0:f016e9e8d48b 103 int main()
shreeshas95 0:f016e9e8d48b 104 {
chaithanyarss 216:570251b23c7b 105
chaithanyarss 216:570251b23c7b 106 CDMS_I2C_GPIO = 0;
chaithanyarss 216:570251b23c7b 107 PL_I2C_GPIO = 0;
chaithanyarss 216:570251b23c7b 108
shreeshas95 0:f016e9e8d48b 109 // ******************INITIALISATIONS START******************
chaithanyarss 216:570251b23c7b 110
shreeshas95 0:f016e9e8d48b 111 RX1M.baud(1200);
shreeshas95 0:f016e9e8d48b 112 gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;
shreeshas95 0:f016e9e8d48b 113 gRX_HEAD_DATA_NODE->next_node = NULL;
shreeshas95 0:f016e9e8d48b 114 gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;
shreeshas95 2:2caf2a9a13aa 115 gRX_COUNT = 0;
chaithanyarss 216:570251b23c7b 116 //gRX_CURRENT_PTR = gRX_CURRENT_DATA_NODE->values;
shreeshas95 0:f016e9e8d48b 117 RX1M.attach(&rx_read, Serial::RxIrq);
chaithanyarss 216:570251b23c7b 118
shreeshas95 0:f016e9e8d48b 119 // DEBUG
ee12b079 88:b9beee1a7a3e 120 //gPC.puts("welcome to mng_tm_tc\r\n");
ee12b079 203:424308159a56 121 gPC.baud(115200);//changed for bypassing COM
chaithanyarss 216:570251b23c7b 122
shreeshas95 0:f016e9e8d48b 123
ee12b079 93:4d76de54a699 124
chaithanyarss 216:570251b23c7b 125
chaithanyarss 216:570251b23c7b 126
ee12b079 196:c51bf4993f75 127 uint8_t test[512] = {0};
ee12b079 196:c51bf4993f75 128 disk_write(test,7000); //to be used only just before launch
chaithanyarss 216:570251b23c7b 129
chaithanyarss 216:570251b23c7b 130 #if DEBUG
ee12b079 113:b8991d9e3b6c 131 gPC.puts("welcome to mng_tmtc\r\n");
chaithanyarss 216:570251b23c7b 132 #endif
chaithanyarss 216:570251b23c7b 133
chaithanyarss 216:570251b23c7b 134
chaithanyarss 216:570251b23c7b 135
shreeshas95 0:f016e9e8d48b 136 // COM_MNG_TMTC THREAD
shreeshas95 0:f016e9e8d48b 137 gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN);
ee12b079 162:48fda0b8d573 138 gCOM_MNG_TMTC_THREAD->set_priority(osPriorityHigh);
chaithanyarss 216:570251b23c7b 139 #if DEBUG
ee12b079 94:611c066467a1 140 gPC.puts("allocating threads\r\n");
chaithanyarss 216:570251b23c7b 141 #endif
ee12b079 113:b8991d9e3b6c 142 gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
chaithanyarss 216:570251b23c7b 143 // gPC.puts("step one complete\r\n");
ee12b079 162:48fda0b8d573 144 gSCIENCE_THREAD->set_priority(osPriorityAboveNormal);
chaithanyarss 216:570251b23c7b 145 #if DEBUG
ee12b079 94:611c066467a1 146 gPC.puts("competed allocating threads\r\n");
chaithanyarss 216:570251b23c7b 147 #endif
chaithanyarss 216:570251b23c7b 148
chaithanyarss 216:570251b23c7b 149
ee12b079 170:286ef9dad36a 150 master.frequency(400000);
ee12b079 190:f0d5fde60221 151 PL_wo_dma = new RtosTimer(payload_isr_fun_dma, osTimerPeriodic,(void * )NULL);
ee12b079 191:f76b475d7807 152 //PL_wo_dma->start(6000);//
ee12b079 205:d2ac4580960d 153 gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);
chaithanyarss 216:570251b23c7b 154
chaithanyarss 216:570251b23c7b 155
chaithanyarss 216:570251b23c7b 156
chaithanyarss 216:570251b23c7b 157
ee12b079 205:d2ac4580960d 158 /*gPC.printf("PL_TC sending\r\n");
chaithanyarss 216:570251b23c7b 159
ee12b079 199:9f03d6ca94c9 160 Base_tm *tm_ptr = new Short_tm;
ee12b079 199:9f03d6ca94c9 161 OBSRS_TC(tm_ptr);
chaithanyarss 216:570251b23c7b 162
ee12b079 199:9f03d6ca94c9 163 gPC.printf("PL_TC sent");
ee12b079 205:d2ac4580960d 164 */
shreeshas95 0:f016e9e8d48b 165 // *******************INITIALISATIONS END********************
chaithanyarss 216:570251b23c7b 166
ee12b079 113:b8991d9e3b6c 167 //RtosTimer gCDMS_HK_TIMER(FCTN_CDMS_HK_MAIN, osTimerPeriodic);
ee12b079 113:b8991d9e3b6c 168 //gCDMS_HK_TIMER.start(5000);
chaithanyarss 216:570251b23c7b 169
ee12b079 97:717c7908c822 170 /*starting the thread with signal*/
ee12b079 191:f76b475d7807 171 //set_sig();
ee12b079 191:f76b475d7807 172 //payload_isr_fun();
chaithanyarss 216:570251b23c7b 173
ee12b079 94:611c066467a1 174 /*Calculating Stack used*/
chaithanyarss 216:570251b23c7b 175
ee12b079 96:4ca92f9775e0 176 int state;
chaithanyarss 216:570251b23c7b 177 /*while (true) {
chaithanyarss 216:570251b23c7b 178 Thread::wait(500);
chaithanyarss 216:570251b23c7b 179 state = gSCIENCE_THREAD->get_state();
chaithanyarss 216:570251b23c7b 180 //gPC.printf("Thread state %d\r\n", state);
chaithanyarss 216:570251b23c7b 181 if(state == Thread::Inactive)
ee12b079 96:4ca92f9775e0 182 {delete gSCIENCE_THREAD;
ee12b079 96:4ca92f9775e0 183 break;}
ee12b079 96:4ca92f9775e0 184 }*/
chaithanyarss 216:570251b23c7b 185
chaithanyarss 216:570251b23c7b 186
chaithanyarss 216:570251b23c7b 187
chaithanyarss 216:570251b23c7b 188 while(true) {
ee12b079 97:717c7908c822 189 Thread::wait(osWaitForever);
ee12b079 96:4ca92f9775e0 190 //state = gCOM_MNG_TMTC_THREAD->get_state() + '0';
chaithanyarss 216:570251b23c7b 191 gLEDG = !gLEDG;
chaithanyarss 216:570251b23c7b 192 //gPC.putc(state);
shreeshas95 0:f016e9e8d48b 193 }
shreeshas95 0:f016e9e8d48b 194 }