I2C code testing

**
Dependencies:
**
FreescaleIAP
SimpleDMA
mbed-rtos
mbed

**Fork of**
COM_MNG_TMTC_SIMPLE_pl123
by

## COM_SND_TM_functions.h@139:17353d6311ce, 2016-03-30 (annotated)

- Committer:
- ee12b079
- Date:
- Wed Mar 30 14:04:48 2016 +0000
- Revision:
- 139:17353d6311ce
- Parent:
- 1:a0055b3280c8

PL I2C worked

### Who changed what in which revision?

User | Revision | Line number | New contents of line |
---|---|---|---|

shreeshas95 | 1:a0055b3280c8 | 1 | // ***************************************** CONVOLUTION ***************************************** |

shreeshas95 | 0:f016e9e8d48b | 2 | class Convolution{ |

shreeshas95 | 0:f016e9e8d48b | 3 | |

shreeshas95 | 0:f016e9e8d48b | 4 | private: |

shreeshas95 | 0:f016e9e8d48b | 5 | typedef struct ConvNode{ |

shreeshas95 | 0:f016e9e8d48b | 6 | //next state |

shreeshas95 | 0:f016e9e8d48b | 7 | //format : 8 bits mapped as [1]xxxx [0]xxxx |

shreeshas95 | 0:f016e9e8d48b | 8 | unsigned char nextState; |

shreeshas95 | 0:f016e9e8d48b | 9 | |

shreeshas95 | 0:f016e9e8d48b | 10 | //output |

shreeshas95 | 0:f016e9e8d48b | 11 | // format : 8 bits mapped as |

shreeshas95 | 0:f016e9e8d48b | 12 | // **** xxxx{2} [1]-[0] {1} [1]-[0] i.e. ****xxxx |

shreeshas95 | 0:f016e9e8d48b | 13 | // x = data, * = junk |

shreeshas95 | 0:f016e9e8d48b | 14 | unsigned char output; |

shreeshas95 | 0:f016e9e8d48b | 15 | }ConvNode; |

shreeshas95 | 0:f016e9e8d48b | 16 | |

shreeshas95 | 0:f016e9e8d48b | 17 | ConvNode convStateList[16]; |

shreeshas95 | 0:f016e9e8d48b | 18 | |

shreeshas95 | 0:f016e9e8d48b | 19 | public: |

shreeshas95 | 0:f016e9e8d48b | 20 | /* |

shreeshas95 | 0:f016e9e8d48b | 21 | @brief: Constructor : Initialise all the variables |

shreeshas95 | 0:f016e9e8d48b | 22 | @param: none |

shreeshas95 | 0:f016e9e8d48b | 23 | @return: none |

shreeshas95 | 0:f016e9e8d48b | 24 | */ |

shreeshas95 | 0:f016e9e8d48b | 25 | Convolution(){ |

shreeshas95 | 0:f016e9e8d48b | 26 | |

shreeshas95 | 0:f016e9e8d48b | 27 | convStateList[0].nextState = 0x10; |

shreeshas95 | 0:f016e9e8d48b | 28 | convStateList[1].nextState = 0x32; |

shreeshas95 | 0:f016e9e8d48b | 29 | convStateList[2].nextState = 0x54; |

shreeshas95 | 0:f016e9e8d48b | 30 | convStateList[3].nextState = 0x76; |

shreeshas95 | 0:f016e9e8d48b | 31 | convStateList[4].nextState = 0x98; |

shreeshas95 | 0:f016e9e8d48b | 32 | convStateList[5].nextState = 0xBA; |

shreeshas95 | 0:f016e9e8d48b | 33 | convStateList[6].nextState = 0xDC; |

shreeshas95 | 0:f016e9e8d48b | 34 | convStateList[7].nextState = 0xFE; |

shreeshas95 | 0:f016e9e8d48b | 35 | convStateList[8].nextState = 0x10; |

shreeshas95 | 0:f016e9e8d48b | 36 | convStateList[9].nextState = 0x32; |

shreeshas95 | 0:f016e9e8d48b | 37 | convStateList[10].nextState = 0x54; |

shreeshas95 | 0:f016e9e8d48b | 38 | convStateList[11].nextState = 0x76; |

shreeshas95 | 0:f016e9e8d48b | 39 | convStateList[12].nextState = 0x98; |

shreeshas95 | 0:f016e9e8d48b | 40 | convStateList[13].nextState = 0xBA; |

shreeshas95 | 0:f016e9e8d48b | 41 | convStateList[14].nextState = 0xDC; |

shreeshas95 | 0:f016e9e8d48b | 42 | convStateList[15].nextState = 0xFE; |

shreeshas95 | 0:f016e9e8d48b | 43 | |

shreeshas95 | 0:f016e9e8d48b | 44 | convStateList[0].output = 0x0A; |

shreeshas95 | 0:f016e9e8d48b | 45 | convStateList[1].output = 0x06; |

shreeshas95 | 0:f016e9e8d48b | 46 | convStateList[2].output = 0x06; |

shreeshas95 | 0:f016e9e8d48b | 47 | convStateList[3].output = 0x0A; |

shreeshas95 | 0:f016e9e8d48b | 48 | convStateList[4].output = 0x09; |

shreeshas95 | 0:f016e9e8d48b | 49 | convStateList[5].output = 0x05; |

shreeshas95 | 0:f016e9e8d48b | 50 | convStateList[6].output = 0x05; |

shreeshas95 | 0:f016e9e8d48b | 51 | convStateList[7].output = 0x09; |

shreeshas95 | 0:f016e9e8d48b | 52 | convStateList[8].output = 0x05; |

shreeshas95 | 0:f016e9e8d48b | 53 | convStateList[9].output = 0x09; |

shreeshas95 | 0:f016e9e8d48b | 54 | convStateList[10].output = 0x09; |

shreeshas95 | 0:f016e9e8d48b | 55 | convStateList[11].output = 0x05; |

shreeshas95 | 0:f016e9e8d48b | 56 | convStateList[12].output = 0x06; |

shreeshas95 | 0:f016e9e8d48b | 57 | convStateList[13].output = 0x0A; |

shreeshas95 | 0:f016e9e8d48b | 58 | convStateList[14].output = 0x0A; |

shreeshas95 | 0:f016e9e8d48b | 59 | convStateList[15].output = 0x06; |

shreeshas95 | 0:f016e9e8d48b | 60 | } |

shreeshas95 | 0:f016e9e8d48b | 61 | |

shreeshas95 | 0:f016e9e8d48b | 62 | |

shreeshas95 | 0:f016e9e8d48b | 63 | /* |

shreeshas95 | 0:f016e9e8d48b | 64 | @brief: convolution encode the input bytes : in sync with => (1-TM-Frame -> 2-T-Frame) |

shreeshas95 | 0:f016e9e8d48b | 65 | @param: inPtr : pointer to input unsigned char array |

shreeshas95 | 0:f016e9e8d48b | 66 | inLength : length in bytes of input array |

shreeshas95 | 0:f016e9e8d48b | 67 | outPtr : pointer to the output bytes, define it outside the function |

shreeshas95 | 0:f016e9e8d48b | 68 | outLength : length of output array in bytes [call by reference, edited inside the function] |

shreeshas95 | 0:f016e9e8d48b | 69 | @return: none |

shreeshas95 | 0:f016e9e8d48b | 70 | */ |

shreeshas95 | 0:f016e9e8d48b | 71 | void convolutionEncode(unsigned char *input, unsigned char *output){ |

shreeshas95 | 0:f016e9e8d48b | 72 | |

shreeshas95 | 0:f016e9e8d48b | 73 | // cout << "inside convolution" << endl; |

shreeshas95 | 0:f016e9e8d48b | 74 | |

shreeshas95 | 0:f016e9e8d48b | 75 | unsigned int convState = 0; |

shreeshas95 | 0:f016e9e8d48b | 76 | |

shreeshas95 | 0:f016e9e8d48b | 77 | int inBit = 7; |

shreeshas95 | 0:f016e9e8d48b | 78 | unsigned int inByte = 0; |

shreeshas95 | 0:f016e9e8d48b | 79 | |

shreeshas95 | 0:f016e9e8d48b | 80 | unsigned int outState = 0; |

shreeshas95 | 0:f016e9e8d48b | 81 | unsigned int outByte = 0; |

shreeshas95 | 0:f016e9e8d48b | 82 | |

shreeshas95 | 0:f016e9e8d48b | 83 | for(unsigned int j = 0 ; j < 536 ; ++j){ |

shreeshas95 | 0:f016e9e8d48b | 84 | // printf("j = %u, inByte = %u\n", j, inByte); |

shreeshas95 | 0:f016e9e8d48b | 85 | // read a new bit from input stream |

shreeshas95 | 0:f016e9e8d48b | 86 | // cout << "inByte " <<inByte; |

shreeshas95 | 0:f016e9e8d48b | 87 | unsigned char tempBit = (input[inByte] >> inBit) & 1; |

shreeshas95 | 0:f016e9e8d48b | 88 | --inBit; |

shreeshas95 | 0:f016e9e8d48b | 89 | |

shreeshas95 | 0:f016e9e8d48b | 90 | // convolute and write output |

shreeshas95 | 0:f016e9e8d48b | 91 | switch(outState){ |

shreeshas95 | 0:f016e9e8d48b | 92 | case 0: |

shreeshas95 | 0:f016e9e8d48b | 93 | outState = 2; |

shreeshas95 | 0:f016e9e8d48b | 94 | output[outByte] = ( (convStateList[convState].output >> tempBit) & 1 ) << 7; |

shreeshas95 | 0:f016e9e8d48b | 95 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 6; |

shreeshas95 | 0:f016e9e8d48b | 96 | break; |

shreeshas95 | 0:f016e9e8d48b | 97 | case 2: |

shreeshas95 | 0:f016e9e8d48b | 98 | outState = 4; |

shreeshas95 | 0:f016e9e8d48b | 99 | output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 5; |

shreeshas95 | 0:f016e9e8d48b | 100 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 4; |

shreeshas95 | 0:f016e9e8d48b | 101 | break; |

shreeshas95 | 0:f016e9e8d48b | 102 | case 4: |

shreeshas95 | 0:f016e9e8d48b | 103 | outState = 6; |

shreeshas95 | 0:f016e9e8d48b | 104 | output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 3; |

shreeshas95 | 0:f016e9e8d48b | 105 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 2; |

shreeshas95 | 0:f016e9e8d48b | 106 | break; |

shreeshas95 | 0:f016e9e8d48b | 107 | case 6: |

shreeshas95 | 0:f016e9e8d48b | 108 | outState = 0; |

shreeshas95 | 0:f016e9e8d48b | 109 | output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 1; |

shreeshas95 | 0:f016e9e8d48b | 110 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ); |

shreeshas95 | 0:f016e9e8d48b | 111 | ++outByte; |

shreeshas95 | 0:f016e9e8d48b | 112 | output[outByte] = 0x00; |

shreeshas95 | 0:f016e9e8d48b | 113 | break; |

shreeshas95 | 0:f016e9e8d48b | 114 | } |

shreeshas95 | 0:f016e9e8d48b | 115 | |

shreeshas95 | 0:f016e9e8d48b | 116 | // next state transition |

shreeshas95 | 0:f016e9e8d48b | 117 | switch(tempBit){ |

shreeshas95 | 0:f016e9e8d48b | 118 | case 0: |

shreeshas95 | 0:f016e9e8d48b | 119 | convState = (convStateList[convState].nextState) & 0xF; |

shreeshas95 | 0:f016e9e8d48b | 120 | break; |

shreeshas95 | 0:f016e9e8d48b | 121 | case 1: |

shreeshas95 | 0:f016e9e8d48b | 122 | convState = (convStateList[convState].nextState >> 4) & 0xF; |

shreeshas95 | 0:f016e9e8d48b | 123 | break; |

shreeshas95 | 0:f016e9e8d48b | 124 | } |

shreeshas95 | 0:f016e9e8d48b | 125 | |

shreeshas95 | 0:f016e9e8d48b | 126 | if(inBit == -1){ |

shreeshas95 | 0:f016e9e8d48b | 127 | // printf("in byte = %u\n", inByte); |

shreeshas95 | 0:f016e9e8d48b | 128 | ++inByte; |

shreeshas95 | 0:f016e9e8d48b | 129 | inBit = 7; |

shreeshas95 | 0:f016e9e8d48b | 130 | } |

shreeshas95 | 0:f016e9e8d48b | 131 | |

shreeshas95 | 0:f016e9e8d48b | 132 | } |

shreeshas95 | 0:f016e9e8d48b | 133 | |

shreeshas95 | 0:f016e9e8d48b | 134 | // printf("normal iteration complete, outByte = %u\n", outByte); |

shreeshas95 | 0:f016e9e8d48b | 135 | |

shreeshas95 | 0:f016e9e8d48b | 136 | for(unsigned int j = 0 ; j < 4 ; ++j){ |

shreeshas95 | 0:f016e9e8d48b | 137 | // printf("j = %u\n, outByte = %u\n", j, outByte); |

shreeshas95 | 0:f016e9e8d48b | 138 | // append zero at the end |

shreeshas95 | 0:f016e9e8d48b | 139 | switch(outState){ |

shreeshas95 | 0:f016e9e8d48b | 140 | case 0: |

shreeshas95 | 0:f016e9e8d48b | 141 | outState = 2; |

shreeshas95 | 0:f016e9e8d48b | 142 | output[outByte] = ( (convStateList[convState].output) & 1 ) << 7; |

shreeshas95 | 0:f016e9e8d48b | 143 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 6; |

shreeshas95 | 0:f016e9e8d48b | 144 | break; |

shreeshas95 | 0:f016e9e8d48b | 145 | case 2: |

shreeshas95 | 0:f016e9e8d48b | 146 | outState = 4; |

shreeshas95 | 0:f016e9e8d48b | 147 | output[outByte] += ( (convStateList[convState].output) & 1 ) << 5; |

shreeshas95 | 0:f016e9e8d48b | 148 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 4; |

shreeshas95 | 0:f016e9e8d48b | 149 | break; |

shreeshas95 | 0:f016e9e8d48b | 150 | case 4: |

shreeshas95 | 0:f016e9e8d48b | 151 | outState = 6; |

shreeshas95 | 0:f016e9e8d48b | 152 | output[outByte] += ( (convStateList[convState].output ) & 1 ) << 3; |

shreeshas95 | 0:f016e9e8d48b | 153 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 2; |

shreeshas95 | 0:f016e9e8d48b | 154 | break; |

shreeshas95 | 0:f016e9e8d48b | 155 | case 6: |

shreeshas95 | 0:f016e9e8d48b | 156 | outState = 0; |

shreeshas95 | 0:f016e9e8d48b | 157 | output[outByte] += ( (convStateList[convState].output ) & 1 ) << 1; |

shreeshas95 | 0:f016e9e8d48b | 158 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ); |

shreeshas95 | 0:f016e9e8d48b | 159 | ++outByte; |

shreeshas95 | 0:f016e9e8d48b | 160 | // printf("outByte @ end of switch = %u\n", outByte); |

shreeshas95 | 0:f016e9e8d48b | 161 | break; |

shreeshas95 | 0:f016e9e8d48b | 162 | } |

shreeshas95 | 0:f016e9e8d48b | 163 | // next state transition |

shreeshas95 | 0:f016e9e8d48b | 164 | convState = (convStateList[convState].nextState) & 0xF; |

shreeshas95 | 0:f016e9e8d48b | 165 | } |

