From d573723196f4f0c97e64d5a3a7adbabd3d51a429 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 8 Dec 2017 08:16:20 +0100 Subject: Rename prbs to PrbsGenerator Some systems apparently don't like having both prbs.h and Prbs.h in the include paths. OSX seems to be affected --- src/Makefile.am | 2 +- src/PrbsGenerator.cpp | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/PrbsGenerator.h | 71 +++++++++++++++++++++++++ src/input/Prbs.h | 2 +- src/prbs.cpp | 143 -------------------------------------------------- src/prbs.h | 71 ------------------------- 6 files changed, 216 insertions(+), 216 deletions(-) create mode 100644 src/PrbsGenerator.cpp create mode 100644 src/PrbsGenerator.h delete mode 100644 src/prbs.cpp delete mode 100644 src/prbs.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index badc0b9..653da76 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -103,7 +103,7 @@ odr_dabmux_SOURCES =DabMux.cpp DabMux.h \ fig/FIGCarousel.cpp fig/FIGCarousel.h \ fig/TransitionHandler.h \ mpeg.h mpeg.c \ - prbs.h prbs.cpp \ + PrbsGenerator.cpp PrbsGenerator.h \ utils.cpp utils.h \ zmq.hpp \ fec/char.h fec/rs-common.h \ diff --git a/src/PrbsGenerator.cpp b/src/PrbsGenerator.cpp new file mode 100644 index 0000000..1f8437c --- /dev/null +++ b/src/PrbsGenerator.cpp @@ -0,0 +1,143 @@ +/* + Copyright (C) 2005, 2006, 2007, 2008, 2009 Her Majesty the Queen in Right + of Canada (Communications Research Center Canada) + */ +/* + This file is part of ODR-DabMux. + + ODR-DabMux 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 of the + License, or (at your option) any later version. + + ODR-DabMux 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 ODR-DabMux. If not, see . + */ + +#include "PrbsGenerator.h" + +#include +#include + + +/* + * Generate a parity check for a 32-bit word. + */ +static uint32_t parity_check(uint32_t prbs_accum) +{ + uint32_t mask = 1; + uint32_t parity = 0; + for (int i = 0; i < 32; ++i) { + parity ^= ((prbs_accum & mask) != 0); + mask <<= 1; + } + return parity; +} + +void PrbsGenerator::setup(uint32_t polynomial) +{ + this->polynomial = polynomial; + this->accum = 0; + gen_prbs_table(); + gen_weight_table(); +} + +uint8_t PrbsGenerator::step() +{ + accum = update_prbs(); + return accum & 0xff; +} + +void PrbsGenerator::rewind() +{ + while (accum < polynomial) { + accum <<= 1; + accum |= 1; + } +} + +void PrbsGenerator::gen_prbs_table() +{ + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 256; ++j) { + uint32_t prbs_accum = ((uint32_t)j << (i * 8)); + for (int k = 0; k < 8; ++k) { + prbs_accum = (prbs_accum << 1) + ^ parity_check(prbs_accum & polynomial); + } + + prbs_table[i][j] = (prbs_accum & 0xff); + } + } +} + +uint32_t PrbsGenerator::update_prbs() +{ + uint8_t acc_lsb = 0; + for (int i = 0; i < 4; ++i ) { + acc_lsb ^= prbs_table [i] [ (accum >> (i * 8) ) & 0xff ]; + } + return (accum << 8) ^ ((uint32_t)acc_lsb); +} + +void PrbsGenerator::gen_weight_table() +{ + for (int i = 0; i < 256; ++i) { + uint8_t mask = 1; + uint8_t ones_count = 0; + + for (int j = 0; j < 8; ++j) { + ones_count += ((i & mask) != 0); + mask = mask << 1; + } + weight[i] = ones_count; + } +} + +size_t PrbsGenerator::error_count( + uint8_t *rx_data, + size_t rx_data_length) +{ + uint32_t error_count = 0; + uint32_t prbs_accum = 0; + + /* seed the PRBS accumulator */ + for (int i = 0; i < 4; ++i) { + prbs_accum = (prbs_accum << 8) ^ (rx_data[i] ^ polarity_mask); + } + + /* check the received data */ + for (size_t i = 0; i < rx_data_length; ++i) { + uint8_t error_pattern = + (prbs_accum >> 24) ^ (rx_data[i] ^ polarity_mask); + + if (error_pattern != 0) { + error_count += weight[error_pattern]; + } + prbs_accum = update_prbs(); + } + return error_count; +} + +void PrbsGenerator::gen_sequence( + uint8_t *tx_data, + size_t tx_data_length, + uint32_t polynomial) +{ + uint32_t prbs_accum = 0; + + while (prbs_accum < polynomial) { + prbs_accum <<= 1; + prbs_accum |= 1; + } + + for (size_t i = 0; i < tx_data_length; i++) { + prbs_accum = update_prbs(); + tx_data[i] = (uint8_t)(prbs_accum & 0xff); + } +} diff --git a/src/PrbsGenerator.h b/src/PrbsGenerator.h new file mode 100644 index 0000000..0c29965 --- /dev/null +++ b/src/PrbsGenerator.h @@ -0,0 +1,71 @@ +/* + Copyright (C) 2005, 2006, 2007, 2008, 2009 Her Majesty the Queen in Right + of Canada (Communications Research Center Canada) + */ +/* + This file is part of ODR-DabMux. + + ODR-DabMux 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 of the + License, or (at your option) any later version. + + ODR-DabMux 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 ODR-DabMux. If not, see . + */ + +#pragma once + +#include +#include + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +class PrbsGenerator { + public: + void setup(uint32_t polynomial); + + uint8_t step(void); + + void rewind(void); + + private: + /* Generate a table of matrix products to update a 32-bit PRBS + * generator. */ + void gen_prbs_table(void); + + /* Update a 32-bit PRBS generator eight bits at a time. */ + uint32_t update_prbs(void); + + /* Generate the weight table. */ + void gen_weight_table(void); + + /* Count the number of errors in a block of received data. */ + size_t error_count( + uint8_t *rx_data, + size_t rx_data_length); + + void gen_sequence( + uint8_t *tx_data, + size_t tx_data_length, + uint32_t polynomial); + + // table of matrix products used to update a 32-bit PRBS generator + uint32_t prbs_table [4] [256]; + // table of weights for 8-bit bytes + uint8_t weight[256]; + // PRBS polynomial generator + uint32_t polynomial; + // PRBS generator polarity mask + uint8_t polarity_mask; + // PRBS accumulator + uint32_t accum; +}; + diff --git a/src/input/Prbs.h b/src/input/Prbs.h index 3b2b7d4..51b7756 100644 --- a/src/input/Prbs.h +++ b/src/input/Prbs.h @@ -31,7 +31,7 @@ #include #include "input/inputs.h" -#include "prbs.h" +#include "PrbsGenerator.h" namespace Inputs { diff --git a/src/prbs.cpp b/src/prbs.cpp deleted file mode 100644 index b0e3d6d..0000000 --- a/src/prbs.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - Copyright (C) 2005, 2006, 2007, 2008, 2009 Her Majesty the Queen in Right - of Canada (Communications Research Center Canada) - */ -/* - This file is part of ODR-DabMux. - - ODR-DabMux 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 of the - License, or (at your option) any later version. - - ODR-DabMux 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 ODR-DabMux. If not, see . - */ - -#include "prbs.h" - -#include -#include - - -/* - * Generate a parity check for a 32-bit word. - */ -static uint32_t parity_check(uint32_t prbs_accum) -{ - uint32_t mask = 1; - uint32_t parity = 0; - for (int i = 0; i < 32; ++i) { - parity ^= ((prbs_accum & mask) != 0); - mask <<= 1; - } - return parity; -} - -void PrbsGenerator::setup(uint32_t polynomial) -{ - this->polynomial = polynomial; - this->accum = 0; - gen_prbs_table(); - gen_weight_table(); -} - -uint8_t PrbsGenerator::step() -{ - accum = update_prbs(); - return accum & 0xff; -} - -void PrbsGenerator::rewind() -{ - while (accum < polynomial) { - accum <<= 1; - accum |= 1; - } -} - -void PrbsGenerator::gen_prbs_table() -{ - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 256; ++j) { - uint32_t prbs_accum = ((uint32_t)j << (i * 8)); - for (int k = 0; k < 8; ++k) { - prbs_accum = (prbs_accum << 1) - ^ parity_check(prbs_accum & polynomial); - } - - prbs_table[i][j] = (prbs_accum & 0xff); - } - } -} - -uint32_t PrbsGenerator::update_prbs() -{ - uint8_t acc_lsb = 0; - for (int i = 0; i < 4; ++i ) { - acc_lsb ^= prbs_table [i] [ (accum >> (i * 8) ) & 0xff ]; - } - return (accum << 8) ^ ((uint32_t)acc_lsb); -} - -void PrbsGenerator::gen_weight_table() -{ - for (int i = 0; i < 256; ++i) { - uint8_t mask = 1; - uint8_t ones_count = 0; - - for (int j = 0; j < 8; ++j) { - ones_count += ((i & mask) != 0); - mask = mask << 1; - } - weight[i] = ones_count; - } -} - -size_t PrbsGenerator::error_count( - uint8_t *rx_data, - size_t rx_data_length) -{ - uint32_t error_count = 0; - uint32_t prbs_accum = 0; - - /* seed the PRBS accumulator */ - for (int i = 0; i < 4; ++i) { - prbs_accum = (prbs_accum << 8) ^ (rx_data[i] ^ polarity_mask); - } - - /* check the received data */ - for (size_t i = 0; i < rx_data_length; ++i) { - uint8_t error_pattern = - (prbs_accum >> 24) ^ (rx_data[i] ^ polarity_mask); - - if (error_pattern != 0) { - error_count += weight[error_pattern]; - } - prbs_accum = update_prbs(); - } - return error_count; -} - -void PrbsGenerator::gen_sequence( - uint8_t *tx_data, - size_t tx_data_length, - uint32_t polynomial) -{ - uint32_t prbs_accum = 0; - - while (prbs_accum < polynomial) { - prbs_accum <<= 1; - prbs_accum |= 1; - } - - for (size_t i = 0; i < tx_data_length; i++) { - prbs_accum = update_prbs(); - tx_data[i] = (uint8_t)(prbs_accum & 0xff); - } -} diff --git a/src/prbs.h b/src/prbs.h deleted file mode 100644 index 0c29965..0000000 --- a/src/prbs.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - Copyright (C) 2005, 2006, 2007, 2008, 2009 Her Majesty the Queen in Right - of Canada (Communications Research Center Canada) - */ -/* - This file is part of ODR-DabMux. - - ODR-DabMux 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 of the - License, or (at your option) any later version. - - ODR-DabMux 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 ODR-DabMux. If not, see . - */ - -#pragma once - -#include -#include - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -class PrbsGenerator { - public: - void setup(uint32_t polynomial); - - uint8_t step(void); - - void rewind(void); - - private: - /* Generate a table of matrix products to update a 32-bit PRBS - * generator. */ - void gen_prbs_table(void); - - /* Update a 32-bit PRBS generator eight bits at a time. */ - uint32_t update_prbs(void); - - /* Generate the weight table. */ - void gen_weight_table(void); - - /* Count the number of errors in a block of received data. */ - size_t error_count( - uint8_t *rx_data, - size_t rx_data_length); - - void gen_sequence( - uint8_t *tx_data, - size_t tx_data_length, - uint32_t polynomial); - - // table of matrix products used to update a 32-bit PRBS generator - uint32_t prbs_table [4] [256]; - // table of weights for 8-bit bytes - uint8_t weight[256]; - // PRBS polynomial generator - uint32_t polynomial; - // PRBS generator polarity mask - uint8_t polarity_mask; - // PRBS accumulator - uint32_t accum; -}; - -- cgit v1.2.3