1/* Reed-Solomon encoder
2 * Copyright 2002, Phil Karn, KA9Q
3 * May be used under the terms of the GNU Lesser General Public License (LGPL)
4 */
5#include <string.h>
6
7#ifdef FIXED
8#include "fixed.h"
9#elif defined(BIGSYM)
10#include "int.h"
11#else
12#include "char.h"
13#endif
14
15void ENCODE_RS(
16#ifdef FIXED
17data_t *data, data_t *bb,int pad){
18#else
19void *p,data_t *data, data_t *bb){
20  struct rs *rs = (struct rs *)p;
21#endif
22  int i, j;
23  data_t feedback;
24
25#ifdef FIXED
26  /* Check pad parameter for validity */
27  if(pad < 0 || pad >= NN)
28    return;
29#endif
30
31  memset(bb,0,NROOTS*sizeof(data_t));
32
33  for(i=0;i<NN-NROOTS-PAD;i++){
34    feedback = INDEX_OF[data[i] ^ bb[0]];
35    if(feedback != A0){      /* feedback term is non-zero */
36#ifdef UNNORMALIZED
37      /* This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
38       * always be for the polynomials constructed by init_rs()
39       */
40      feedback = MODNN(NN - GENPOLY[NROOTS] + feedback);
41#endif
42      for(j=1;j<NROOTS;j++)
43	bb[j] ^= ALPHA_TO[MODNN(feedback + GENPOLY[NROOTS-j])];
44    }
45    /* Shift */
46    memmove(&bb[0],&bb[1],sizeof(data_t)*(NROOTS-1));
47    if(feedback != A0)
48      bb[NROOTS-1] = ALPHA_TO[MODNN(feedback + GENPOLY[0])];
49    else
50      bb[NROOTS-1] = 0;
51  }
52}
53