Blame view
include/linux/rslib.h
2.99 KB
03ead8427 [LIB] reed_solomo... |
1 |
/* |
1da177e4c Linux-2.6.12-rc2 |
2 3 4 5 |
* include/linux/rslib.h * * Overview: * Generic Reed Solomon encoder / decoder library |
03ead8427 [LIB] reed_solomo... |
6 |
* |
1da177e4c Linux-2.6.12-rc2 |
7 8 9 10 11 |
* Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) * * RS code lifted from reed solomon library written by Phil Karn * Copyright 2002 Phil Karn, KA9Q * |
03ead8427 [LIB] reed_solomo... |
12 |
* $Id: rslib.h,v 1.4 2005/11/07 11:14:52 gleixner Exp $ |
1da177e4c Linux-2.6.12-rc2 |
13 14 15 16 17 18 19 20 21 22 |
* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #ifndef _RSLIB_H_ #define _RSLIB_H_ #include <linux/list.h> |
03ead8427 [LIB] reed_solomo... |
23 |
/** |
1da177e4c Linux-2.6.12-rc2 |
24 |
* struct rs_control - rs control structure |
03ead8427 [LIB] reed_solomo... |
25 |
* |
1da177e4c Linux-2.6.12-rc2 |
26 27 28 29 |
* @mm: Bits per symbol * @nn: Symbols per block (= (1<<mm)-1) * @alpha_to: log lookup table * @index_of: Antilog lookup table |
03ead8427 [LIB] reed_solomo... |
30 |
* @genpoly: Generator polynomial |
1da177e4c Linux-2.6.12-rc2 |
31 32 |
* @nroots: Number of generator roots = number of parity symbols * @fcr: First consecutive root, index form |
03ead8427 [LIB] reed_solomo... |
33 34 35 |
* @prim: Primitive element, index form * @iprim: prim-th root of 1, index form * @gfpoly: The primitive generator polynominal |
d7e5a5462 [RSLIB] Support n... |
36 |
* @gffunc: Function to generate the field, if non-canonical representation |
03ead8427 [LIB] reed_solomo... |
37 |
* @users: Users of this structure |
1da177e4c Linux-2.6.12-rc2 |
38 39 40 41 42 43 44 45 46 47 48 49 50 |
* @list: List entry for the rs control list */ struct rs_control { int mm; int nn; uint16_t *alpha_to; uint16_t *index_of; uint16_t *genpoly; int nroots; int fcr; int prim; int iprim; int gfpoly; |
d7e5a5462 [RSLIB] Support n... |
51 |
int (*gffunc)(int); |
1da177e4c Linux-2.6.12-rc2 |
52 53 54 55 56 57 58 59 60 61 |
int users; struct list_head list; }; /* General purpose RS codec, 8-bit data width, symbol width 1-15 bit */ #ifdef CONFIG_REED_SOLOMON_ENC8 int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par, uint16_t invmsk); #endif #ifdef CONFIG_REED_SOLOMON_DEC8 |
03ead8427 [LIB] reed_solomo... |
62 |
int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len, |
1da177e4c Linux-2.6.12-rc2 |
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, uint16_t *corr); #endif /* General purpose RS codec, 16-bit data width, symbol width 1-15 bit */ #ifdef CONFIG_REED_SOLOMON_ENC16 int encode_rs16(struct rs_control *rs, uint16_t *data, int len, uint16_t *par, uint16_t invmsk); #endif #ifdef CONFIG_REED_SOLOMON_DEC16 int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len, uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, uint16_t *corr); #endif /* Create or get a matching rs control structure */ |
03ead8427 [LIB] reed_solomo... |
79 |
struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim, |
1da177e4c Linux-2.6.12-rc2 |
80 |
int nroots); |
d7e5a5462 [RSLIB] Support n... |
81 82 |
struct rs_control *init_rs_non_canonical(int symsize, int (*func)(int), int fcr, int prim, int nroots); |
1da177e4c Linux-2.6.12-rc2 |
83 84 85 86 87 88 89 90 91 92 |
/* Release a rs control structure */ void free_rs(struct rs_control *rs); /** modulo replacement for galois field arithmetics * * @rs: the rs control structure * @x: the value to reduce * * where |
03ead8427 [LIB] reed_solomo... |
93 |
* rs->mm = number of bits per symbol |
1da177e4c Linux-2.6.12-rc2 |
94 |
* rs->nn = (2^rs->mm) - 1 |
03ead8427 [LIB] reed_solomo... |
95 |
* |
1da177e4c Linux-2.6.12-rc2 |
96 97 98 99 100 101 102 103 104 105 106 107 108 |
* Simple arithmetic modulo would return a wrong result for values * >= 3 * rs->nn */ static inline int rs_modnn(struct rs_control *rs, int x) { while (x >= rs->nn) { x -= rs->nn; x = (x >> rs->mm) + (x & rs->nn); } return x; } #endif |