Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Committer:
ee12b079
Date:
Sun Jul 03 18:50:32 2016 +0000
Revision:
217:5006c998ea50
Parent:
205:d2ac4580960d
restarting dma solved

Who changed what in which revision?

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