aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/prbs.cpp61
-rw-r--r--src/prbs.h24
2 files changed, 42 insertions, 43 deletions
diff --git a/src/prbs.cpp b/src/prbs.cpp
index 0ac3187..b0e3d6d 100644
--- a/src/prbs.cpp
+++ b/src/prbs.cpp
@@ -28,18 +28,18 @@
/*
* Generate a parity check for a 32-bit word.
*/
-static unsigned long parity_check(unsigned long prbs_accum)
+static uint32_t parity_check(uint32_t prbs_accum)
{
- unsigned long mask=1UL, parity=0UL;
- int i;
- for (i = 0; i < 32; ++i) {
- parity ^= ((prbs_accum & mask) != 0UL);
+ 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(long polynomial)
+void PrbsGenerator::setup(uint32_t polynomial)
{
this->polynomial = polynomial;
this->accum = 0;
@@ -65,7 +65,7 @@ void PrbsGenerator::gen_prbs_table()
{
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 256; ++j) {
- unsigned long prbs_accum = ((unsigned long)j << (i * 8));
+ 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);
@@ -76,24 +76,23 @@ void PrbsGenerator::gen_prbs_table()
}
}
-unsigned long PrbsGenerator::update_prbs()
+uint32_t PrbsGenerator::update_prbs()
{
- unsigned char acc_lsb = 0;
- int i;
- for (i = 0; i < 4; ++i ) {
+ uint8_t acc_lsb = 0;
+ for (int i = 0; i < 4; ++i ) {
acc_lsb ^= prbs_table [i] [ (accum >> (i * 8) ) & 0xff ];
}
- return (accum << 8) ^ ((unsigned long)acc_lsb);
+ return (accum << 8) ^ ((uint32_t)acc_lsb);
}
void PrbsGenerator::gen_weight_table()
{
for (int i = 0; i < 256; ++i) {
- unsigned char mask = 1U;
- unsigned char ones_count = 0U;
+ uint8_t mask = 1;
+ uint8_t ones_count = 0;
for (int j = 0; j < 8; ++j) {
- ones_count += ((i & mask) != 0U);
+ ones_count += ((i & mask) != 0);
mask = mask << 1;
}
weight[i] = ones_count;
@@ -101,23 +100,23 @@ void PrbsGenerator::gen_weight_table()
}
size_t PrbsGenerator::error_count(
- unsigned char *rx_data,
- int rx_data_length)
+ uint8_t *rx_data,
+ size_t rx_data_length)
{
- unsigned long error_count = 0U;
- unsigned long prbs_accum = 0U;
+ uint32_t error_count = 0;
+ uint32_t prbs_accum = 0;
/* seed the PRBS accumulator */
- for (int i = 0; i < 4; ++i) {
+ for (int i = 0; i < 4; ++i) {
prbs_accum = (prbs_accum << 8) ^ (rx_data[i] ^ polarity_mask);
}
/* check the received data */
- for (int i = 0; i < rx_data_length; ++i) {
- unsigned char error_pattern = (unsigned char)
- ((prbs_accum >> 24)
- ^ (rx_data[i] ^ polarity_mask));
- if (error_pattern != 0U) {
+ 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();
@@ -126,19 +125,19 @@ size_t PrbsGenerator::error_count(
}
void PrbsGenerator::gen_sequence(
- unsigned char *tx_data,
- int tx_data_length,
- unsigned long polynomial)
+ uint8_t *tx_data,
+ size_t tx_data_length,
+ uint32_t polynomial)
{
- unsigned long prbs_accum = 0U;
+ uint32_t prbs_accum = 0;
while (prbs_accum < polynomial) {
prbs_accum <<= 1;
prbs_accum |= 1;
}
- while (tx_data_length-- > 0) {
+ for (size_t i = 0; i < tx_data_length; i++) {
prbs_accum = update_prbs();
- *(tx_data++) = (unsigned char)(prbs_accum & 0xff);
+ tx_data[i] = (uint8_t)(prbs_accum & 0xff);
}
}
diff --git a/src/prbs.h b/src/prbs.h
index 5b6b7c2..0c29965 100644
--- a/src/prbs.h
+++ b/src/prbs.h
@@ -30,7 +30,7 @@
class PrbsGenerator {
public:
- void setup(long polynomial);
+ void setup(uint32_t polynomial);
uint8_t step(void);
@@ -42,30 +42,30 @@ class PrbsGenerator {
void gen_prbs_table(void);
/* Update a 32-bit PRBS generator eight bits at a time. */
- unsigned long update_prbs(void);
+ 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(
- unsigned char *rx_data,
- int rx_data_length);
+ uint8_t *rx_data,
+ size_t rx_data_length);
void gen_sequence(
- unsigned char *tx_data,
- int tx_data_length,
- unsigned long polynomial);
+ uint8_t *tx_data,
+ size_t tx_data_length,
+ uint32_t polynomial);
// table of matrix products used to update a 32-bit PRBS generator
- unsigned long prbs_table [4] [256];
+ uint32_t prbs_table [4] [256];
// table of weights for 8-bit bytes
- unsigned char weight[256];
+ uint8_t weight[256];
// PRBS polynomial generator
- unsigned long polynomial;
+ uint32_t polynomial;
// PRBS generator polarity mask
- unsigned char polarity_mask;
+ uint8_t polarity_mask;
// PRBS accumulator
- unsigned long accum;
+ uint32_t accum;
};