blob: 5d71503945c209959a9aaf559ea0b78e7f9e4693 [file] [log] [blame]
Bill Yi4e213d52015-06-23 13:53:11 -07001.TH REED-SOLOMON 3
2.SH NAME
3init_rs_int, encode_rs_int, decode_rs_int, free_rs_int,
4init_rs_char, encode_rs_char, decode_rs_char, free_rs_char,
5encode_rs_8, decode_rs_8, encode_rs_ccsds, decode_rs_ccsds
6\- Reed-Solomon encoding/decoding
7.SH SYNOPSIS
8.nf
9.ft B
10#include "fec.h"
11
12void *init_rs_int(int symsize,int gfpoly,int fcr,int prim,
13 int nroots,int pad);
14
15void encode_rs_int(void *rs,int *data,int *parity);
16
17int decode_rs_int(void *rs,int *data,int *eras_pos,int no_eras);
18
19void free_rs_int(void *rs);
20
21
22void *init_rs_char(int symsize,int gfpoly,int fcr,int prim,
23 int nroots,int pad);
24
25void encode_rs_char(void *rs,unsigned char *data,
26 unsigned char *parity);
27
28int decode_rs_char(void *rs,unsigned char *data,int *eras_pos,
29 int no_eras);
30
31void free_rs_char(void *rs);
32
33
34void encode_rs_8(unsigned char *data,unsigned char *parity,
35 int pad);
36
37int decode_rs_8(unsigned char *data,int *eras_pos,int no_eras,
38 int pad);
39
40
41void encode_rs_ccsds(unsigned char *data,unsigned char *parity,
42 int pad);
43
44int decode_rs_ccsds(unsigned char *data,int *eras_pos,int no_eras,
45 int pad);
46
47unsigned char Taltab[256];
48unsigned char Tal1tab[256];
49
50.fi
51
52.SH DESCRIPTION
53These functions implement Reed-Solomon error control encoding and
54decoding. For optimal performance in a variety of applications, three
55sets of functions are supplied. To access these functions, add "-lfec"
56to your linker command line.
57
58The functions with names ending in \fB_int\fR handle data in integer arrays,
59permitting arbitrarily large codewords limited only by machine
60resources.
61
62The functions with names ending in \fB_char\fR take unsigned char arrays and can
63handle codes with symbols of 8 bits or less (i.e., with codewords of
64255 symbols or less).
65
66\fBencode_rs_8\fR and \fBdecode_rs_8\fR implement a specific
67(255,223) code with 8-bit symbols specified by the CCSDS:
68a field generator of 1 + X + X^2 + X^7 + X^8 and a code
69generator with first consecutive root = 112 and a primitive element of
7011. These functions use the conventional
71polynomial form, \fInot\fR the dual-basis specified in
72the CCSDS standard, to represent symbols. This code may be
73shortened by giving a non-zero \fBpad\fR value to produce a
74(255-\fBpad\fR,223-\fBpad\fR) code. The padding will consist of the
75specified number of zeroes at the front of the full codeword.
76
77For full CCSDS compatibility, \fBencode_rs_ccsds\fR and
78\fBdecode_rs_ccsds\fR are provided. These functions use two lookup
79tables, \fBTaltab\fR to convert from conventional to dual-basis, and
80\fBTal1tab\fR to perform the inverse mapping from dual-basis to
81conventional form, before and after calls to \fBencode_rs_8\fR
82and \fBdecode_rs_8\fR.
83
84The \fB_8\fR and \fB_ccsds\fR functions do not require initialization.
85
86To use the general purpose RS encoder or decoder (i.e.,
87the \fB_char\fR or \fB_int\fR versions), the user must first
88call \fBinit_rs_int\fR or \fBinit_rs_char\fR as appropriate. The
89arguments are as follows:
90
91\fBsymsize\fR gives the symbol size in bits, up to 8 for \fBinit_rs_char\fR
92or 32 for \fBinit_rs_int\fR on a machine with 32-bit ints (though such a
93huge code would exhaust memory limits on a 32-bit machine). The resulting
94Reed-Solomon code word will have 2^\fBsymsize\fR - 1 symbols,
95each containing \fBsymsize\fR bits. The codeword may be shortened with the
96\fBpad\fR parameter described below.
97
98\fBgfpoly\fR gives the extended Galois field generator polynomial coefficients,
99with the 0th coefficient in the low order bit. The polynomial
100\fImust\fR be primitive; if not, the call will fail and NULL will be
101returned.
102
103\fBfcr\fR gives, in index form, the first consecutive root of the
104Reed Solomon code generator polynomial.
105
106\fBprim\fR gives, in index form, the primitive element in the Galois field
107used to generate the Reed Solomon code generator polynomial.
108
109\fBnroots\fR gives the number of roots in the Reed Solomon code
110generator polynomial. This equals the number of parity symbols
111per code block.
112
113\fBpad\fR gives the number of leading symbols in the codeword
114that are implicitly padded to zero in a shortened code block.
115
116The resulting Reed-Solomon code has parameters (N,K), where
117N = 2^\fBsymsize\fR - \fBpad\fR - 1 and K = N-\fBnroots\fR.
118
119The \fBencode_rs_char\fR and \fBencode_rs_int\fR functions accept
120the pointer returned by \fBinit_rs_char\fR or
121\fBinit_rs_int\fR, respectively, to
122encode a block of data using the specified code.
123The input data array is expected to
124contain K symbols (of \fBsymsize\fR bits each, right justified
125in each char or int) and \fBnroots\fR parity symbols will be placed
126into the \fBparity\fR array, right justified.
127
128The \fBdecode_\fR functions correct
129the errors in a Reed-Solomon codeword of N symbols up to the capability of the code.
130An optional list of "erased" symbol indices may be given in the \fBeras_pos\fR
131array to assist the decoder; this parameter may be NULL if no erasures
132are given. The number of erased symbols must be given in the \fBno_eras\fR
133parameter.
134
135To maximize performance, the encode and decode functions perform no
136"sanity checking" of their inputs. Decoder failure may result if
137\fBeras_pos\fR contains duplicate entries, and both encoder and
138decoder will fail if an input symbol exceeds its allowable range.
139(Symbol range overflow cannot occur with the \fB_8\fR or
140\fB_ccsds\fR functions,
141or with the \fB_char\fR functions when 8-bit symbols are specified.)
142
143The decoder corrects the symbols "in place", returning the number
144of symbols in error. If the codeword is uncorrectable, -1 is returned
145and the data block is unchanged. If \fBeras_pos\fR is non-null, it is
146used to return a list of corrected symbol positions, in no particular
147order. This means that the
148array passed through this parameter \fImust\fR have at least \fBnroots\fR
149elements to prevent a possible buffer overflow.
150
151The \fBfree_rs_int\fR and \fBfree_rs_char\fR functions free the internal
152space allocated by the \fBinit_rs_int\fR and \fBinit_rs_char\fR functions,
153respecitively.
154
155The functions \fBencode_rs_8\fR and \fBdecode_rs_8\fR do not have
156corresponding \fBinit\fR and \fBfree\fR, nor do they take the
157\fBrs\fR argument accepted by the other functions as their parameters
158are statically compiled. These functions implement a code
159equivalent to calling
160
161\fBinit_rs_char\fR(8,0x187,112,11,32,pad);
162
163and using the resulting pointer with \fBencode_rs_char\fR and
164\fBdecode_rs_char\fR.
165
166.SH RETURN VALUES
167\fBinit_rs_int\fR and \fBinit_rs_char\fR return a pointer to an internal
168control structure that must be passed to the corresponding encode, decode
169and free functions. These functions return NULL on error.
170
171The \fBdecode_\fR functions return a count of corrected
172symbols, or -1 if the block was uncorrectible.
173
174.SH AUTHOR
175Phil Karn, KA9Q (karn@ka9q.net), based heavily on earlier work by Robert
176Morelos-Zaragoza (robert@spectra.eng.hawaii.edu) and Hari Thirumoorthy
177(harit@spectra.eng.hawaii.edu). Extra improvements suggested by Detmar
178Welz (dwelz@web.de).
179
180.SH COPYRIGHT
181Copyright 2004, Phil Karn, KA9Q. May be used under the terms of the
182GNU Lesser General Public License (LGPL).
183
184.SH SEE ALSO
185CCSDS 101.0-B-6: Telemetry Channel Coding.
186http://www.ccsds.org/documents/101x0b6.pdf
187
188.SH NOTE
189CCSDS chose the "dual basis" symbol representation because it
190simplified the implementation of a Reed-Solomon encoder in dedicated
191hardware. However, this approach holds no advantages for a software
192implementation on a general purpose computer, so use of the dual basis
193is recommended only if compatibility with the CCSDS standard is needed,
194e.g., to decode data from an existing spacecraft using the CCSDS
195standard. If you just want a fast (255,223) RS codec without needing
196to interoperate with a CCSDS standard code, use \fBencode_rs_8\fR
197and \fBdecode_rs_8\fR.
198