diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-06-18 18:16:02 +0300 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-07-10 23:42:02 +0200 |
commit | 1389e86d116509884b0e5ee3421fe7683afcab9b (patch) | |
tree | 52ef42f5f49ac3ae52e687cbc7207426fd11e075 /src | |
parent | 548e3712009f68f801be806884d848b47c30dced (diff) |
Add pseudo-random bit sequence generator to libosmcoore
These PRBS sequences are specified in ITU-T O.150. They are typically
used as test data to be transmitted for BER (bit error rate) testing.
Change-Id: I227b6a6e86a251460ecb816afa9a7439d5fb94d1
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/prbs.c | 74 |
2 files changed, 75 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d8fcecac..8e7ef4b4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,7 +21,7 @@ libosmocore_la_SOURCES = timer.c timer_gettimeofday.c select.c signal.c msgb.c b conv.c application.c rbtree.c strrb.c \ loggingrb.c crc8gen.c crc16gen.c crc32gen.c crc64gen.c \ macaddr.c stat_item.c stats.c stats_statsd.c prim.c \ - conv_acc.c conv_acc_generic.c sercomm.c + conv_acc.c conv_acc_generic.c sercomm.c prbs.c if HAVE_SSE3 libosmocore_la_SOURCES += conv_acc_sse.c diff --git a/src/prbs.c b/src/prbs.c new file mode 100644 index 00000000..be52fd4c --- /dev/null +++ b/src/prbs.c @@ -0,0 +1,74 @@ +/* Osmocom implementation of pseudo-random bit sequence generation */ +/* (C) 2017 by Harald Welte <laforge@gnumonks.org> */ + +#include <stdint.h> +#include <string.h> +#include <osmocom/core/bits.h> +#include <osmocom/core/prbs.h> + +/*! \brief PRBS-7 according ITU-T O.150 */ +const struct osmo_prbs osmo_prbs7 = { + /* x^7 + x^6 + 1 */ + .name = "PRBS-7", + .len = 7, + .coeff = (1<<6) | (1<<5), +}; + +/*! \brief PRBS-9 according ITU-T O.150 */ +const struct osmo_prbs osmo_prbs9 = { + /* x^9 + x^5 + 1 */ + .name = "PRBS-9", + .len = 9, + .coeff = (1<<8) | (1<<4), +}; + +/*! \brief PRBS-11 according ITU-T O.150 */ +const struct osmo_prbs osmo_prbs11 = { + /* x^11 + x^9 + 1 */ + .name = "PRBS-11", + .len = 11, + .coeff = (1<<10) | (1<<8), +}; + +/*! \brief PRBS-15 according ITU-T O.150 */ +const struct osmo_prbs osmo_prbs15 = { + /* x^15 + x^14+ 1 */ + .name = "PRBS-15", + .len = 15, + .coeff = (1<<14) | (1<<13), +}; + +/*! \brief Initialize the given caller-allocated PRBS state */ +void osmo_prbs_state_init(struct osmo_prbs_state *st, const struct osmo_prbs *prbs) +{ + memset(st, 0, sizeof(*st)); + st->prbs = prbs; + st->state = 1; +} + +static void osmo_prbs_process_bit(struct osmo_prbs_state *state, ubit_t bit) +{ + state->state >>= 1; + if (bit) + state->state ^= state->prbs->coeff; +} + +/*! \brief Get the next bit out of given PRBS instance */ +ubit_t osmo_prbs_get_ubit(struct osmo_prbs_state *state) +{ + ubit_t result = state->state & 0x1; + osmo_prbs_process_bit(state, result); + + return result; +} + +/*! \brief Fill buffer of unpacked bits with next bits out of given PRBS instance */ +int osmo_prbs_get_ubits(ubit_t *out, unsigned int out_len, struct osmo_prbs_state *state) +{ + unsigned int i; + + for (i = 0; i < out_len; i++) + out[i] = osmo_prbs_get_ubit(state); + + return i; +} |