Configuration according to flowchart included. (UPTO PHY_ON). INclusion of #define functions
Fork of send_tn_intgration_sss by
convolutionHeader2.h@5:9664602e1ceb, 2016-01-13 (annotated)
- Committer:
- dheerajmpai23
- Date:
- Wed Jan 13 11:49:09 2016 +0000
- Revision:
- 5:9664602e1ceb
- Parent:
- 0:da506debc107
Changes Made:; ; inclusion of 1. #define functions 2.config_f() function without PHY_TX; ; file from krishan's a/c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
krishanprajapat | 0:da506debc107 | 1 | |
krishanprajapat | 0:da506debc107 | 2 | |
krishanprajapat | 0:da506debc107 | 3 | class Convolution{ |
krishanprajapat | 0:da506debc107 | 4 | |
krishanprajapat | 0:da506debc107 | 5 | private: |
krishanprajapat | 0:da506debc107 | 6 | typedef struct ConvNode{ |
krishanprajapat | 0:da506debc107 | 7 | //next state |
krishanprajapat | 0:da506debc107 | 8 | //format : 8 bits mapped as [1]xxxx [0]xxxx |
krishanprajapat | 0:da506debc107 | 9 | unsigned char nextState; |
krishanprajapat | 0:da506debc107 | 10 | |
krishanprajapat | 0:da506debc107 | 11 | //output |
krishanprajapat | 0:da506debc107 | 12 | // format : 8 bits mapped as |
krishanprajapat | 0:da506debc107 | 13 | // **** xxxx{2} [1]-[0] {1} [1]-[0] i.e. ****xxxx |
krishanprajapat | 0:da506debc107 | 14 | // x = data, * = junk |
krishanprajapat | 0:da506debc107 | 15 | unsigned char output; |
krishanprajapat | 0:da506debc107 | 16 | }ConvNode; |
krishanprajapat | 0:da506debc107 | 17 | |
krishanprajapat | 0:da506debc107 | 18 | ConvNode convStateList[16]; |
krishanprajapat | 0:da506debc107 | 19 | |
krishanprajapat | 0:da506debc107 | 20 | public: |
krishanprajapat | 0:da506debc107 | 21 | /* |
krishanprajapat | 0:da506debc107 | 22 | @brief: Constructor : Initialise all the variables |
krishanprajapat | 0:da506debc107 | 23 | @param: none |
krishanprajapat | 0:da506debc107 | 24 | @return: none |
krishanprajapat | 0:da506debc107 | 25 | */ |
krishanprajapat | 0:da506debc107 | 26 | Convolution(){ |
krishanprajapat | 0:da506debc107 | 27 | |
krishanprajapat | 0:da506debc107 | 28 | convStateList[0].nextState = 0x10; |
krishanprajapat | 0:da506debc107 | 29 | convStateList[1].nextState = 0x32; |
krishanprajapat | 0:da506debc107 | 30 | convStateList[2].nextState = 0x54; |
krishanprajapat | 0:da506debc107 | 31 | convStateList[3].nextState = 0x76; |
krishanprajapat | 0:da506debc107 | 32 | convStateList[4].nextState = 0x98; |
krishanprajapat | 0:da506debc107 | 33 | convStateList[5].nextState = 0xBA; |
krishanprajapat | 0:da506debc107 | 34 | convStateList[6].nextState = 0xDC; |
krishanprajapat | 0:da506debc107 | 35 | convStateList[7].nextState = 0xFE; |
krishanprajapat | 0:da506debc107 | 36 | convStateList[8].nextState = 0x10; |
krishanprajapat | 0:da506debc107 | 37 | convStateList[9].nextState = 0x32; |
krishanprajapat | 0:da506debc107 | 38 | convStateList[10].nextState = 0x54; |
krishanprajapat | 0:da506debc107 | 39 | convStateList[11].nextState = 0x76; |
krishanprajapat | 0:da506debc107 | 40 | convStateList[12].nextState = 0x98; |
krishanprajapat | 0:da506debc107 | 41 | convStateList[13].nextState = 0xBA; |
krishanprajapat | 0:da506debc107 | 42 | convStateList[14].nextState = 0xDC; |
krishanprajapat | 0:da506debc107 | 43 | convStateList[15].nextState = 0xFE; |
krishanprajapat | 0:da506debc107 | 44 | |
krishanprajapat | 0:da506debc107 | 45 | convStateList[0].output = 0x0A; |
krishanprajapat | 0:da506debc107 | 46 | convStateList[1].output = 0x06; |
krishanprajapat | 0:da506debc107 | 47 | convStateList[2].output = 0x06; |
krishanprajapat | 0:da506debc107 | 48 | convStateList[3].output = 0x0A; |
krishanprajapat | 0:da506debc107 | 49 | convStateList[4].output = 0x09; |
krishanprajapat | 0:da506debc107 | 50 | convStateList[5].output = 0x05; |
krishanprajapat | 0:da506debc107 | 51 | convStateList[6].output = 0x05; |
krishanprajapat | 0:da506debc107 | 52 | convStateList[7].output = 0x09; |
krishanprajapat | 0:da506debc107 | 53 | convStateList[8].output = 0x05; |
krishanprajapat | 0:da506debc107 | 54 | convStateList[9].output = 0x09; |
krishanprajapat | 0:da506debc107 | 55 | convStateList[10].output = 0x09; |
krishanprajapat | 0:da506debc107 | 56 | convStateList[11].output = 0x05; |
krishanprajapat | 0:da506debc107 | 57 | convStateList[12].output = 0x06; |
krishanprajapat | 0:da506debc107 | 58 | convStateList[13].output = 0x0A; |
krishanprajapat | 0:da506debc107 | 59 | convStateList[14].output = 0x0A; |
krishanprajapat | 0:da506debc107 | 60 | convStateList[15].output = 0x06; |
krishanprajapat | 0:da506debc107 | 61 | } |
krishanprajapat | 0:da506debc107 | 62 | |
krishanprajapat | 0:da506debc107 | 63 | |
krishanprajapat | 0:da506debc107 | 64 | /* |
krishanprajapat | 0:da506debc107 | 65 | @brief: convolution encode the input bytes : in sync with => (1-TM-Frame -> 2-T-Frame) |
krishanprajapat | 0:da506debc107 | 66 | @param: inPtr : pointer to input unsigned char array |
krishanprajapat | 0:da506debc107 | 67 | inLength : length in bytes of input array |
krishanprajapat | 0:da506debc107 | 68 | outPtr : pointer to the output bytes, define it outside the function |
krishanprajapat | 0:da506debc107 | 69 | outLength : length of output array in bytes [call by reference, edited inside the function] |
krishanprajapat | 0:da506debc107 | 70 | @return: none |
krishanprajapat | 0:da506debc107 | 71 | */ |
krishanprajapat | 0:da506debc107 | 72 | void convolutionEncode(unsigned char *input, unsigned char *output){ |
krishanprajapat | 0:da506debc107 | 73 | |
krishanprajapat | 0:da506debc107 | 74 | // cout << "inside convolution" << endl; |
krishanprajapat | 0:da506debc107 | 75 | |
krishanprajapat | 0:da506debc107 | 76 | unsigned int convState = 0; |
krishanprajapat | 0:da506debc107 | 77 | |
krishanprajapat | 0:da506debc107 | 78 | int inBit = 7; |
krishanprajapat | 0:da506debc107 | 79 | unsigned int inByte = 0; |
krishanprajapat | 0:da506debc107 | 80 | |
krishanprajapat | 0:da506debc107 | 81 | unsigned int outState = 0; |
krishanprajapat | 0:da506debc107 | 82 | unsigned int outByte = 0; |
krishanprajapat | 0:da506debc107 | 83 | |
krishanprajapat | 0:da506debc107 | 84 | for(unsigned int j = 0 ; j < 536 ; ++j){ |
krishanprajapat | 0:da506debc107 | 85 | // printf("j = %u, inByte = %u\n", j, inByte); |
krishanprajapat | 0:da506debc107 | 86 | // read a new bit from input stream |
krishanprajapat | 0:da506debc107 | 87 | // cout << "inByte " <<inByte; |
krishanprajapat | 0:da506debc107 | 88 | unsigned char tempBit = (input[inByte] >> inBit) & 1; |
krishanprajapat | 0:da506debc107 | 89 | --inBit; |
krishanprajapat | 0:da506debc107 | 90 | |
krishanprajapat | 0:da506debc107 | 91 | // convolute and write output |
krishanprajapat | 0:da506debc107 | 92 | switch(outState){ |
krishanprajapat | 0:da506debc107 | 93 | case 0: |
krishanprajapat | 0:da506debc107 | 94 | outState = 2; |
krishanprajapat | 0:da506debc107 | 95 | output[outByte] = ( (convStateList[convState].output >> tempBit) & 1 ) << 7; |
krishanprajapat | 0:da506debc107 | 96 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 6; |
krishanprajapat | 0:da506debc107 | 97 | break; |
krishanprajapat | 0:da506debc107 | 98 | case 2: |
krishanprajapat | 0:da506debc107 | 99 | outState = 4; |
krishanprajapat | 0:da506debc107 | 100 | output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 5; |
krishanprajapat | 0:da506debc107 | 101 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 4; |
krishanprajapat | 0:da506debc107 | 102 | break; |
krishanprajapat | 0:da506debc107 | 103 | case 4: |
krishanprajapat | 0:da506debc107 | 104 | outState = 6; |
krishanprajapat | 0:da506debc107 | 105 | output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 3; |
krishanprajapat | 0:da506debc107 | 106 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 2; |
krishanprajapat | 0:da506debc107 | 107 | break; |
krishanprajapat | 0:da506debc107 | 108 | case 6: |
krishanprajapat | 0:da506debc107 | 109 | outState = 0; |
krishanprajapat | 0:da506debc107 | 110 | output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 1; |
krishanprajapat | 0:da506debc107 | 111 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ); |
krishanprajapat | 0:da506debc107 | 112 | ++outByte; |
krishanprajapat | 0:da506debc107 | 113 | output[outByte] = 0x00; |
krishanprajapat | 0:da506debc107 | 114 | break; |
krishanprajapat | 0:da506debc107 | 115 | } |
krishanprajapat | 0:da506debc107 | 116 | |
krishanprajapat | 0:da506debc107 | 117 | // next state transition |
krishanprajapat | 0:da506debc107 | 118 | switch(tempBit){ |
krishanprajapat | 0:da506debc107 | 119 | case 0: |
krishanprajapat | 0:da506debc107 | 120 | convState = (convStateList[convState].nextState) & 0xF; |
krishanprajapat | 0:da506debc107 | 121 | break; |
krishanprajapat | 0:da506debc107 | 122 | case 1: |
krishanprajapat | 0:da506debc107 | 123 | convState = (convStateList[convState].nextState >> 4) & 0xF; |
krishanprajapat | 0:da506debc107 | 124 | break; |
krishanprajapat | 0:da506debc107 | 125 | } |
krishanprajapat | 0:da506debc107 | 126 | |
krishanprajapat | 0:da506debc107 | 127 | if(inBit == -1){ |
krishanprajapat | 0:da506debc107 | 128 | // printf("in byte = %u\n", inByte); |
krishanprajapat | 0:da506debc107 | 129 | ++inByte; |
krishanprajapat | 0:da506debc107 | 130 | inBit = 7; |
krishanprajapat | 0:da506debc107 | 131 | } |
krishanprajapat | 0:da506debc107 | 132 | |
krishanprajapat | 0:da506debc107 | 133 | } |
krishanprajapat | 0:da506debc107 | 134 | |
krishanprajapat | 0:da506debc107 | 135 | // printf("normal iteration complete, outByte = %u\n", outByte); |
krishanprajapat | 0:da506debc107 | 136 | |
krishanprajapat | 0:da506debc107 | 137 | for(unsigned int j = 0 ; j < 4 ; ++j){ |
krishanprajapat | 0:da506debc107 | 138 | // printf("j = %u\n, outByte = %u\n", j, outByte); |
krishanprajapat | 0:da506debc107 | 139 | // append zero at the end |
krishanprajapat | 0:da506debc107 | 140 | switch(outState){ |
krishanprajapat | 0:da506debc107 | 141 | case 0: |
krishanprajapat | 0:da506debc107 | 142 | outState = 2; |
krishanprajapat | 0:da506debc107 | 143 | output[outByte] = ( (convStateList[convState].output) & 1 ) << 7; |
krishanprajapat | 0:da506debc107 | 144 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 6; |
krishanprajapat | 0:da506debc107 | 145 | break; |
krishanprajapat | 0:da506debc107 | 146 | case 2: |
krishanprajapat | 0:da506debc107 | 147 | outState = 4; |
krishanprajapat | 0:da506debc107 | 148 | output[outByte] += ( (convStateList[convState].output) & 1 ) << 5; |
krishanprajapat | 0:da506debc107 | 149 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 4; |
krishanprajapat | 0:da506debc107 | 150 | break; |
krishanprajapat | 0:da506debc107 | 151 | case 4: |
krishanprajapat | 0:da506debc107 | 152 | outState = 6; |
krishanprajapat | 0:da506debc107 | 153 | output[outByte] += ( (convStateList[convState].output ) & 1 ) << 3; |
krishanprajapat | 0:da506debc107 | 154 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 2; |
krishanprajapat | 0:da506debc107 | 155 | break; |
krishanprajapat | 0:da506debc107 | 156 | case 6: |
krishanprajapat | 0:da506debc107 | 157 | outState = 0; |
krishanprajapat | 0:da506debc107 | 158 | output[outByte] += ( (convStateList[convState].output ) & 1 ) << 1; |
krishanprajapat | 0:da506debc107 | 159 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ); |
krishanprajapat | 0:da506debc107 | 160 | ++outByte; |
krishanprajapat | 0:da506debc107 | 161 | // printf("outByte @ end of switch = %u\n", outByte); |
krishanprajapat | 0:da506debc107 | 162 | break; |
krishanprajapat | 0:da506debc107 | 163 | } |
krishanprajapat | 0:da506debc107 | 164 | // next state transition |
krishanprajapat | 0:da506debc107 | 165 | convState = (convStateList[convState].nextState) & 0xF; |
krishanprajapat | 0:da506debc107 | 166 | } |
krishanprajapat | 0:da506debc107 | 167 | // printf("complete\n"); |
krishanprajapat | 0:da506debc107 | 168 | } |
krishanprajapat | 0:da506debc107 | 169 | |
krishanprajapat | 0:da506debc107 | 170 | }; |