shreeshas95 | 0:f016e9e8d48b | 166 | // printf("complete\n"); |

shreeshas95 | 0:f016e9e8d48b | 167 | } |

shreeshas95 | 0:f016e9e8d48b | 168 | |

shreeshas95 | 0:f016e9e8d48b | 169 | }; |

shreeshas95 | 1:a0055b3280c8 | 170 | |

shreeshas95 | 1:a0055b3280c8 | 171 | |

shreeshas95 | 1:a0055b3280c8 | 172 | // ******************************************** INTERLEAVE ************************************** |

shreeshas95 | 1:a0055b3280c8 | 173 | void interleave( unsigned char *input, unsigned char *output ){ |

shreeshas95 | 1:a0055b3280c8 | 174 | |

shreeshas95 | 1:a0055b3280c8 | 175 | unsigned int outState = 0; |

shreeshas95 | 1:a0055b3280c8 | 176 | unsigned int outByte = 0; |

shreeshas95 | 1:a0055b3280c8 | 177 | |

shreeshas95 | 1:a0055b3280c8 | 178 | for( unsigned int i = 0 ; i < 36 ; ++i ){ |

shreeshas95 | 1:a0055b3280c8 | 179 | for(unsigned int j = 0 ; j < 30 ; ++j){ |

shreeshas95 | 1:a0055b3280c8 | 180 | unsigned int x = j*36+i; |

shreeshas95 | 1:a0055b3280c8 | 181 | unsigned char tempBit = ((input[x >> 3]) >> (7-(x % 8))) & 1; |

shreeshas95 | 1:a0055b3280c8 | 182 | switch(outState){ |

shreeshas95 | 1:a0055b3280c8 | 183 | case 0: |

shreeshas95 | 1:a0055b3280c8 | 184 | outState = 1; |

shreeshas95 | 1:a0055b3280c8 | 185 | output[outByte] = tempBit << 7; |

shreeshas95 | 1:a0055b3280c8 | 186 | break; |

shreeshas95 | 1:a0055b3280c8 | 187 | case 1: |

shreeshas95 | 1:a0055b3280c8 | 188 | outState = 2; |

shreeshas95 | 1:a0055b3280c8 | 189 | output[outByte] += tempBit << 6; |

shreeshas95 | 1:a0055b3280c8 | 190 | break; |

shreeshas95 | 1:a0055b3280c8 | 191 | case 2: |

shreeshas95 | 1:a0055b3280c8 | 192 | outState = 3; |

shreeshas95 | 1:a0055b3280c8 | 193 | output[outByte] += tempBit << 5; |

shreeshas95 | 1:a0055b3280c8 | 194 | break; |

shreeshas95 | 1:a0055b3280c8 | 195 | case 3: |

shreeshas95 | 1:a0055b3280c8 | 196 | outState = 4; |

shreeshas95 | 1:a0055b3280c8 | 197 | output[outByte] += tempBit << 4; |

shreeshas95 | 1:a0055b3280c8 | 198 | break; |

shreeshas95 | 1:a0055b3280c8 | 199 | case 4: |

shreeshas95 | 1:a0055b3280c8 | 200 | outState = 5; |

shreeshas95 | 1:a0055b3280c8 | 201 | output[outByte] += tempBit << 3; |

shreeshas95 | 1:a0055b3280c8 | 202 | break; |

shreeshas95 | 1:a0055b3280c8 | 203 | case 5: |

shreeshas95 | 1:a0055b3280c8 | 204 | outState = 6; |

shreeshas95 | 1:a0055b3280c8 | 205 | output[outByte] += tempBit << 2; |

shreeshas95 | 1:a0055b3280c8 | 206 | break; |

shreeshas95 | 1:a0055b3280c8 | 207 | case 6: |

shreeshas95 | 1:a0055b3280c8 | 208 | outState = 7; |

shreeshas95 | 1:a0055b3280c8 | 209 | output[outByte] += tempBit << 1; |

shreeshas95 | 1:a0055b3280c8 | 210 | break; |

shreeshas95 | 1:a0055b3280c8 | 211 | case 7: |

shreeshas95 | 1:a0055b3280c8 | 212 | outState = 0; |

shreeshas95 | 1:a0055b3280c8 | 213 | output[outByte] += tempBit; |

shreeshas95 | 1:a0055b3280c8 | 214 | ++outByte; |

shreeshas95 | 1:a0055b3280c8 | 215 | break; |

shreeshas95 | 1:a0055b3280c8 | 216 | } |

shreeshas95 | 1:a0055b3280c8 | 217 | } |

shreeshas95 | 1:a0055b3280c8 | 218 | for(unsigned int j = 0 ; j < 2 ; ++j){ |

shreeshas95 | 1:a0055b3280c8 | 219 | switch(outState){ |

shreeshas95 | 1:a0055b3280c8 | 220 | case 0: |

shreeshas95 | 1:a0055b3280c8 | 221 | output[outByte] = 0; |

shreeshas95 | 1:a0055b3280c8 | 222 | outState = 1; |

shreeshas95 | 1:a0055b3280c8 | 223 | break; |

shreeshas95 | 1:a0055b3280c8 | 224 | case 1: |

shreeshas95 | 1:a0055b3280c8 | 225 | outState = 2; |

shreeshas95 | 1:a0055b3280c8 | 226 | break; |

shreeshas95 | 1:a0055b3280c8 | 227 | case 2: |

shreeshas95 | 1:a0055b3280c8 | 228 | outState = 3; |

shreeshas95 | 1:a0055b3280c8 | 229 | break; |

shreeshas95 | 1:a0055b3280c8 | 230 | case 3: |

shreeshas95 | 1:a0055b3280c8 | 231 | outState = 4; |

shreeshas95 | 1:a0055b3280c8 | 232 | break; |

shreeshas95 | 1:a0055b3280c8 | 233 | case 4: |

shreeshas95 | 1:a0055b3280c8 | 234 | outState = 5; |

shreeshas95 | 1:a0055b3280c8 | 235 | break; |

shreeshas95 | 1:a0055b3280c8 | 236 | case 5: |

shreeshas95 | 1:a0055b3280c8 | 237 | outState = 6; |

shreeshas95 | 1:a0055b3280c8 | 238 | break; |

shreeshas95 | 1:a0055b3280c8 | 239 | case 6: |

shreeshas95 | 1:a0055b3280c8 | 240 | outState = 7; |

shreeshas95 | 1:a0055b3280c8 | 241 | break; |

shreeshas95 | 1:a0055b3280c8 | 242 | case 7: |

shreeshas95 | 1:a0055b3280c8 | 243 | outState = 0; |

shreeshas95 | 1:a0055b3280c8 | 244 | ++outByte; |

shreeshas95 | 1:a0055b3280c8 | 245 | break; |

shreeshas95 | 1:a0055b3280c8 | 246 | } |

shreeshas95 | 1:a0055b3280c8 | 247 | } |

shreeshas95 | 1:a0055b3280c8 | 248 | } |

shreeshas95 | 1:a0055b3280c8 | 249 | } |