From 98db75d85ed82979a9f1a681693acf3a8df056c0 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Wed, 14 Dec 2011 23:01:55 +0100 Subject: [PATCH] l1/punct: Add method to generate the puncturing array from a gmr1_puncturer Signed-off-by: Sylvain Munaut --- include/osmocom/gmr1/l1/punct.h | 6 +++++ src/l1/punct.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/osmocom/gmr1/l1/punct.h b/include/osmocom/gmr1/l1/punct.h index 77be5b5..03aaed9 100644 --- a/include/osmocom/gmr1/l1/punct.h +++ b/include/osmocom/gmr1/l1/punct.h @@ -42,6 +42,12 @@ struct gmr1_puncturer { }; +struct osmo_conv_code; + +int gmr1_puncturer_generate(struct osmo_conv_code *code, + const struct gmr1_puncturer *punct); + + /* Various puncturing codes used in GMR-1 */ extern const struct gmr1_puncturer gmr1_punct12_P12; diff --git a/src/l1/punct.c b/src/l1/punct.c index 629c6e5..93669e0 100644 --- a/src/l1/punct.c +++ b/src/l1/punct.c @@ -26,8 +26,54 @@ * \brief Osmocom GMR-1 puncturing implementation */ +#include + #include +#include +#include + + +/*! \brief Generate convolutional code puncturing array for a osmo_conv_code + * \param[inout] code The code for which to generate the puncturing array + * \param[in] punct The puncturing scheme description + * \return 0 for success, <0 for error codes. + * + * The array is allocated with malloc and must be free'd by the caller + * when no longer required. + */ +int +gmr1_puncturer_generate(struct osmo_conv_code *code, + const struct gmr1_puncturer *punct) +{ + int i, j, cl, pl; + int *p; + + /* Safety checks */ + if (code->N != punct->N) + return -EINVAL; + + /* Upper bound for length */ + cl = osmo_conv_get_output_length(code, 0); + pl = ((cl + punct->L - 1) / punct->L) * punct->r + 1; + + /* Alloc array */ + p = malloc(pl * sizeof(int)); + if (!p) + return -ENOMEM; + + code->puncture = p; + + /* Fill */ + for (i=0, j=0; imask[i % (punct->N * punct->L)] == 0) + p[j++] = i; + } + p[j] = -1; + + return 0; +} + /*! \brief GMR-1 P(1;2) puncturing code for the rate 1/2 conv coder */ const struct gmr1_puncturer gmr1_punct12_P12 = {