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