blob: db3058cd84656a6fd177832479ec4ad3942769a4 [file] [log] [blame]
Sylvain Munaut19dc5c92011-04-23 16:09:19 +02001/*
2 * conv.h
3 *
4 * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
Harald Welteba6988b2011-08-17 12:46:48 +020023/*! \defgroup conv Convolutional encoding and decoding routines
24 * @{
25 */
26
27/*! \file conv.h
28 * \file Osmocom convolutional encoder and decoder
29 */
30
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020031#ifndef __OSMO_CONV_H__
32#define __OSMO_CONV_H__
33
34#include <stdint.h>
35
36#include <osmocom/core/bits.h>
37
Harald Welteba6988b2011-08-17 12:46:48 +020038/*! \brief structure describing a given convolutional code */
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020039struct osmo_conv_code {
40 int N;
41 int K;
42 int len;
43
44 const uint8_t (*next_output)[2];
45 const uint8_t (*next_state)[2];
46
47 const uint8_t *next_term_output;
48 const uint8_t *next_term_state;
49
50 const int *puncture;
51};
52
53
54/* Encoding */
55
56 /* Low level API */
Harald Welteba6988b2011-08-17 12:46:48 +020057/*! \brief convolutional encoder state */
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020058struct osmo_conv_encoder {
Harald Welteba6988b2011-08-17 12:46:48 +020059 const struct osmo_conv_code *code; /*!< \brief for which code? */
60 int i_idx; /*!< \brief Next input bit index */
61 int p_idx; /*!< \brief Current puncture index */
62 uint8_t state; /*!< \brief Current state */
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020063};
64
65void osmo_conv_encode_init(struct osmo_conv_encoder *encoder,
66 const struct osmo_conv_code *code);
67int osmo_conv_encode_raw(struct osmo_conv_encoder *encoder,
68 const ubit_t *input, ubit_t *output, int n);
69int osmo_conv_encode_finish(struct osmo_conv_encoder *encoder, ubit_t *output);
70
71 /* All-in-one */
72int osmo_conv_encode(const struct osmo_conv_code *code,
73 const ubit_t *input, ubit_t *output);
74
75
76/* Decoding */
77
78 /* Low level API */
Harald Welteba6988b2011-08-17 12:46:48 +020079/*! \brief convolutional decoder state */
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020080struct osmo_conv_decoder {
Harald Welteba6988b2011-08-17 12:46:48 +020081 /*! \brief description of convolutional code */
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020082 const struct osmo_conv_code *code;
83
Harald Welteba6988b2011-08-17 12:46:48 +020084 int n_states; /*!< \brief number of states */
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020085
Harald Welteba6988b2011-08-17 12:46:48 +020086 int len; /*!< \brief Max o_idx (excl. termination) */
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020087
Harald Welteba6988b2011-08-17 12:46:48 +020088 int o_idx; /*!< \brief output index */
89 int p_idx; /*!< \brief puncture index */
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020090
Harald Welteba6988b2011-08-17 12:46:48 +020091 unsigned int *ae; /*!< \brief accumulater error */
92 unsigned int *ae_next; /*!< \brief next accumulated error (tmp in scan) */
93 uint8_t *state_history; /*!< \brief state history [len][n_states] */
Sylvain Munaut19dc5c92011-04-23 16:09:19 +020094};
95
96void osmo_conv_decode_init(struct osmo_conv_decoder *decoder,
97 const struct osmo_conv_code *code, int len);
98void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder);
99void osmo_conv_decode_deinit(struct osmo_conv_decoder *decoder);
100
101int osmo_conv_decode_scan(struct osmo_conv_decoder *decoder,
102 const sbit_t *input, int n);
103int osmo_conv_decode_finish(struct osmo_conv_decoder *decoder,
104 const sbit_t *input);
105int osmo_conv_decode_get_output(struct osmo_conv_decoder *decoder,
106 ubit_t *output, int has_finish);
107
108 /* All-in-one */
109int osmo_conv_decode(const struct osmo_conv_code *code,
110 const sbit_t *input, ubit_t *output);
111
112
Harald Welteba6988b2011-08-17 12:46:48 +0200113/*! }@ */
114
Sylvain Munaut19dc5c92011-04-23 16:09:19 +0200115#endif /* __OSMO_CONV_H__ */