1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE book PUBLIC
"-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []
>
5 <book id=
"Reed-Solomon-Library-Guide">
7 <title>Reed-Solomon Library Programming Interface
</title>
11 <firstname>Thomas
</firstname>
12 <surname>Gleixner
</surname>
15 <email>tglx@linutronix.de
</email>
23 <holder>Thomas Gleixner
</holder>
28 This documentation is free software; you can redistribute
29 it and/or modify it under the terms of the GNU General Public
30 License version
2 as published by the Free Software Foundation.
34 This program is distributed in the hope that it will be
35 useful, but WITHOUT ANY WARRANTY; without even the implied
36 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
37 See the GNU General Public License for more details.
41 You should have received a copy of the GNU General Public
42 License along with this program; if not, write to the Free
43 Software Foundation, Inc.,
59 Temple Place, Suite
330, Boston,
48 For more details see the file COPYING in the source
49 distribution of Linux.
57 <title>Introduction
</title>
59 The generic Reed-Solomon Library provides encoding, decoding
60 and error correction functions.
63 Reed-Solomon codes are used in communication and storage
64 applications to ensure data integrity.
67 This documentation is provided for developers who want to utilize
68 the functions provided by the library.
73 <title>Known Bugs And Assumptions
</title>
82 This chapter provides examples of how to use the library.
85 <title>Initializing
</title>
87 The init function init_rs returns a pointer to an
88 rs decoder structure, which holds the necessary
89 information for encoding, decoding and error correction
90 with the given polynomial. It either uses an existing
91 matching decoder or creates a new one. On creation all
92 the lookup tables for fast en/decoding are created.
93 The function may take a while, so make sure not to
94 call it in critical code paths.
97 /* the Reed Solomon control structure */
98 static struct rs_control *rs_decoder;
100 /* Symbolsize is
10 (bits)
101 * Primitive polynomial is x^
10+x^
3+
1
102 * first consecutive root is
0
103 * primitive element to generate roots =
1
104 * generator polynomial degree (number of roots) =
6
106 rs_decoder = init_rs (
10,
0x409,
0,
1,
6);
110 <title>Encoding
</title>
112 The encoder calculates the Reed-Solomon code over
113 the given data length and stores the result in
114 the parity buffer. Note that the parity buffer must
115 be initialized before calling the encoder.
118 The expanded data can be inverted on the fly by
119 providing a non-zero inversion mask. The expanded data is
120 XOR'ed with the mask. This is used e.g. for FLASH
121 ECC, where the all
0xFF is inverted to an all
0x00.
122 The Reed-Solomon code for all
0x00 is all
0x00. The
123 code is inverted before storing to FLASH so it is
0xFF
124 too. This prevents that reading from an erased FLASH
125 results in ECC errors.
128 The databytes are expanded to the given symbol size
129 on the fly. There is no support for encoding continuous
130 bitstreams with a symbol size !=
8 at the moment. If
131 it is necessary it should be not a big deal to implement
135 /* Parity buffer. Size = number of roots */
137 /* Initialize the parity buffer */
138 memset(par,
0, sizeof(par));
139 /* Encode
512 byte in data8. Store parity in buffer par */
140 encode_rs8 (rs_decoder, data8,
512, par,
0);
144 <title>Decoding
</title>
146 The decoder calculates the syndrome over
147 the given data length and the received parity symbols
148 and corrects errors in the data.
151 If a syndrome is available from a hardware decoder
152 then the syndrome calculation is skipped.
155 The correction of the data buffer can be suppressed
156 by providing a correction pattern buffer and an error
157 location buffer to the decoder. The decoder stores the
158 calculated error location and the correction bitmask
159 in the given buffers. This is useful for hardware
160 decoders which use a weird bit ordering scheme.
163 The databytes are expanded to the given symbol size
164 on the fly. There is no support for decoding continuous
165 bitstreams with a symbolsize !=
8 at the moment. If
166 it is necessary it should be not a big deal to implement
172 Decoding with syndrome calculation, direct data correction
175 /* Parity buffer. Size = number of roots */
183 /* Decode
512 byte in data8.*/
184 numerr = decode_rs8 (rs_decoder, data8, par,
512, NULL,
0, NULL,
0, NULL);
190 Decoding with syndrome given by hardware decoder, direct data correction
193 /* Parity buffer. Size = number of roots */
194 uint16_t par[
6], syn[
6];
201 /* Get syndrome from hardware decoder */
203 /* Decode
512 byte in data8.*/
204 numerr = decode_rs8 (rs_decoder, data8, par,
512, syn,
0, NULL,
0, NULL);
210 Decoding with syndrome given by hardware decoder, no direct data correction.
213 Note: It's not necessary to give data and received parity to the decoder.
216 /* Parity buffer. Size = number of roots */
217 uint16_t par[
6], syn[
6], corr[
8];
219 int numerr, errpos[
8];
224 /* Get syndrome from hardware decoder */
226 /* Decode
512 byte in data8.*/
227 numerr = decode_rs8 (rs_decoder, NULL, NULL,
512, syn,
0, errpos,
0, corr);
228 for (i =
0; i
< numerr; i++) {
229 do_error_correction_in_your_buffer(errpos[i], corr[i]);
235 <title>Cleanup
</title>
237 The function free_rs frees the allocated resources,
238 if the caller is the last user of the decoder.
241 /* Release resources */
248 <chapter id=
"structs">
249 <title>Structures
</title>
251 This chapter contains the autogenerated documentation of the structures which are
252 used in the Reed-Solomon Library and are relevant for a developer.
254 !Iinclude/linux/rslib.h
257 <chapter id=
"pubfunctions">
258 <title>Public Functions Provided
</title>
260 This chapter contains the autogenerated documentation of the Reed-Solomon functions
263 !Elib/reed_solomon/reed_solomon.c
266 <chapter id=
"credits">
267 <title>Credits
</title>
269 The library code for encoding and decoding was written by Phil Karn.
272 Copyright
2002, Phil Karn, KA9Q
273 May be used under the terms of the GNU General Public License (GPL)
276 The wrapper functions and interfaces are written by Thomas Gleixner.
279 Many users have provided bugfixes, improvements and helping hands for testing.
283 The following people have contributed to this document:
286 Thomas Gleixner
<email>tglx@linutronix.de
</email>