summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/reed-solomon
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src/lib/reed-solomon')
-rw-r--r--gnuradio-core/src/lib/reed-solomon/CMakeLists.txt62
-rw-r--r--gnuradio-core/src/lib/reed-solomon/char.h11
-rw-r--r--gnuradio-core/src/lib/reed-solomon/decode_rs.c9
-rw-r--r--gnuradio-core/src/lib/reed-solomon/encode_rs.c1
-rw-r--r--gnuradio-core/src/lib/reed-solomon/exercise.c9
-rw-r--r--gnuradio-core/src/lib/reed-solomon/fixed.h6
-rw-r--r--gnuradio-core/src/lib/reed-solomon/int.h11
-rw-r--r--gnuradio-core/src/lib/reed-solomon/rs.h21
8 files changed, 105 insertions, 25 deletions
diff --git a/gnuradio-core/src/lib/reed-solomon/CMakeLists.txt b/gnuradio-core/src/lib/reed-solomon/CMakeLists.txt
new file mode 100644
index 000000000..5640b12a2
--- /dev/null
+++ b/gnuradio-core/src/lib/reed-solomon/CMakeLists.txt
@@ -0,0 +1,62 @@
+# Copyright 2010-2011 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+
+########################################################################
+# This file included, use CMake directory variables
+########################################################################
+#MSVC workaround: we cant have dynamically sized arrays.
+#So ifdef a max array bounds that is larger than NN and NROOTS
+#Its a bit of a hack, but if you look at the code, its so full of ifdefs,
+#and lacks optimization where it should be pre-allocating these arrays.
+IF(MSVC)
+ SET_SOURCE_FILES_PROPERTIES(
+ ${CMAKE_CURRENT_SOURCE_DIR}/exercise.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/decode_rs.c
+ PROPERTIES COMPILE_DEFINITIONS "MAX_ARRAY=256;"
+ )
+ENDIF(MSVC)
+
+SET(gr_core_rs_sources
+ ${CMAKE_CURRENT_SOURCE_DIR}/encode_rs.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/decode_rs.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/init_rs.c
+)
+
+########################################################################
+# Setup sources and includes
+########################################################################
+LIST(APPEND gnuradio_core_sources ${gr_core_rs_sources})
+
+INSTALL(
+ FILES ${CMAKE_CURRENT_SOURCE_DIR}/rs.h
+ DESTINATION ${GR_INCLUDE_DIR}/gnuradio
+ COMPONENT "core_devel"
+)
+
+########################################################################
+# Register unit tests
+########################################################################
+IF(ENABLE_TESTING)
+ADD_EXECUTABLE(gr_core_rstest
+ ${gr_core_rs_sources}
+ ${CMAKE_CURRENT_SOURCE_DIR}/rstest.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/exercise.c
+)
+ADD_TEST(gr-core-reed-solomon-test gr_core_rstest)
+ENDIF(ENABLE_TESTING)
diff --git a/gnuradio-core/src/lib/reed-solomon/char.h b/gnuradio-core/src/lib/reed-solomon/char.h
index 2fbcb504a..8010fb0b9 100644
--- a/gnuradio-core/src/lib/reed-solomon/char.h
+++ b/gnuradio-core/src/lib/reed-solomon/char.h
@@ -6,6 +6,8 @@
#define DTYPE unsigned char
+#include <gr_core_api.h>
+
/* Reed-Solomon codec control block */
struct rs {
unsigned int mm; /* Bits per symbol */
@@ -44,12 +46,11 @@ static inline int modnn(struct rs *rs,int x){
#define INIT_RS init_rs_char
#define FREE_RS free_rs_char
-void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity);
-int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras);
-void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned int fcr,
+GR_CORE_API void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity);
+GR_CORE_API int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras);
+GR_CORE_API void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned int fcr,
unsigned int prim,unsigned int nroots);
-void FREE_RS(void *p);
-
+GR_CORE_API void FREE_RS(void *p);
diff --git a/gnuradio-core/src/lib/reed-solomon/decode_rs.c b/gnuradio-core/src/lib/reed-solomon/decode_rs.c
index 27ddd8532..ba60b89ee 100644
--- a/gnuradio-core/src/lib/reed-solomon/decode_rs.c
+++ b/gnuradio-core/src/lib/reed-solomon/decode_rs.c
@@ -8,7 +8,6 @@
#endif
#include <string.h>
-#include <strings.h>
#define NULL ((void *)0)
#define min(a,b) ((a) < (b) ? (a) : (b))
@@ -32,11 +31,19 @@ DTYPE *data, int *eras_pos, int no_eras){
#endif
int deg_lambda, el, deg_omega;
int i, j, r,k;
+#ifdef MAX_ARRAY
+ DTYPE u,q,tmp,num1,num2,den,discr_r;
+ DTYPE lambda[MAX_ARRAY], s[MAX_ARRAY]; /* Err+Eras Locator poly
+ * and syndrome poly */
+ DTYPE b[MAX_ARRAY], t[MAX_ARRAY], omega[MAX_ARRAY];
+ DTYPE root[MAX_ARRAY], reg[MAX_ARRAY], loc[MAX_ARRAY];
+#else
DTYPE u,q,tmp,num1,num2,den,discr_r;
DTYPE lambda[NROOTS+1], s[NROOTS]; /* Err+Eras Locator poly
* and syndrome poly */
DTYPE b[NROOTS+1], t[NROOTS+1], omega[NROOTS+1];
DTYPE root[NROOTS], reg[NROOTS+1], loc[NROOTS];
+#endif
int syn_error, count;
/* form the syndromes; i.e., evaluate data(x) at roots of g(x) */
diff --git a/gnuradio-core/src/lib/reed-solomon/encode_rs.c b/gnuradio-core/src/lib/reed-solomon/encode_rs.c
index 147f0a9e3..9d56d0bf1 100644
--- a/gnuradio-core/src/lib/reed-solomon/encode_rs.c
+++ b/gnuradio-core/src/lib/reed-solomon/encode_rs.c
@@ -3,7 +3,6 @@
* May be used under the terms of the GNU General Public License (GPL)
*/
#include <string.h>
-#include <strings.h>
#ifdef FIXED
#include "fixed.h"
diff --git a/gnuradio-core/src/lib/reed-solomon/exercise.c b/gnuradio-core/src/lib/reed-solomon/exercise.c
index 1e04f618d..987fe1aeb 100644
--- a/gnuradio-core/src/lib/reed-solomon/exercise.c
+++ b/gnuradio-core/src/lib/reed-solomon/exercise.c
@@ -13,7 +13,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <strings.h>
#ifdef FIXED
#include "fixed.h"
@@ -47,11 +46,19 @@ int trials){
#if !defined(CCSDS) && !defined(FIXED)
struct rs *rs = (struct rs *)p;
#endif
+#if MAX_ARRAY
+ DTYPE block[MAX_ARRAY],tblock[MAX_ARRAY];
+ int i;
+ int errors;
+ int errlocs[MAX_ARRAY];
+ int derrlocs[MAX_ARRAY];
+#else
DTYPE block[NN],tblock[NN];
int i;
int errors;
int errlocs[NN];
int derrlocs[NROOTS];
+#endif
int derrors;
int errval,errloc;
int erasures;
diff --git a/gnuradio-core/src/lib/reed-solomon/fixed.h b/gnuradio-core/src/lib/reed-solomon/fixed.h
index 9f0ddd9a4..30091e7bf 100644
--- a/gnuradio-core/src/lib/reed-solomon/fixed.h
+++ b/gnuradio-core/src/lib/reed-solomon/fixed.h
@@ -7,6 +7,8 @@
*/
#define DTYPE unsigned char
+#include <gr_core_api.h>
+
static inline int mod255(int x){
while (x >= 255) {
x -= 255;
@@ -34,5 +36,5 @@ extern unsigned char CCSDS_poly[];
#define ENCODE_RS encode_rs_8
#define DECODE_RS decode_rs_8
-void ENCODE_RS(DTYPE *data,DTYPE *parity);
-int DECODE_RS(DTYPE *data, int *eras_pos, int no_eras);
+GR_CORE_API void ENCODE_RS(DTYPE *data,DTYPE *parity);
+GR_CORE_API int DECODE_RS(DTYPE *data, int *eras_pos, int no_eras); \ No newline at end of file
diff --git a/gnuradio-core/src/lib/reed-solomon/int.h b/gnuradio-core/src/lib/reed-solomon/int.h
index 2b0405ae0..79979f827 100644
--- a/gnuradio-core/src/lib/reed-solomon/int.h
+++ b/gnuradio-core/src/lib/reed-solomon/int.h
@@ -5,8 +5,10 @@
*/
#define DTYPE int
+#include <gr_core_api.h>
+
/* Reed-Solomon codec control block */
-struct rs {
+struct GR_CORE_API rs {
unsigned int mm; /* Bits per symbol */
unsigned int nn; /* Symbols per block (= (1<<mm)-1) */
int *alpha_to; /* log lookup table */
@@ -43,12 +45,11 @@ static inline int modnn(struct rs *rs,int x){
#define INIT_RS init_rs_int
#define FREE_RS free_rs_int
-void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity);
-int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras);
+GR_CORE_API void ENCODE_RS(void *p,DTYPE *data,DTYPE *parity);
+GR_CORE_API int DECODE_RS(void *p,DTYPE *data,int *eras_pos,int no_eras);
void *INIT_RS(unsigned int symsize,unsigned int gfpoly,unsigned int fcr,
unsigned int prim,unsigned int nroots);
-void FREE_RS(void *p);
-
+GR_CORE_API void FREE_RS(void *p);
diff --git a/gnuradio-core/src/lib/reed-solomon/rs.h b/gnuradio-core/src/lib/reed-solomon/rs.h
index 9e731d9d9..97e78769e 100644
--- a/gnuradio-core/src/lib/reed-solomon/rs.h
+++ b/gnuradio-core/src/lib/reed-solomon/rs.h
@@ -1,28 +1,29 @@
+#include <gr_core_api.h>
/* User include file for the Reed-Solomon codec
* Copyright 2002, Phil Karn KA9Q
* May be used under the terms of the GNU General Public License (GPL)
*/
/* General purpose RS codec, 8-bit symbols */
-void encode_rs_char(void *rs,unsigned char *data,unsigned char *parity);
-int decode_rs_char(void *rs,unsigned char *data,int *eras_pos,
+GR_CORE_API void encode_rs_char(void *rs,unsigned char *data,unsigned char *parity);
+GR_CORE_API int decode_rs_char(void *rs,unsigned char *data,int *eras_pos,
int no_eras);
-void *init_rs_char(unsigned int symsize,unsigned int gfpoly,
+GR_CORE_API void *init_rs_char(unsigned int symsize,unsigned int gfpoly,
unsigned int fcr,unsigned int prim,unsigned int nroots);
-void free_rs_char(void *rs);
+GR_CORE_API void free_rs_char(void *rs);
/* General purpose RS codec, integer symbols */
-void encode_rs_int(void *rs,int *data,int *parity);
-int decode_rs_int(void *rs,int *data,int *eras_pos,int no_eras);
-void *init_rs_int(unsigned int symsize,unsigned int gfpoly,unsigned int fcr,
+GR_CORE_API void encode_rs_int(void *rs,int *data,int *parity);
+GR_CORE_API int decode_rs_int(void *rs,int *data,int *eras_pos,int no_eras);
+GR_CORE_API void *init_rs_int(unsigned int symsize,unsigned int gfpoly,unsigned int fcr,
unsigned int prim,unsigned int nroots);
-void free_rs_int(void *rs);
+GR_CORE_API void free_rs_int(void *rs);
/* CCSDS standard (255,223) RS codec with conventional (*not* dual-basis)
* symbol representation
*/
-void encode_rs_8(unsigned char *data,unsigned char *parity);
-int decode_rs_8(unsigned char *data,int *eras_pos,int no_eras);
+GR_CORE_API void encode_rs_8(unsigned char *data,unsigned char *parity);
+GR_CORE_API int decode_rs_8(unsigned char *data,int *eras_pos,int no_eras);
/* Tables to map from conventional->dual (Taltab) and
* dual->conventional (Tal1tab) bases