Repository for CDMS code
Dependencies: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
main.cpp@138:6fcbbaf19284, 2016-03-12 (annotated)
- Committer:
- Piasiv1206
- Date:
- Sat Mar 12 10:42:22 2016 +0000
- Revision:
- 138:6fcbbaf19284
- Parent:
- 136:8074893cd24e
workin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 7:fcd26c28411d | 1 | // TESTING PUSH PULL IN MAIN CPP |
shreeshas95 | 7:fcd26c28411d | 2 | |
shreeshas95 | 0:f016e9e8d48b | 3 | #include "mbed.h" |
ee12b079 | 98:fd99ddc0e0a1 | 4 | |
ee12b079 | 132:d4a4461214ad | 5 | uint8_t rcv_isr = 0; // flag for interrupt |
ee12b079 | 132:d4a4461214ad | 6 | |
ee12b079 | 130:d5b53088270b | 7 | #define DEBUG 1 |
Piasiv1206 | 138:6fcbbaf19284 | 8 | #define SDCARD 0 |
Piasiv1206 | 138:6fcbbaf19284 | 9 | #define I2C_PL 1 |
ee12b079 | 136:8074893cd24e | 10 | |
ee12b079 | 98:fd99ddc0e0a1 | 11 | |
shreeshas95 | 101:bece931236a2 | 12 | #include "SimpleDMA.h" |
shreeshas95 | 101:bece931236a2 | 13 | #include "dmaSPIslave.h" |
shreeshas95 | 0:f016e9e8d48b | 14 | #include "rtos.h" |
shreeshas95 | 1:a0055b3280c8 | 15 | #include "mbed_debug.h" |
shreeshas95 | 0:f016e9e8d48b | 16 | |
shreeshas95 | 0:f016e9e8d48b | 17 | #include "Structures.h" |
shreeshas95 | 103:b55559925dc1 | 18 | #include "pinconfig.h" |
shreeshas95 | 0:f016e9e8d48b | 19 | #include "DefinitionsAndGlobals.h" |
shreeshas95 | 0:f016e9e8d48b | 20 | #include "crc.h" |
ee12b079 | 130:d5b53088270b | 21 | #include "i2c.h" |
shreeshas95 | 1:a0055b3280c8 | 22 | #include "COM_SND_TM_functions.h" |
shreeshas95 | 1:a0055b3280c8 | 23 | #include "COM_SND_TM.h" |
ee12b079 | 99:efde3df6cd94 | 24 | #include "cdms_sd.h" |
ee12b079 | 114:9fb55057b13f | 25 | //#include "CDMS_HK.h" |
ee12b079 | 86:a26f5f22631d | 26 | #include "OBSRS.h" |
shreeshas95 | 1:a0055b3280c8 | 27 | #include "adf.h" |
shreeshas95 | 0:f016e9e8d48b | 28 | #include "COM_RCV_TC.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 | |
shreeshas95 | 105:5ce0337e7c15 | 35 | //void set_sig(){gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);} |
ee12b079 | 132:d4a4461214ad | 36 | |
Piasiv1206 | 138:6fcbbaf19284 | 37 | char pia1 [13] ; |
Piasiv1206 | 138:6fcbbaf19284 | 38 | |
Piasiv1206 | 138:6fcbbaf19284 | 39 | void INIT_TC_TEMP (void) |
Piasiv1206 | 138:6fcbbaf19284 | 40 | { |
Piasiv1206 | 138:6fcbbaf19284 | 41 | int i; |
Piasiv1206 | 138:6fcbbaf19284 | 42 | uint16_t CRC_VALUE = 0 ; |
Piasiv1206 | 138:6fcbbaf19284 | 43 | |
Piasiv1206 | 138:6fcbbaf19284 | 44 | pia1[0] = 123 ; |
Piasiv1206 | 138:6fcbbaf19284 | 45 | pia1[1] = 0xff ; |
Piasiv1206 | 138:6fcbbaf19284 | 46 | pia1[2] = 0x81 ; |
Piasiv1206 | 138:6fcbbaf19284 | 47 | pia1[3] = 0xD0 ; |
Piasiv1206 | 138:6fcbbaf19284 | 48 | pia1[4] = 0x00 ; |
Piasiv1206 | 138:6fcbbaf19284 | 49 | pia1[5] = 0x00 ; |
Piasiv1206 | 138:6fcbbaf19284 | 50 | pia1[6] = 0x00 ; |
Piasiv1206 | 138:6fcbbaf19284 | 51 | pia1[7] = 0x00 ; |
Piasiv1206 | 138:6fcbbaf19284 | 52 | pia1[8] = 0x00 ; |
Piasiv1206 | 138:6fcbbaf19284 | 53 | CRC_VALUE = 0 ; |
Piasiv1206 | 138:6fcbbaf19284 | 54 | pia1[9] = (char)((CRC_VALUE >> 8) & 0xff); |
Piasiv1206 | 138:6fcbbaf19284 | 55 | pia1[10] = (char)((CRC_VALUE >> 0) & 0xff); |
Piasiv1206 | 138:6fcbbaf19284 | 56 | |
Piasiv1206 | 138:6fcbbaf19284 | 57 | for(i = 0; i < 13 ; i++) |
Piasiv1206 | 138:6fcbbaf19284 | 58 | { |
Piasiv1206 | 138:6fcbbaf19284 | 59 | PL_I2C_DATA[i]= 0; |
Piasiv1206 | 138:6fcbbaf19284 | 60 | } |
Piasiv1206 | 138:6fcbbaf19284 | 61 | |
Piasiv1206 | 138:6fcbbaf19284 | 62 | |
Piasiv1206 | 138:6fcbbaf19284 | 63 | } |
ee12b079 | 132:d4a4461214ad | 64 | |
shreeshas95 | 0:f016e9e8d48b | 65 | int main() |
shreeshas95 | 0:f016e9e8d48b | 66 | { |
ee12b079 | 97:717c7908c822 | 67 | //gLEDR = 1; |
ee12b079 | 96:4ca92f9775e0 | 68 | |
shreeshas95 | 0:f016e9e8d48b | 69 | // ******************INITIALISATIONS START****************** |
shreeshas95 | 0:f016e9e8d48b | 70 | // COM RX |
shreeshas95 | 0:f016e9e8d48b | 71 | RX1M.baud(1200); |
shreeshas95 | 0:f016e9e8d48b | 72 | gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE; |
shreeshas95 | 0:f016e9e8d48b | 73 | gRX_HEAD_DATA_NODE->next_node = NULL; |
shreeshas95 | 0:f016e9e8d48b | 74 | gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE; |
shreeshas95 | 2:2caf2a9a13aa | 75 | gRX_COUNT = 0; |
shreeshas95 | 2:2caf2a9a13aa | 76 | // gRX_CURRENT_PTR = gRX_CURRENT_DATA_NODE->values; |
shreeshas95 | 0:f016e9e8d48b | 77 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 0:f016e9e8d48b | 78 | |
Piasiv1206 | 138:6fcbbaf19284 | 79 | |
ee12b079 | 130:d5b53088270b | 80 | //I2C to Payload (depends on pl interrupt design) |
ee12b079 | 132:d4a4461214ad | 81 | PYLD_I2C_Int.rise(&isr_pyldtm); |
Piasiv1206 | 138:6fcbbaf19284 | 82 | |
ee12b079 | 126:b7c024b5632d | 83 | |
shreeshas95 | 0:f016e9e8d48b | 84 | // DEBUG |
ee12b079 | 88:b9beee1a7a3e | 85 | //gPC.puts("welcome to mng_tm_tc\r\n"); |
ee12b079 | 136:8074893cd24e | 86 | gPC.baud(115200); |
shreeshas95 | 0:f016e9e8d48b | 87 | |
shreeshas95 | 0:f016e9e8d48b | 88 | // COMMON SPI |
shreeshas95 | 0:f016e9e8d48b | 89 | spi.format(8,0); |
shreeshas95 | 0:f016e9e8d48b | 90 | spi.frequency(1000000); |
shreeshas95 | 0:f016e9e8d48b | 91 | |
shreeshas95 | 0:f016e9e8d48b | 92 | // SD CARD |
ee12b079 | 86:a26f5f22631d | 93 | cs_sd = 1; |
shreeshas95 | 2:2caf2a9a13aa | 94 | gCS_RTC = 1; |
ee12b079 | 90:df55a5f68331 | 95 | gCS_ADF = 1; |
ee12b079 | 93:4d76de54a699 | 96 | |
ee12b079 | 98:fd99ddc0e0a1 | 97 | //FCTN_CDMS_INIT_RTC();/* rtc initialization*/ |
ee12b079 | 132:d4a4461214ad | 98 | #if SDCARD |
ee12b079 | 113:b8991d9e3b6c | 99 | FCTN_CDMS_SD_INIT();/* sd card initialization*/ |
ee12b079 | 132:d4a4461214ad | 100 | #endif |
shreeshas95 | 0:f016e9e8d48b | 101 | |
ee12b079 | 113:b8991d9e3b6c | 102 | #if DEBUG |
ee12b079 | 113:b8991d9e3b6c | 103 | gPC.puts("welcome to mng_tmtc\r\n"); |
ee12b079 | 113:b8991d9e3b6c | 104 | #endif |
ee12b079 | 113:b8991d9e3b6c | 105 | |
shreeshas95 | 0:f016e9e8d48b | 106 | // COM_MNG_TMTC THREAD |
shreeshas95 | 0:f016e9e8d48b | 107 | gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN); |
shreeshas95 | 0:f016e9e8d48b | 108 | gCOM_MNG_TMTC_THREAD->set_priority(osPriorityAboveNormal); |
ee12b079 | 99:efde3df6cd94 | 109 | #if DEBUG |
ee12b079 | 94:611c066467a1 | 110 | gPC.puts("allocating threads\r\n"); |
ee12b079 | 99:efde3df6cd94 | 111 | #endif |
ee12b079 | 132:d4a4461214ad | 112 | #if SDCARD |
ee12b079 | 113:b8991d9e3b6c | 113 | gSCIENCE_THREAD = new Thread(SCIENCE_FUN); |
ee12b079 | 94:611c066467a1 | 114 | // gPC.puts("step one complete\r\n"); |
ee12b079 | 113:b8991d9e3b6c | 115 | gSCIENCE_THREAD->set_priority(osPriorityBelowNormal); |
ee12b079 | 132:d4a4461214ad | 116 | #endif |
ee12b079 | 126:b7c024b5632d | 117 | |
ee12b079 | 99:efde3df6cd94 | 118 | #if DEBUG |
ee12b079 | 94:611c066467a1 | 119 | gPC.puts("competed allocating threads\r\n"); |
ee12b079 | 99:efde3df6cd94 | 120 | #endif |
ee12b079 | 132:d4a4461214ad | 121 | |
shreeshas95 | 0:f016e9e8d48b | 122 | // *******************INITIALISATIONS END******************** |
shreeshas95 | 0:f016e9e8d48b | 123 | |
ee12b079 | 113:b8991d9e3b6c | 124 | //RtosTimer gCDMS_HK_TIMER(FCTN_CDMS_HK_MAIN, osTimerPeriodic); |
ee12b079 | 113:b8991d9e3b6c | 125 | //gCDMS_HK_TIMER.start(5000); |
shreeshas95 | 104:a50ae79ca36e | 126 | |
ee12b079 | 97:717c7908c822 | 127 | /*starting the thread with signal*/ |
shreeshas95 | 105:5ce0337e7c15 | 128 | // set_sig(); |
ee12b079 | 97:717c7908c822 | 129 | |
ee12b079 | 94:611c066467a1 | 130 | /*Calculating Stack used*/ |
ee12b079 | 94:611c066467a1 | 131 | |
ee12b079 | 96:4ca92f9775e0 | 132 | int state; |
ee12b079 | 96:4ca92f9775e0 | 133 | /*while (true) { |
ee12b079 | 96:4ca92f9775e0 | 134 | Thread::wait(500); |
ee12b079 | 96:4ca92f9775e0 | 135 | state = gSCIENCE_THREAD->get_state(); |
ee12b079 | 96:4ca92f9775e0 | 136 | //gPC.printf("Thread state %d\r\n", state); |
ee12b079 | 96:4ca92f9775e0 | 137 | if(state == Thread::Inactive) |
ee12b079 | 96:4ca92f9775e0 | 138 | {delete gSCIENCE_THREAD; |
ee12b079 | 96:4ca92f9775e0 | 139 | break;} |
ee12b079 | 96:4ca92f9775e0 | 140 | }*/ |
Piasiv1206 | 138:6fcbbaf19284 | 141 | INIT_TC_TEMP(); |
ee12b079 | 132:d4a4461214ad | 142 | int i =0 ; |
ee12b079 | 132:d4a4461214ad | 143 | char test[1] ; |
ee12b079 | 132:d4a4461214ad | 144 | test[0] = 7; |
ee12b079 | 132:d4a4461214ad | 145 | while(1) |
ee12b079 | 132:d4a4461214ad | 146 | { |
Piasiv1206 | 138:6fcbbaf19284 | 147 | //test[0] = gPC.getc(); |
Piasiv1206 | 138:6fcbbaf19284 | 148 | gPC.printf("Wriring to I2C\n\r"); |
ee12b079 | 132:d4a4461214ad | 149 | |
Piasiv1206 | 138:6fcbbaf19284 | 150 | wait(10); |
Piasiv1206 | 138:6fcbbaf19284 | 151 | |
Piasiv1206 | 138:6fcbbaf19284 | 152 | master.write(addr_pl|0x00,pia1,11); |
ee12b079 | 132:d4a4461214ad | 153 | |
ee12b079 | 132:d4a4461214ad | 154 | if(rcv_isr == 1) |
ee12b079 | 132:d4a4461214ad | 155 | { |
Piasiv1206 | 138:6fcbbaf19284 | 156 | for(i = 0; i < 13 ; i++) |
ee12b079 | 132:d4a4461214ad | 157 | { |
Piasiv1206 | 138:6fcbbaf19284 | 158 | gPC.printf("%d\r\n",PL_I2C_DATA[i]); |
Piasiv1206 | 138:6fcbbaf19284 | 159 | PL_I2C_DATA[i] = 0 ; |
ee12b079 | 132:d4a4461214ad | 160 | } |
ee12b079 | 132:d4a4461214ad | 161 | rcv_isr = 0; |
ee12b079 | 132:d4a4461214ad | 162 | } |
ee12b079 | 132:d4a4461214ad | 163 | |
ee12b079 | 132:d4a4461214ad | 164 | } |
Piasiv1206 | 138:6fcbbaf19284 | 165 | |
shreeshas95 | 0:f016e9e8d48b | 166 | while(true){ |
ee12b079 | 97:717c7908c822 | 167 | Thread::wait(osWaitForever); |
ee12b079 | 96:4ca92f9775e0 | 168 | //state = gCOM_MNG_TMTC_THREAD->get_state() + '0'; |
ee12b079 | 96:4ca92f9775e0 | 169 | gLEDG = !gLEDG; |
ee12b079 | 96:4ca92f9775e0 | 170 | //gPC.putc(state); |
shreeshas95 | 0:f016e9e8d48b | 171 | } |
shreeshas95 | 0:f016e9e8d48b | 172 | } |