cdms_i2c_hardware_test
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of standaloneworkingi2c_cdms by
main.cpp@155:80e7c7ff8aaf, 2016-04-16 (annotated)
- Committer:
- prasanthbj05
- Date:
- Sat Apr 16 11:25:38 2016 +0000
- Revision:
- 155:80e7c7ff8aaf
- Parent:
- 154:e808cdb56239
- Child:
- 156:741ab5dd826d
i2c_working;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 8:fcd26c28411d | 1 | // TESTING PUSH PULL IN MAIN CPP |
shreeshas95 | 8:fcd26c28411d | 2 | |
shreeshas95 | 0:f016e9e8d48b | 3 | #include "mbed.h" |
ee12b079 | 95:fd99ddc0e0a1 | 4 | |
ee12b079 | 131:d4a4461214ad | 5 | uint8_t rcv_isr = 0; // flag for interrupt |
ee12b079 | 131:d4a4461214ad | 6 | |
ee12b079 | 129:d5b53088270b | 7 | #define DEBUG 1 |
ee12b079 | 148:e6c7d4f87704 | 8 | #define SDCARD 0 |
ee12b079 | 136:8074893cd24e | 9 | #define I2C_PL 0 |
ee12b079 | 136:8074893cd24e | 10 | |
ee12b079 | 95: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" |
prasanthbj05 | 155:80e7c7ff8aaf | 16 | #include "cassert" |
shreeshas95 | 0:f016e9e8d48b | 17 | |
shreeshas95 | 0:f016e9e8d48b | 18 | #include "Structures.h" |
shreeshas95 | 104:b55559925dc1 | 19 | #include "pinconfig.h" |
shreeshas95 | 0:f016e9e8d48b | 20 | #include "DefinitionsAndGlobals.h" |
shreeshas95 | 0:f016e9e8d48b | 21 | #include "crc.h" |
ee12b079 | 129: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 | 96:efde3df6cd94 | 25 | #include "cdms_sd.h" |
ee12b079 | 113:9fb55057b13f | 26 | //#include "CDMS_HK.h" |
ee12b079 | 83: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 | 93:4ca92f9775e0 | 33 | #include "Compression.h" |
shreeshas95 | 0:f016e9e8d48b | 34 | #include "ThreadsAndFunctions.h" |
prasanthbj05 | 155:80e7c7ff8aaf | 35 | uint8_t TM[134]; |
shreeshas95 | 106:5ce0337e7c15 | 36 | //void set_sig(){gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);} |
ee12b079 | 131:d4a4461214ad | 37 | |
prasanthbj05 | 155:80e7c7ff8aaf | 38 | void verifyHK_DATA() |
prasanthbj05 | 155:80e7c7ff8aaf | 39 | { |
prasanthbj05 | 155:80e7c7ff8aaf | 40 | /*hk_verify[0]=TM[26]; |
prasanthbj05 | 155:80e7c7ff8aaf | 41 | hk_verify[1]=TM[27]; |
prasanthbj05 | 155:80e7c7ff8aaf | 42 | hk_verify[2]=TM[28]; |
prasanthbj05 | 155:80e7c7ff8aaf | 43 | hk_verify[3]=TM[29];*/ |
prasanthbj05 | 155:80e7c7ff8aaf | 44 | |
prasanthbj05 | 155:80e7c7ff8aaf | 45 | uint8_t output1[4]; |
prasanthbj05 | 155:80e7c7ff8aaf | 46 | uint32_t input_stage1=0x00000000; |
prasanthbj05 | 155:80e7c7ff8aaf | 47 | output1[0]=(uint32_t)(TM[26]); |
prasanthbj05 | 155:80e7c7ff8aaf | 48 | output1[1]=(uint32_t)(TM[27]); |
prasanthbj05 | 155:80e7c7ff8aaf | 49 | output1[2]=(uint32_t)(TM[28]); |
prasanthbj05 | 155:80e7c7ff8aaf | 50 | output1[3]=(uint32_t)(TM[29]); |
prasanthbj05 | 155:80e7c7ff8aaf | 51 | |
prasanthbj05 | 155:80e7c7ff8aaf | 52 | |
prasanthbj05 | 155:80e7c7ff8aaf | 53 | //input_stage1=output[3]+(output[2]*(0x100))+(output[1]*(0x10000))+(output[0]*(0x1000000)); |
prasanthbj05 | 155:80e7c7ff8aaf | 54 | input_stage1=(output1[0]<<24) | (output1[1]<<16) | (output1[2]<<8) | (output1[3]); |
prasanthbj05 | 155:80e7c7ff8aaf | 55 | |
prasanthbj05 | 155:80e7c7ff8aaf | 56 | |
prasanthbj05 | 155:80e7c7ff8aaf | 57 | assert(sizeof(float) == sizeof(uint32_t)); |
prasanthbj05 | 155:80e7c7ff8aaf | 58 | float* temp1 = reinterpret_cast<float*>(&input_stage1); |
prasanthbj05 | 155:80e7c7ff8aaf | 59 | |
prasanthbj05 | 155:80e7c7ff8aaf | 60 | printf("\n\r the value is: %f \n",*temp1); |
prasanthbj05 | 155:80e7c7ff8aaf | 61 | } |
shreeshas95 | 0:f016e9e8d48b | 62 | int main() |
shreeshas95 | 0:f016e9e8d48b | 63 | { |
ee12b079 | 148:e6c7d4f87704 | 64 | CDMS_I2C_GPIO = 0; |
ee12b079 | 148:e6c7d4f87704 | 65 | |
ee12b079 | 94:717c7908c822 | 66 | //gLEDR = 1; |
ee12b079 | 93:4ca92f9775e0 | 67 | |
shreeshas95 | 0:f016e9e8d48b | 68 | // ******************INITIALISATIONS START****************** |
shreeshas95 | 0:f016e9e8d48b | 69 | // COM RX |
shreeshas95 | 0:f016e9e8d48b | 70 | RX1M.baud(1200); |
shreeshas95 | 0:f016e9e8d48b | 71 | gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE; |
shreeshas95 | 0:f016e9e8d48b | 72 | gRX_HEAD_DATA_NODE->next_node = NULL; |
shreeshas95 | 0:f016e9e8d48b | 73 | gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE; |
shreeshas95 | 2:2caf2a9a13aa | 74 | gRX_COUNT = 0; |
shreeshas95 | 2:2caf2a9a13aa | 75 | // gRX_CURRENT_PTR = gRX_CURRENT_DATA_NODE->values; |
shreeshas95 | 0:f016e9e8d48b | 76 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 0:f016e9e8d48b | 77 | |
ee12b079 | 136:8074893cd24e | 78 | #if I2c |
ee12b079 | 129:d5b53088270b | 79 | //I2C to Payload (depends on pl interrupt design) |
ee12b079 | 131:d4a4461214ad | 80 | PYLD_I2C_Int.rise(&isr_pyldtm); |
ee12b079 | 148:e6c7d4f87704 | 81 | |
ee12b079 | 136:8074893cd24e | 82 | #endif |
prasanthbj05 | 155:80e7c7ff8aaf | 83 | master.frequency(400000); |
shreeshas95 | 0:f016e9e8d48b | 84 | // DEBUG |
ee12b079 | 85:b9beee1a7a3e | 85 | //gPC.puts("welcome to mng_tm_tc\r\n"); |
prasanthbj05 | 155:80e7c7ff8aaf | 86 | gPC.baud(9600); |
shreeshas95 | 0:f016e9e8d48b | 87 | |
shreeshas95 | 0:f016e9e8d48b | 88 | // COMMON SPI |
ee12b079 | 149:8e4155426581 | 89 | // spi.format(8,0); |
ee12b079 | 149:8e4155426581 | 90 | // spi.frequency(1000000); |
ee12b079 | 149:8e4155426581 | 91 | // |
ee12b079 | 149:8e4155426581 | 92 | // // SD CARD |
ee12b079 | 149:8e4155426581 | 93 | // cs_sd = 1; |
ee12b079 | 149:8e4155426581 | 94 | // gCS_RTC = 1; |
ee12b079 | 149:8e4155426581 | 95 | // gCS_ADF = 1; |
ee12b079 | 149:8e4155426581 | 96 | // |
ee12b079 | 149:8e4155426581 | 97 | // //FCTN_CDMS_INIT_RTC();/* rtc initialization*/ |
ee12b079 | 149:8e4155426581 | 98 | // #if SDCARD |
ee12b079 | 149:8e4155426581 | 99 | // FCTN_CDMS_SD_INIT();/* sd card initialization*/ |
ee12b079 | 149:8e4155426581 | 100 | // #endif |
ee12b079 | 149:8e4155426581 | 101 | // |
ee12b079 | 149:8e4155426581 | 102 | // #if DEBUG |
ee12b079 | 149:8e4155426581 | 103 | // gPC.puts("welcome to mng_tmtc\r\n"); |
ee12b079 | 149:8e4155426581 | 104 | // #endif |
ee12b079 | 149:8e4155426581 | 105 | // |
ee12b079 | 149:8e4155426581 | 106 | // // COM_MNG_TMTC THREAD |
ee12b079 | 149:8e4155426581 | 107 | // gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN); |
ee12b079 | 149:8e4155426581 | 108 | // gCOM_MNG_TMTC_THREAD->set_priority(osPriorityAboveNormal); |
ee12b079 | 149:8e4155426581 | 109 | // #if DEBUG |
ee12b079 | 149:8e4155426581 | 110 | // gPC.puts("allocating threads\r\n"); |
ee12b079 | 149:8e4155426581 | 111 | // #endif |
ee12b079 | 149:8e4155426581 | 112 | // #if SDCARD |
ee12b079 | 149:8e4155426581 | 113 | // gSCIENCE_THREAD = new Thread(SCIENCE_FUN); |
ee12b079 | 149:8e4155426581 | 114 | // // gPC.puts("step one complete\r\n"); |
ee12b079 | 149:8e4155426581 | 115 | // gSCIENCE_THREAD->set_priority(osPriorityBelowNormal); |
ee12b079 | 149:8e4155426581 | 116 | // #endif |
ee12b079 | 149:8e4155426581 | 117 | // |
ee12b079 | 149:8e4155426581 | 118 | // #if DEBUG |
ee12b079 | 149:8e4155426581 | 119 | // gPC.puts("competed allocating threads\r\n"); |
ee12b079 | 149:8e4155426581 | 120 | // #endif |
ee12b079 | 149:8e4155426581 | 121 | // |
shreeshas95 | 0:f016e9e8d48b | 122 | // *******************INITIALISATIONS END******************** |
shreeshas95 | 0:f016e9e8d48b | 123 | |
ee12b079 | 112:b8991d9e3b6c | 124 | //RtosTimer gCDMS_HK_TIMER(FCTN_CDMS_HK_MAIN, osTimerPeriodic); |
ee12b079 | 112:b8991d9e3b6c | 125 | //gCDMS_HK_TIMER.start(5000); |
ee12b079 | 149:8e4155426581 | 126 | |
prasanthbj05 | 155:80e7c7ff8aaf | 127 | uint8_t TC[11] = {0x1, 0x60, 0x62, 0x00, 0x01, 0x0, 0x0, 0x0, 0x0, 0x1d, 0xd9}; |
prasanthbj05 | 155:80e7c7ff8aaf | 128 | |
prasanthbj05 | 155:80e7c7ff8aaf | 129 | //uint8_t hk_verify[4]; |
ee12b079 | 154:e808cdb56239 | 130 | printf("\n\r sending tc\n"); |
prasanthbj05 | 155:80e7c7ff8aaf | 131 | //while(1) |
prasanthbj05 | 155:80e7c7ff8aaf | 132 | //{ |
prasanthbj05 | 155:80e7c7ff8aaf | 133 | //if(ii) |
prasanthbj05 | 155:80e7c7ff8aaf | 134 | //{ |
prasanthbj05 | 155:80e7c7ff8aaf | 135 | //TC[11] = {0x1, 0x60, 0x61, 0x15, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1d, 0xd9}; |
prasanthbj05 | 155:80e7c7ff8aaf | 136 | wait(10); |
ee12b079 | 154:e808cdb56239 | 137 | FCTN_I2C_WRITE((char*)TC,TC_SHORT_SIZE); |
ee12b079 | 149:8e4155426581 | 138 | |
ee12b079 | 149:8e4155426581 | 139 | wait(1); //TimeOut instead of wait |
prasanthbj05 | 155:80e7c7ff8aaf | 140 | if(BAE_I2C_GPIO == 1) |
ee12b079 | 149:8e4155426581 | 141 | { |
ee12b079 | 149:8e4155426581 | 142 | |
ee12b079 | 154:e808cdb56239 | 143 | // printf("receiving...\r\n"); |
ee12b079 | 149:8e4155426581 | 144 | FCTN_I2C_READ((char*)TM,TM_LONG_SIZE); |
ee12b079 | 149:8e4155426581 | 145 | //printf("%s", tm_pointer->TM_string); |
ee12b079 | 149:8e4155426581 | 146 | } |
ee12b079 | 149:8e4155426581 | 147 | else |
ee12b079 | 149:8e4155426581 | 148 | { |
ee12b079 | 149:8e4155426581 | 149 | gPC.printf("bae_INTR NOT HIGH"); |
prasanthbj05 | 155:80e7c7ff8aaf | 150 | } |
prasanthbj05 | 155:80e7c7ff8aaf | 151 | |
prasanthbj05 | 155:80e7c7ff8aaf | 152 | |
prasanthbj05 | 155:80e7c7ff8aaf | 153 | /* Code to verify HK DATA */ |
prasanthbj05 | 155:80e7c7ff8aaf | 154 | verifyHK_DATA(); |
prasanthbj05 | 155:80e7c7ff8aaf | 155 | |
prasanthbj05 | 155:80e7c7ff8aaf | 156 | |
prasanthbj05 | 155:80e7c7ff8aaf | 157 | |
prasanthbj05 | 155:80e7c7ff8aaf | 158 | //} |
prasanthbj05 | 155:80e7c7ff8aaf | 159 | //else |
prasanthbj05 | 155:80e7c7ff8aaf | 160 | //{ |
prasanthbj05 | 155:80e7c7ff8aaf | 161 | /*TC[11] = {0x1, 0x60, 0x81, 0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1d, 0xd9}; |
prasanthbj05 | 155:80e7c7ff8aaf | 162 | wait(10); |
prasanthbj05 | 155:80e7c7ff8aaf | 163 | FCTN_I2C_WRITE((char*)TC,TC_SHORT_SIZE); |
prasanthbj05 | 155:80e7c7ff8aaf | 164 | |
prasanthbj05 | 155:80e7c7ff8aaf | 165 | wait(1); //TimeOut instead of wait |
prasanthbj05 | 155:80e7c7ff8aaf | 166 | if(BAE_I2C_GPIO == 1) |
prasanthbj05 | 155:80e7c7ff8aaf | 167 | { |
prasanthbj05 | 155:80e7c7ff8aaf | 168 | |
prasanthbj05 | 155:80e7c7ff8aaf | 169 | // printf("receiving...\r\n"); |
prasanthbj05 | 155:80e7c7ff8aaf | 170 | FCTN_I2C_READ((char*)TM,TM_LONG_SIZE); |
prasanthbj05 | 155:80e7c7ff8aaf | 171 | //printf("%s", tm_pointer->TM_string); |
prasanthbj05 | 155:80e7c7ff8aaf | 172 | } |
prasanthbj05 | 155:80e7c7ff8aaf | 173 | else |
prasanthbj05 | 155:80e7c7ff8aaf | 174 | { |
prasanthbj05 | 155:80e7c7ff8aaf | 175 | gPC.printf("bae_INTR NOT HIGH"); |
prasanthbj05 | 155:80e7c7ff8aaf | 176 | }*/ |
prasanthbj05 | 155:80e7c7ff8aaf | 177 | //} |
prasanthbj05 | 155:80e7c7ff8aaf | 178 | |
prasanthbj05 | 155:80e7c7ff8aaf | 179 | //} |
shreeshas95 | 0:f016e9e8d48b | 180 | while(true){ |
ee12b079 | 94:717c7908c822 | 181 | Thread::wait(osWaitForever); |
ee12b079 | 93:4ca92f9775e0 | 182 | //state = gCOM_MNG_TMTC_THREAD->get_state() + '0'; |
ee12b079 | 93:4ca92f9775e0 | 183 | gLEDG = !gLEDG; |
ee12b079 | 93:4ca92f9775e0 | 184 | //gPC.putc(state); |
shreeshas95 | 0:f016e9e8d48b | 185 | } |
shreeshas95 | 0:f016e9e8d48b | 186 | } |