1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V3.1//EN"[]>
3 <book id="Reed-Solomon-Library-Guide">
5 <title>Reed-Solomon Library Programming Interface</title>
9 <firstname>Thomas</firstname>
10 <surname>Gleixner</surname>
13 <email>tglx@linutronix.de</email>
21 <holder>Thomas Gleixner</holder>
26 This documentation is free software; you can redistribute
27 it and/or modify it under the terms of the GNU General Public
28 License version 2 as published by the Free Software Foundation.
32 This program is distributed in the hope that it will be
33 useful, but WITHOUT ANY WARRANTY; without even the implied
34 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35 See the GNU General Public License for more details.
39 You should have received a copy of the GNU General Public
40 License along with this program; if not, write to the Free
41 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
46 For more details see the file COPYING in the source
47 distribution of Linux.
55 <title>Introduction</title>
57 The generic Reed-Solomon Library provides encoding, decoding
58 and error correction functions.
61 Reed-Solomon codes are used in communication and storage
62 applications to ensure data integrity.
65 This documentation is provided for developers who want to utilize
66 the functions provided by the library.
71 <title>Known Bugs And Assumptions</title>
80 This chapter provides examples how to use the library.
83 <title>Initializing</title>
85 The init function init_rs returns a pointer to a
86 rs decoder structure, which holds the necessary
87 information for encoding, decoding and error correction
88 with the given polynomial. It either uses an existing
89 matching decoder or creates a new one. On creation all
90 the lookup tables for fast en/decoding are created.
91 The function may take a while, so make sure not to
92 call it in critical code paths.
95 /* the Reed Solomon control structure */
96 static struct rs_control *rs_decoder;
98 /* Symbolsize is 10 (bits)
99 * Primitve polynomial is x^10+x^3+1
100 * first consecutive root is 0
101 * primitve element to generate roots = 1
102 * generator polinomial degree (number of roots) = 6
104 rs_decoder = init_rs (10, 0x409, 0, 1, 6);
108 <title>Encoding</title>
110 The encoder calculates the Reed-Solomon code over
111 the given data length and stores the result in
112 the parity buffer. Note that the parity buffer must
113 be initialized before calling the encoder.
116 The expanded data can be inverted on the fly by
117 providing a non zero inversion mask. The expanded data is
118 XOR'ed with the mask. This is used e.g. for FLASH
119 ECC, where the all 0xFF is inverted to an all 0x00.
120 The Reed-Solomon code for all 0x00 is all 0x00. The
121 code is inverted before storing to FLASH so it is 0xFF
122 too. This prevent's that reading from an erased FLASH
123 results in ECC errors.
126 The databytes are expanded to the given symbol size
127 on the fly. There is no support for encoding continuous
128 bitstreams with a symbol size != 8 at the moment. If
129 it is necessary it should be not a big deal to implement
133 /* Parity buffer. Size = number of roots */
135 /* Initialize the parity buffer */
136 memset(par, 0, sizeof(par));
137 /* Encode 512 byte in data8. Store parity in buffer par */
138 encode_rs8 (rs_decoder, data8, 512, par, 0);
142 <title>Decoding</title>
144 The decoder calculates the syndrome over
145 the given data length and the received parity symbols
146 and corrects errors in the data.
149 If a syndrome is available from a hardware decoder
150 then the syndrome calculation is skipped.
153 The correction of the data buffer can be suppressed
154 by providing a correction pattern buffer and an error
155 location buffer to the decoder. The decoder stores the
156 calculated error location and the correction bitmask
157 in the given buffers. This is useful for hardware
158 decoders which use a weird bit ordering scheme.
161 The databytes are expanded to the given symbol size
162 on the fly. There is no support for decoding continuous
163 bitstreams with a symbolsize != 8 at the moment. If
164 it is necessary it should be not a big deal to implement
170 Decoding with syndrome calculation, direct data correction
173 /* Parity buffer. Size = number of roots */
181 /* Decode 512 byte in data8.*/
182 numerr = decode_rs8 (rs_decoder, data8, par, 512, NULL, 0, NULL, 0, NULL);
188 Decoding with syndrome given by hardware decoder, direct data correction
191 /* Parity buffer. Size = number of roots */
192 uint16_t par[6], syn[6];
199 /* Get syndrome from hardware decoder */
201 /* Decode 512 byte in data8.*/
202 numerr = decode_rs8 (rs_decoder, data8, par, 512, syn, 0, NULL, 0, NULL);
208 Decoding with syndrome given by hardware decoder, no direct data correction.
211 Note: It's not necessary to give data and received parity to the decoder.
214 /* Parity buffer. Size = number of roots */
215 uint16_t par[6], syn[6], corr[8];
217 int numerr, errpos[8];
222 /* Get syndrome from hardware decoder */
224 /* Decode 512 byte in data8.*/
225 numerr = decode_rs8 (rs_decoder, NULL, NULL, 512, syn, 0, errpos, 0, corr);
226 for (i = 0; i < numerr; i++) {
227 do_error_correction_in_your_buffer(errpos[i], corr[i]);
233 <title>Cleanup</title>
235 The function free_rs frees the allocated resources,
236 if the caller is the last user of the decoder.
239 /* Release resources */
246 <chapter id="structs">
247 <title>Structures</title>
249 This chapter contains the autogenerated documentation of the structures which are
250 used in the Reed-Solomon Library and are relevant for a developer.
252 !Iinclude/linux/rslib.h
255 <chapter id="pubfunctions">
256 <title>Public Functions Provided</title>
258 This chapter contains the autogenerated documentation of the Reed-Solomon functions
261 !Elib/reed_solomon/reed_solomon.c
264 <chapter id="credits">
265 <title>Credits</title>
267 The library code for encoding and decoding was written by Phil Karn.
270 Copyright 2002, Phil Karn, KA9Q
271 May be used under the terms of the GNU General Public License (GPL)
274 The wrapper functions and interfaces are written by Thomas Gleixner
277 Many users have provided bugfixes, improvements and helping hands for testing.
281 The following people have contributed to this document:
284 Thomas Gleixner<email>tglx@linutronix.de</email>