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