1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

#define mm 6 /* RS code over GF(2**6) */
#define nn 24 /* nn=2**mm 1 length of codeword */
#define tt 6 /* number of errors that can be corrected */
#define kk 12 /* kk = nn2*tt */
int pp [mm+1] = { 1, 1, 0, 0, 0, 0, 1 } ; /* specify irreducible polynomial coeffts */
int alpha_to [nn+1], index_of [nn+1], gg [nnkk+1] ;
int recd [nn], data [kk], bb [nnkk] ;
// 1st parameter is pointer to 144 bit array filled by the hamming decode
// 2nd parameter is pointer to 72 bit array filled by this decoder to be used later
void
ldu1::decode_reed_solomon(uint16_t *rs_codewords, uint16_t *decoded_lcw)
{
generate_gf( ) ;
gen_poly( ) ;
for(int index = 0; index < 6; index++)
{
/*
takes the 144 bits in rs_codewords array filled by the hamming decoder
the first 72 bits are data, the last 72 bits are parity
there are 6 24bit codewords, first 12 bits are data, last 12 bits are parity bits
*/
// create the codewords, put data and parity in right places
int i;
for (i=0; i<nnkk; i++) recd[i] = rs_codewords[i*index+kk] ; // 72 parity bits, should start taking values from oridals 72143
for (i=0; i<kk; i++) recd[i+nnkk] = rs_codewords[i*index] ; // 72 bits data payload, should start taking values from oridals 071
// put recd[i] into index form; should 24bit codeword
for (i=0; i<nn; i++)
recd[i] = index_of[recd[i]] ;
decode_rs(); // recd[] is returned in polynomial form, should be 12bits of data
// need to store the 6 corrected 12bit arrays recd[] into single 72 bit array
for(i=nnkk; i < nn; i++)
{
decoded_lcw[i  (nnkk) + index*(nnkk)] = recd[i];
}
}
}
