diff --git a/SP5WWP/golay.c b/SP5WWP/golay.c deleted file mode 100644 index cef5df6..0000000 --- a/SP5WWP/golay.c +++ /dev/null @@ -1,228 +0,0 @@ -#include -#include -#include "golay.h" - -const uint16_t encode_matrix[12]= -{ - 0x8eb, 0x93e, 0xa97, 0xdc6, 0x367, 0x6cd, - 0xd99, 0x3da, 0x7b4, 0xf68, 0x63b, 0xc75 -}; - -const uint16_t decode_matrix[12]= -{ - 0xc75, 0x49f, 0x93e, 0x6e3, 0xdc6, 0xf13, - 0xab9, 0x1ed, 0x3da, 0x7b4, 0xf68, 0xa4f -}; - -//0 index - LSB -void IntToSoft(uint16_t* out, const uint16_t in, uint8_t len) -{ - for(uint8_t i=0; i>i)&1 ? (out[i]=0xFFFF) : (out[i]=0); - } -} - -uint16_t SoftToInt(const uint16_t* in, uint8_t len) -{ - uint16_t tmp=0; - - for(uint8_t i=0; i0x7FFF) - tmp|=(1<>16); -} - -//use bilinear interpolation for XOR -uint16_t SoftBitXOR(const uint16_t a, const uint16_t b) -{ - return Mul16(Div16(0xFFFF-b, 0xFFFF), Div16(a, 0xFFFF)) + Mul16(Div16(b, 0xFFFF), Div16(0xFFFF-a, 0xFFFF)); -} - -//soft XOR -void SoftXOR(uint16_t* out, const uint16_t* a, const uint16_t* b, uint8_t len) -{ - for(uint8_t i=0; i0x7FFF) - { - SoftXOR(checksum, checksum, soft_em, 12); - } - } - - memcpy((uint8_t*)out, (uint8_t*)checksum, 12*2); -} - -uint32_t SdetectErrors(const uint16_t* codeword) -{ - uint16_t data[12]; - uint16_t parity[12]; - uint16_t cksum[12]; - uint16_t syndrome[12]; - uint32_t weight; //for soft popcount - - memcpy((uint8_t*)data, (uint8_t*)&codeword[12], 2*12); - memcpy((uint8_t*)parity, (uint8_t*)&codeword[0], 2*12); - - calcChecksumS(cksum, data); - SoftXOR(syndrome, parity, cksum, 12); - - weight=spopcount(syndrome, 12); - - //all (less than 4) errors in the parity part - if(weight < 4*0xFFFE) - { - //printf("1: %1.2f\n", (float)weight/0xFFFF); - return SoftToInt(syndrome, 12); - } - - //one of the errors in data part, up to 3 in parity - for(uint8_t i = 0; i<12; i++) - { - uint16_t e = 1< 0x7FFF) - { - IntToSoft(dm, decode_matrix[i], 12); - SoftXOR(inv_syndrome, inv_syndrome, dm, 12); - } - } - - //all (less than 4) errors in the data part - weight=spopcount(inv_syndrome, 12); - if(weight < 4*0xFFFF) - { - //printf("4: %1.2f\n", (float)weight/0xFFFF); - return SoftToInt(inv_syndrome, 12) << 12; - } - - //one error in parity bits, up to 3 in data - this part has some quirks, the reason remains unknown - for(uint8_t i=0; i<12; i++) - { - uint16_t e = 1<> 12) & 0x0FFF; -}