libosmocore/include/osmocom/core/conv.h

116 lines
3.4 KiB
C

/*
* conv.h
*
* Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
*
* All Rights Reserved
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*! \defgroup conv Convolutional encoding and decoding routines
* @{
*/
/*! \file conv.h
* \file Osmocom convolutional encoder and decoder
*/
#ifndef __OSMO_CONV_H__
#define __OSMO_CONV_H__
#include <stdint.h>
#include <osmocom/core/bits.h>
/*! \brief structure describing a given convolutional code */
struct osmo_conv_code {
int N;
int K;
int len;
const uint8_t (*next_output)[2];
const uint8_t (*next_state)[2];
const uint8_t *next_term_output;
const uint8_t *next_term_state;
const int *puncture;
};
/* Encoding */
/* Low level API */
/*! \brief convolutional encoder state */
struct osmo_conv_encoder {
const struct osmo_conv_code *code; /*!< \brief for which code? */
int i_idx; /*!< \brief Next input bit index */
int p_idx; /*!< \brief Current puncture index */
uint8_t state; /*!< \brief Current state */
};
void osmo_conv_encode_init(struct osmo_conv_encoder *encoder,
const struct osmo_conv_code *code);
int osmo_conv_encode_raw(struct osmo_conv_encoder *encoder,
const ubit_t *input, ubit_t *output, int n);
int osmo_conv_encode_finish(struct osmo_conv_encoder *encoder, ubit_t *output);
/* All-in-one */
int osmo_conv_encode(const struct osmo_conv_code *code,
const ubit_t *input, ubit_t *output);
/* Decoding */
/* Low level API */
/*! \brief convolutional decoder state */
struct osmo_conv_decoder {
/*! \brief description of convolutional code */
const struct osmo_conv_code *code;
int n_states; /*!< \brief number of states */
int len; /*!< \brief Max o_idx (excl. termination) */
int o_idx; /*!< \brief output index */
int p_idx; /*!< \brief puncture index */
unsigned int *ae; /*!< \brief accumulater error */
unsigned int *ae_next; /*!< \brief next accumulated error (tmp in scan) */
uint8_t *state_history; /*!< \brief state history [len][n_states] */
};
void osmo_conv_decode_init(struct osmo_conv_decoder *decoder,
const struct osmo_conv_code *code, int len);
void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder);
void osmo_conv_decode_deinit(struct osmo_conv_decoder *decoder);
int osmo_conv_decode_scan(struct osmo_conv_decoder *decoder,
const sbit_t *input, int n);
int osmo_conv_decode_finish(struct osmo_conv_decoder *decoder,
const sbit_t *input);
int osmo_conv_decode_get_output(struct osmo_conv_decoder *decoder,
ubit_t *output, int has_finish);
/* All-in-one */
int osmo_conv_decode(const struct osmo_conv_code *code,
const sbit_t *input, ubit_t *output);
/*! }@ */
#endif /* __OSMO_CONV_H__ */