librs.tmpl 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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" []>
  4. <book id="Reed-Solomon-Library-Guide">
  5. <bookinfo>
  6. <title>Reed-Solomon Library Programming Interface</title>
  7. <authorgroup>
  8. <author>
  9. <firstname>Thomas</firstname>
  10. <surname>Gleixner</surname>
  11. <affiliation>
  12. <address>
  13. <email>tglx@linutronix.de</email>
  14. </address>
  15. </affiliation>
  16. </author>
  17. </authorgroup>
  18. <copyright>
  19. <year>2004</year>
  20. <holder>Thomas Gleixner</holder>
  21. </copyright>
  22. <legalnotice>
  23. <para>
  24. This documentation is free software; you can redistribute
  25. it and/or modify it under the terms of the GNU General Public
  26. License version 2 as published by the Free Software Foundation.
  27. </para>
  28. <para>
  29. This program is distributed in the hope that it will be
  30. useful, but WITHOUT ANY WARRANTY; without even the implied
  31. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  32. See the GNU General Public License for more details.
  33. </para>
  34. <para>
  35. You should have received a copy of the GNU General Public
  36. License along with this program; if not, write to the Free
  37. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  38. MA 02111-1307 USA
  39. </para>
  40. <para>
  41. For more details see the file COPYING in the source
  42. distribution of Linux.
  43. </para>
  44. </legalnotice>
  45. </bookinfo>
  46. <toc></toc>
  47. <chapter id="intro">
  48. <title>Introduction</title>
  49. <para>
  50. The generic Reed-Solomon Library provides encoding, decoding
  51. and error correction functions.
  52. </para>
  53. <para>
  54. Reed-Solomon codes are used in communication and storage
  55. applications to ensure data integrity.
  56. </para>
  57. <para>
  58. This documentation is provided for developers who want to utilize
  59. the functions provided by the library.
  60. </para>
  61. </chapter>
  62. <chapter id="bugs">
  63. <title>Known Bugs And Assumptions</title>
  64. <para>
  65. None.
  66. </para>
  67. </chapter>
  68. <chapter id="usage">
  69. <title>Usage</title>
  70. <para>
  71. This chapter provides examples of how to use the library.
  72. </para>
  73. <sect1>
  74. <title>Initializing</title>
  75. <para>
  76. The init function init_rs returns a pointer to an
  77. rs decoder structure, which holds the necessary
  78. information for encoding, decoding and error correction
  79. with the given polynomial. It either uses an existing
  80. matching decoder or creates a new one. On creation all
  81. the lookup tables for fast en/decoding are created.
  82. The function may take a while, so make sure not to
  83. call it in critical code paths.
  84. </para>
  85. <programlisting>
  86. /* the Reed Solomon control structure */
  87. static struct rs_control *rs_decoder;
  88. /* Symbolsize is 10 (bits)
  89. * Primitive polynomial is x^10+x^3+1
  90. * first consecutive root is 0
  91. * primitive element to generate roots = 1
  92. * generator polynomial degree (number of roots) = 6
  93. */
  94. rs_decoder = init_rs (10, 0x409, 0, 1, 6);
  95. </programlisting>
  96. </sect1>
  97. <sect1>
  98. <title>Encoding</title>
  99. <para>
  100. The encoder calculates the Reed-Solomon code over
  101. the given data length and stores the result in
  102. the parity buffer. Note that the parity buffer must
  103. be initialized before calling the encoder.
  104. </para>
  105. <para>
  106. The expanded data can be inverted on the fly by
  107. providing a non-zero inversion mask. The expanded data is
  108. XOR'ed with the mask. This is used e.g. for FLASH
  109. ECC, where the all 0xFF is inverted to an all 0x00.
  110. The Reed-Solomon code for all 0x00 is all 0x00. The
  111. code is inverted before storing to FLASH so it is 0xFF
  112. too. This prevents that reading from an erased FLASH
  113. results in ECC errors.
  114. </para>
  115. <para>
  116. The databytes are expanded to the given symbol size
  117. on the fly. There is no support for encoding continuous
  118. bitstreams with a symbol size != 8 at the moment. If
  119. it is necessary it should be not a big deal to implement
  120. such functionality.
  121. </para>
  122. <programlisting>
  123. /* Parity buffer. Size = number of roots */
  124. uint16_t par[6];
  125. /* Initialize the parity buffer */
  126. memset(par, 0, sizeof(par));
  127. /* Encode 512 byte in data8. Store parity in buffer par */
  128. encode_rs8 (rs_decoder, data8, 512, par, 0);
  129. </programlisting>
  130. </sect1>
  131. <sect1>
  132. <title>Decoding</title>
  133. <para>
  134. The decoder calculates the syndrome over
  135. the given data length and the received parity symbols
  136. and corrects errors in the data.
  137. </para>
  138. <para>
  139. If a syndrome is available from a hardware decoder
  140. then the syndrome calculation is skipped.
  141. </para>
  142. <para>
  143. The correction of the data buffer can be suppressed
  144. by providing a correction pattern buffer and an error
  145. location buffer to the decoder. The decoder stores the
  146. calculated error location and the correction bitmask
  147. in the given buffers. This is useful for hardware
  148. decoders which use a weird bit ordering scheme.
  149. </para>
  150. <para>
  151. The databytes are expanded to the given symbol size
  152. on the fly. There is no support for decoding continuous
  153. bitstreams with a symbolsize != 8 at the moment. If
  154. it is necessary it should be not a big deal to implement
  155. such functionality.
  156. </para>
  157. <sect2>
  158. <title>
  159. Decoding with syndrome calculation, direct data correction
  160. </title>
  161. <programlisting>
  162. /* Parity buffer. Size = number of roots */
  163. uint16_t par[6];
  164. uint8_t data[512];
  165. int numerr;
  166. /* Receive data */
  167. .....
  168. /* Receive parity */
  169. .....
  170. /* Decode 512 byte in data8.*/
  171. numerr = decode_rs8 (rs_decoder, data8, par, 512, NULL, 0, NULL, 0, NULL);
  172. </programlisting>
  173. </sect2>
  174. <sect2>
  175. <title>
  176. Decoding with syndrome given by hardware decoder, direct data correction
  177. </title>
  178. <programlisting>
  179. /* Parity buffer. Size = number of roots */
  180. uint16_t par[6], syn[6];
  181. uint8_t data[512];
  182. int numerr;
  183. /* Receive data */
  184. .....
  185. /* Receive parity */
  186. .....
  187. /* Get syndrome from hardware decoder */
  188. .....
  189. /* Decode 512 byte in data8.*/
  190. numerr = decode_rs8 (rs_decoder, data8, par, 512, syn, 0, NULL, 0, NULL);
  191. </programlisting>
  192. </sect2>
  193. <sect2>
  194. <title>
  195. Decoding with syndrome given by hardware decoder, no direct data correction.
  196. </title>
  197. <para>
  198. Note: It's not necessary to give data and received parity to the decoder.
  199. </para>
  200. <programlisting>
  201. /* Parity buffer. Size = number of roots */
  202. uint16_t par[6], syn[6], corr[8];
  203. uint8_t data[512];
  204. int numerr, errpos[8];
  205. /* Receive data */
  206. .....
  207. /* Receive parity */
  208. .....
  209. /* Get syndrome from hardware decoder */
  210. .....
  211. /* Decode 512 byte in data8.*/
  212. numerr = decode_rs8 (rs_decoder, NULL, NULL, 512, syn, 0, errpos, 0, corr);
  213. for (i = 0; i &lt; numerr; i++) {
  214. do_error_correction_in_your_buffer(errpos[i], corr[i]);
  215. }
  216. </programlisting>
  217. </sect2>
  218. </sect1>
  219. <sect1>
  220. <title>Cleanup</title>
  221. <para>
  222. The function free_rs frees the allocated resources,
  223. if the caller is the last user of the decoder.
  224. </para>
  225. <programlisting>
  226. /* Release resources */
  227. free_rs(rs_decoder);
  228. </programlisting>
  229. </sect1>
  230. </chapter>
  231. <chapter id="structs">
  232. <title>Structures</title>
  233. <para>
  234. This chapter contains the autogenerated documentation of the structures which are
  235. used in the Reed-Solomon Library and are relevant for a developer.
  236. </para>
  237. !Iinclude/linux/rslib.h
  238. </chapter>
  239. <chapter id="pubfunctions">
  240. <title>Public Functions Provided</title>
  241. <para>
  242. This chapter contains the autogenerated documentation of the Reed-Solomon functions
  243. which are exported.
  244. </para>
  245. !Elib/reed_solomon/reed_solomon.c
  246. </chapter>
  247. <chapter id="credits">
  248. <title>Credits</title>
  249. <para>
  250. The library code for encoding and decoding was written by Phil Karn.
  251. </para>
  252. <programlisting>
  253. Copyright 2002, Phil Karn, KA9Q
  254. May be used under the terms of the GNU General Public License (GPL)
  255. </programlisting>
  256. <para>
  257. The wrapper functions and interfaces are written by Thomas Gleixner.
  258. </para>
  259. <para>
  260. Many users have provided bugfixes, improvements and helping hands for testing.
  261. Thanks a lot.
  262. </para>
  263. <para>
  264. The following people have contributed to this document:
  265. </para>
  266. <para>
  267. Thomas Gleixner<email>tglx@linutronix.de</email>
  268. </para>
  269. </chapter>
  270. </book>