GNU Radio's SATELLITES Package
lib/libfec/encode_rs.h
Go to the documentation of this file.
1 /* The guts of the Reed-Solomon encoder, meant to be #included
2  * into a function body with the following typedefs, macros and variables supplied
3  * according to the code parameters:
4 
5  * data_t - a typedef for the data symbol
6  * data_t data[] - array of NN-NROOTS-PAD and type data_t to be encoded
7  * data_t parity[] - an array of NROOTS and type data_t to be written with parity symbols
8  * NROOTS - the number of roots in the RS code generator polynomial,
9  * which is the same as the number of parity symbols in a block.
10  Integer variable or literal.
11  *
12  * NN - the total number of symbols in a RS block. Integer variable or literal.
13  * PAD - the number of pad symbols in a block. Integer variable or literal.
14  * ALPHA_TO - The address of an array of NN elements to convert Galois field
15  * elements in index (log) form to polynomial form. Read only.
16  * INDEX_OF - The address of an array of NN elements to convert Galois field
17  * elements in polynomial form to index (log) form. Read only.
18  * MODNN - a function to reduce its argument modulo NN. May be inline or a macro.
19  * GENPOLY - an array of NROOTS+1 elements containing the generator polynomial in index
20  form
21 
22  * The memset() and memmove() functions are used. The appropriate header
23  * file declaring these functions (usually <string.h>) must be included by the calling
24  * program.
25 
26  * Copyright 2004, Phil Karn, KA9Q
27  * May be used under the terms of the GNU Lesser General Public License (LGPL)
28  */
29 
30 
31 #undef A0
32 #define A0 (NN) /* Special reserved value encoding zero in index form */
33 
34 {
35  int i, j;
37 
38  memset(parity, 0, NROOTS * sizeof(data_t));
39 
40  for (i = 0; i < NN - NROOTS - PAD; i++) {
41  feedback = INDEX_OF[data[i] ^ parity[0]];
42  if (feedback != A0) { /* feedback term is non-zero */
43 #ifdef UNNORMALIZED
44  /* This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
45  * always be for the polynomials constructed by init_rs()
46  */
48 #endif
49  for (j = 1; j < NROOTS; j++)
50  parity[j] ^= ALPHA_TO[MODNN(feedback + GENPOLY[NROOTS - j])];
51  }
52  /* Shift */
53  memmove(&parity[0], &parity[1], sizeof(data_t) * (NROOTS - 1));
54  if (feedback != A0)
55  parity[NROOTS - 1] = ALPHA_TO[MODNN(feedback + GENPOLY[0])];
56  else
57  parity[NROOTS - 1] = 0;
58  }
59 }
#define NN
Definition: ccsds.h:3
#define NROOTS
Definition: ccsds.h:4
unsigned char data_t
Definition: ccsds.h:1
#define PAD
Definition: char.h:19
#define MODNN(x)
Definition: char.h:8
#define INDEX_OF
Definition: char.h:13
#define GENPOLY
Definition: char.h:14
#define ALPHA_TO
Definition: char.h:12
int j
Definition: lib/libfec/decode_rs.h:73
int i
Definition: lib/libfec/decode_rs.h:71
#define A0
Definition: lib/libfec/encode_rs.h:32
data_t feedback
Definition: lib/libfec/encode_rs.h:34
memset(parity, 0, NROOTS *sizeof(data_t))