cdms_i2c_hardware_test
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of standaloneworkingi2c_cdms by
main.cpp@156:741ab5dd826d, 2016-04-19 (annotated)
- Committer:
- lakshya
- Date:
- Tue Apr 19 21:30:03 2016 +0000
- Revision:
- 156:741ab5dd826d
- Parent:
- 155:80e7c7ff8aaf
- Child:
- 157:d99f525edc4c
checking
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];*/ |
lakshya | 156:741ab5dd826d | 44 | |
lakshya | 156:741ab5dd826d | 45 | //float input=5.4332; |
lakshya | 156:741ab5dd826d | 46 | uint8_t output[4]; |
lakshya | 156:741ab5dd826d | 47 | uint8_t output1[4]; |
lakshya | 156:741ab5dd826d | 48 | // assert(sizeof(float) == sizeof(uint32_t)); |
lakshya | 156:741ab5dd826d | 49 | // uint32_t* temp = reinterpret_cast<uint32_t*>(&input); |
lakshya | 156:741ab5dd826d | 50 | |
lakshya | 156:741ab5dd826d | 51 | //float* output1 = reinterpret_cast<float*>(temp); |
lakshya | 156:741ab5dd826d | 52 | |
lakshya | 156:741ab5dd826d | 53 | // printf("\n\r %f ", input); |
lakshya | 156:741ab5dd826d | 54 | // std::cout << "\n\r uint32 \t"<<*temp << std::endl; |
lakshya | 156:741ab5dd826d | 55 | |
lakshya | 156:741ab5dd826d | 56 | /* output[0] =(uint8_t )(((*temp)>>24)&0xFF); |
lakshya | 156:741ab5dd826d | 57 | output[1] =(uint8_t ) (((*temp)>>16)&0xFF); |
lakshya | 156:741ab5dd826d | 58 | output[2] =(uint8_t ) (((*temp)>>8)&0xFF); |
lakshya | 156:741ab5dd826d | 59 | output[3] =(uint8_t ) ((*temp) & 0xFF); // verify the logic |
lakshya | 156:741ab5dd826d | 60 | */ |
lakshya | 156:741ab5dd826d | 61 | //printf("\n\r inside %d %d %d %d", output[3],output[2],output[1],output[0]); |
lakshya | 156:741ab5dd826d | 62 | //std:: cout << "\n\r uint8 inside " << output[3] << '\t' << output[2] << '\t' << output[1] << '\t' << output[0] <<std::endl; |
prasanthbj05 | 155:80e7c7ff8aaf | 63 | |
lakshya | 156:741ab5dd826d | 64 | /*convertion back or recheck code*/ |
lakshya | 156:741ab5dd826d | 65 | |
lakshya | 156:741ab5dd826d | 66 | output[0] =TM[42]; |
lakshya | 156:741ab5dd826d | 67 | output[1] =TM[43]; |
lakshya | 156:741ab5dd826d | 68 | output[2] =TM[44]; |
lakshya | 156:741ab5dd826d | 69 | output[3] =TM[45]; // verify the logic |
lakshya | 156:741ab5dd826d | 70 | |
lakshya | 156:741ab5dd826d | 71 | //printf("\n\rthe value is 26\t %x\n",TM[38]); |
lakshya | 156:741ab5dd826d | 72 | // printf("\n\rthe value is 27\t%x\n",TM[39]); |
lakshya | 156:741ab5dd826d | 73 | // printf("\n\rthe value is 28\t%x\n",TM[40]); |
lakshya | 156:741ab5dd826d | 74 | // printf("\n\rthe value is 29\t%x\n",TM[41]); |
lakshya | 156:741ab5dd826d | 75 | |
lakshya | 156:741ab5dd826d | 76 | |
lakshya | 156:741ab5dd826d | 77 | |
prasanthbj05 | 155:80e7c7ff8aaf | 78 | uint32_t input_stage1=0x00000000; |
lakshya | 156:741ab5dd826d | 79 | output1[0]=(uint32_t)(output[0]); |
lakshya | 156:741ab5dd826d | 80 | output1[1]=(uint32_t)(output[1]); |
lakshya | 156:741ab5dd826d | 81 | output1[2]=(uint32_t)(output[2]); |
lakshya | 156:741ab5dd826d | 82 | output1[3]=(uint32_t)(output[3]); |
prasanthbj05 | 155:80e7c7ff8aaf | 83 | |
prasanthbj05 | 155:80e7c7ff8aaf | 84 | //input_stage1=output[3]+(output[2]*(0x100))+(output[1]*(0x10000))+(output[0]*(0x1000000)); |
prasanthbj05 | 155:80e7c7ff8aaf | 85 | input_stage1=(output1[0]<<24) | (output1[1]<<16) | (output1[2]<<8) | (output1[3]); |
prasanthbj05 | 155:80e7c7ff8aaf | 86 | |
prasanthbj05 | 155:80e7c7ff8aaf | 87 | |
prasanthbj05 | 155:80e7c7ff8aaf | 88 | assert(sizeof(float) == sizeof(uint32_t)); |
prasanthbj05 | 155:80e7c7ff8aaf | 89 | float* temp1 = reinterpret_cast<float*>(&input_stage1); |
prasanthbj05 | 155:80e7c7ff8aaf | 90 | |
prasanthbj05 | 155:80e7c7ff8aaf | 91 | printf("\n\r the value is: %f \n",*temp1); |
lakshya | 156:741ab5dd826d | 92 | |
lakshya | 156:741ab5dd826d | 93 | |
lakshya | 156:741ab5dd826d | 94 | //___________________________________________________- |
lakshya | 156:741ab5dd826d | 95 | /* |
lakshya | 156:741ab5dd826d | 96 | float input =5.4367; |
lakshya | 156:741ab5dd826d | 97 | //uint32_t tem; |
lakshya | 156:741ab5dd826d | 98 | uint8_t Tmm[4]; |
lakshya | 156:741ab5dd826d | 99 | assert(sizeof(float) == sizeof(uint32_t)); |
lakshya | 156:741ab5dd826d | 100 | uint32_t* tem = reinterpret_cast<uint32_t*>(&input); |
lakshya | 156:741ab5dd826d | 101 | |
lakshya | 156:741ab5dd826d | 102 | Tmm[0] =(uint8_t )(((*tem)>>24)&0xFF); |
lakshya | 156:741ab5dd826d | 103 | Tmm[2] =(uint8_t ) (((*tem)>>16)&0xFF); |
lakshya | 156:741ab5dd826d | 104 | Tmm[1] =(uint8_t ) (((*tem)>>8)&0xFF); |
lakshya | 156:741ab5dd826d | 105 | Tmm[3] =(uint8_t ) ((*tem) & 0xFF); |
lakshya | 156:741ab5dd826d | 106 | |
lakshya | 156:741ab5dd826d | 107 | |
lakshya | 156:741ab5dd826d | 108 | uint8_t output1[4]; |
lakshya | 156:741ab5dd826d | 109 | //uint32_t input_stage1=0x00000000; |
lakshya | 156:741ab5dd826d | 110 | output1[0]=(uint32_t)(Tmm[0]); |
lakshya | 156:741ab5dd826d | 111 | output1[1]=(uint32_t)(Tmm[1]); |
lakshya | 156:741ab5dd826d | 112 | output1[2]=(uint32_t)(Tmm[2]); |
lakshya | 156:741ab5dd826d | 113 | output1[3]=(uint32_t)(Tmm[3]); |
lakshya | 156:741ab5dd826d | 114 | |
lakshya | 156:741ab5dd826d | 115 | |
lakshya | 156:741ab5dd826d | 116 | //input_stage1=output[3]+(output[2]*(0x100))+(output[1]*(0x10000))+(output[0]*(0x1000000)); |
lakshya | 156:741ab5dd826d | 117 | uint32_t input_stage1=(output1[0]<<24) | (output1[1]<<16) | (output1[2]<<8) | (output1[3]); |
lakshya | 156:741ab5dd826d | 118 | |
lakshya | 156:741ab5dd826d | 119 | |
lakshya | 156:741ab5dd826d | 120 | //assert(sizeof(float) == sizeof(uint32_t)); |
lakshya | 156:741ab5dd826d | 121 | float* value = reinterpret_cast<float*>(&input_stage1); |
lakshya | 156:741ab5dd826d | 122 | printf("\n\rthe actual value: %f\n",input); |
lakshya | 156:741ab5dd826d | 123 | printf("\n\r the value is: %f \n",&value); |
lakshya | 156:741ab5dd826d | 124 | */ |
prasanthbj05 | 155:80e7c7ff8aaf | 125 | } |
shreeshas95 | 0:f016e9e8d48b | 126 | int main() |
shreeshas95 | 0:f016e9e8d48b | 127 | { |
ee12b079 | 148:e6c7d4f87704 | 128 | CDMS_I2C_GPIO = 0; |
ee12b079 | 148:e6c7d4f87704 | 129 | |
ee12b079 | 94:717c7908c822 | 130 | //gLEDR = 1; |
ee12b079 | 93:4ca92f9775e0 | 131 | |
shreeshas95 | 0:f016e9e8d48b | 132 | // ******************INITIALISATIONS START****************** |
shreeshas95 | 0:f016e9e8d48b | 133 | // COM RX |
shreeshas95 | 0:f016e9e8d48b | 134 | RX1M.baud(1200); |
shreeshas95 | 0:f016e9e8d48b | 135 | gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE; |
shreeshas95 | 0:f016e9e8d48b | 136 | gRX_HEAD_DATA_NODE->next_node = NULL; |
shreeshas95 | 0:f016e9e8d48b | 137 | gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE; |
shreeshas95 | 2:2caf2a9a13aa | 138 | gRX_COUNT = 0; |
shreeshas95 | 2:2caf2a9a13aa | 139 | // gRX_CURRENT_PTR = gRX_CURRENT_DATA_NODE->values; |
shreeshas95 | 0:f016e9e8d48b | 140 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 0:f016e9e8d48b | 141 | |
ee12b079 | 136:8074893cd24e | 142 | #if I2c |
ee12b079 | 129:d5b53088270b | 143 | //I2C to Payload (depends on pl interrupt design) |
ee12b079 | 131:d4a4461214ad | 144 | PYLD_I2C_Int.rise(&isr_pyldtm); |
ee12b079 | 148:e6c7d4f87704 | 145 | |
ee12b079 | 136:8074893cd24e | 146 | #endif |
prasanthbj05 | 155:80e7c7ff8aaf | 147 | master.frequency(400000); |
shreeshas95 | 0:f016e9e8d48b | 148 | // DEBUG |
ee12b079 | 85:b9beee1a7a3e | 149 | //gPC.puts("welcome to mng_tm_tc\r\n"); |
prasanthbj05 | 155:80e7c7ff8aaf | 150 | gPC.baud(9600); |
shreeshas95 | 0:f016e9e8d48b | 151 | |
shreeshas95 | 0:f016e9e8d48b | 152 | // COMMON SPI |
ee12b079 | 149:8e4155426581 | 153 | // spi.format(8,0); |
ee12b079 | 149:8e4155426581 | 154 | // spi.frequency(1000000); |
ee12b079 | 149:8e4155426581 | 155 | // |
ee12b079 | 149:8e4155426581 | 156 | // // SD CARD |
ee12b079 | 149:8e4155426581 | 157 | // cs_sd = 1; |
ee12b079 | 149:8e4155426581 | 158 | // gCS_RTC = 1; |
ee12b079 | 149:8e4155426581 | 159 | // gCS_ADF = 1; |
ee12b079 | 149:8e4155426581 | 160 | // |
ee12b079 | 149:8e4155426581 | 161 | // //FCTN_CDMS_INIT_RTC();/* rtc initialization*/ |
ee12b079 | 149:8e4155426581 | 162 | // #if SDCARD |
ee12b079 | 149:8e4155426581 | 163 | // FCTN_CDMS_SD_INIT();/* sd card initialization*/ |
ee12b079 | 149:8e4155426581 | 164 | // #endif |
ee12b079 | 149:8e4155426581 | 165 | // |
ee12b079 | 149:8e4155426581 | 166 | // #if DEBUG |
ee12b079 | 149:8e4155426581 | 167 | // gPC.puts("welcome to mng_tmtc\r\n"); |
ee12b079 | 149:8e4155426581 | 168 | // #endif |
ee12b079 | 149:8e4155426581 | 169 | // |
ee12b079 | 149:8e4155426581 | 170 | // // COM_MNG_TMTC THREAD |
ee12b079 | 149:8e4155426581 | 171 | // gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN); |
ee12b079 | 149:8e4155426581 | 172 | // gCOM_MNG_TMTC_THREAD->set_priority(osPriorityAboveNormal); |
ee12b079 | 149:8e4155426581 | 173 | // #if DEBUG |
ee12b079 | 149:8e4155426581 | 174 | // gPC.puts("allocating threads\r\n"); |
ee12b079 | 149:8e4155426581 | 175 | // #endif |
ee12b079 | 149:8e4155426581 | 176 | // #if SDCARD |
ee12b079 | 149:8e4155426581 | 177 | // gSCIENCE_THREAD = new Thread(SCIENCE_FUN); |
ee12b079 | 149:8e4155426581 | 178 | // // gPC.puts("step one complete\r\n"); |
ee12b079 | 149:8e4155426581 | 179 | // gSCIENCE_THREAD->set_priority(osPriorityBelowNormal); |
ee12b079 | 149:8e4155426581 | 180 | // #endif |
ee12b079 | 149:8e4155426581 | 181 | // |
ee12b079 | 149:8e4155426581 | 182 | // #if DEBUG |
ee12b079 | 149:8e4155426581 | 183 | // gPC.puts("competed allocating threads\r\n"); |
ee12b079 | 149:8e4155426581 | 184 | // #endif |
ee12b079 | 149:8e4155426581 | 185 | // |
shreeshas95 | 0:f016e9e8d48b | 186 | // *******************INITIALISATIONS END******************** |
shreeshas95 | 0:f016e9e8d48b | 187 | |
ee12b079 | 112:b8991d9e3b6c | 188 | //RtosTimer gCDMS_HK_TIMER(FCTN_CDMS_HK_MAIN, osTimerPeriodic); |
ee12b079 | 112:b8991d9e3b6c | 189 | //gCDMS_HK_TIMER.start(5000); |
ee12b079 | 149:8e4155426581 | 190 | |
lakshya | 156:741ab5dd826d | 191 | uint8_t TC[11] = {0x1, 0x60, 0x81, 0x34, 0x01, 0x0, 0x0, 0x0, 0x0, 0x1d, 0xd9}; |
lakshya | 156:741ab5dd826d | 192 | /*tc[2]=62,tc[3]=00*/ |
prasanthbj05 | 155:80e7c7ff8aaf | 193 | //uint8_t hk_verify[4]; |
ee12b079 | 154:e808cdb56239 | 194 | printf("\n\r sending tc\n"); |
lakshya | 156:741ab5dd826d | 195 | printf("\n\rservicetype:servicesubtype = %x \n PID's =%x \n",TC[2],TC[3]); |
prasanthbj05 | 155:80e7c7ff8aaf | 196 | //while(1) |
prasanthbj05 | 155:80e7c7ff8aaf | 197 | //{ |
prasanthbj05 | 155:80e7c7ff8aaf | 198 | //if(ii) |
prasanthbj05 | 155:80e7c7ff8aaf | 199 | //{ |
prasanthbj05 | 155:80e7c7ff8aaf | 200 | //TC[11] = {0x1, 0x60, 0x61, 0x15, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1d, 0xd9}; |
prasanthbj05 | 155:80e7c7ff8aaf | 201 | wait(10); |
ee12b079 | 154:e808cdb56239 | 202 | FCTN_I2C_WRITE((char*)TC,TC_SHORT_SIZE); |
ee12b079 | 149:8e4155426581 | 203 | |
ee12b079 | 149:8e4155426581 | 204 | wait(1); //TimeOut instead of wait |
prasanthbj05 | 155:80e7c7ff8aaf | 205 | if(BAE_I2C_GPIO == 1) |
ee12b079 | 149:8e4155426581 | 206 | { |
ee12b079 | 149:8e4155426581 | 207 | |
ee12b079 | 154:e808cdb56239 | 208 | // printf("receiving...\r\n"); |
ee12b079 | 149:8e4155426581 | 209 | FCTN_I2C_READ((char*)TM,TM_LONG_SIZE); |
ee12b079 | 149:8e4155426581 | 210 | //printf("%s", tm_pointer->TM_string); |
ee12b079 | 149:8e4155426581 | 211 | } |
ee12b079 | 149:8e4155426581 | 212 | else |
ee12b079 | 149:8e4155426581 | 213 | { |
ee12b079 | 149:8e4155426581 | 214 | gPC.printf("bae_INTR NOT HIGH"); |
prasanthbj05 | 155:80e7c7ff8aaf | 215 | } |
prasanthbj05 | 155:80e7c7ff8aaf | 216 | |
prasanthbj05 | 155:80e7c7ff8aaf | 217 | |
prasanthbj05 | 155:80e7c7ff8aaf | 218 | /* Code to verify HK DATA */ |
prasanthbj05 | 155:80e7c7ff8aaf | 219 | verifyHK_DATA(); |
prasanthbj05 | 155:80e7c7ff8aaf | 220 | |
prasanthbj05 | 155:80e7c7ff8aaf | 221 | |
prasanthbj05 | 155:80e7c7ff8aaf | 222 | |
prasanthbj05 | 155:80e7c7ff8aaf | 223 | //} |
prasanthbj05 | 155:80e7c7ff8aaf | 224 | //else |
prasanthbj05 | 155:80e7c7ff8aaf | 225 | //{ |
prasanthbj05 | 155:80e7c7ff8aaf | 226 | /*TC[11] = {0x1, 0x60, 0x81, 0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1d, 0xd9}; |
prasanthbj05 | 155:80e7c7ff8aaf | 227 | wait(10); |
prasanthbj05 | 155:80e7c7ff8aaf | 228 | FCTN_I2C_WRITE((char*)TC,TC_SHORT_SIZE); |
prasanthbj05 | 155:80e7c7ff8aaf | 229 | |
prasanthbj05 | 155:80e7c7ff8aaf | 230 | wait(1); //TimeOut instead of wait |
prasanthbj05 | 155:80e7c7ff8aaf | 231 | if(BAE_I2C_GPIO == 1) |
prasanthbj05 | 155:80e7c7ff8aaf | 232 | { |
prasanthbj05 | 155:80e7c7ff8aaf | 233 | |
prasanthbj05 | 155:80e7c7ff8aaf | 234 | // printf("receiving...\r\n"); |
prasanthbj05 | 155:80e7c7ff8aaf | 235 | FCTN_I2C_READ((char*)TM,TM_LONG_SIZE); |
prasanthbj05 | 155:80e7c7ff8aaf | 236 | //printf("%s", tm_pointer->TM_string); |
prasanthbj05 | 155:80e7c7ff8aaf | 237 | } |
prasanthbj05 | 155:80e7c7ff8aaf | 238 | else |
prasanthbj05 | 155:80e7c7ff8aaf | 239 | { |
prasanthbj05 | 155:80e7c7ff8aaf | 240 | gPC.printf("bae_INTR NOT HIGH"); |
prasanthbj05 | 155:80e7c7ff8aaf | 241 | }*/ |
prasanthbj05 | 155:80e7c7ff8aaf | 242 | //} |
prasanthbj05 | 155:80e7c7ff8aaf | 243 | |
prasanthbj05 | 155:80e7c7ff8aaf | 244 | //} |
shreeshas95 | 0:f016e9e8d48b | 245 | while(true){ |
ee12b079 | 94:717c7908c822 | 246 | Thread::wait(osWaitForever); |
ee12b079 | 93:4ca92f9775e0 | 247 | //state = gCOM_MNG_TMTC_THREAD->get_state() + '0'; |
ee12b079 | 93:4ca92f9775e0 | 248 | gLEDG = !gLEDG; |
ee12b079 | 93:4ca92f9775e0 | 249 | //gPC.putc(state); |
shreeshas95 | 0:f016e9e8d48b | 250 | } |
shreeshas95 | 0:f016e9e8d48b | 251 | } |