GNU Radio's GSM Package
conv.h
Go to the documentation of this file.
1 /*! \file conv.h
2  * Osmocom convolutional encoder and decoder. */
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 
23 /*! \defgroup conv Convolutional encoding and decoding routines
24  * @{
25  * \file conv.h */
26 
27 #pragma once
28 
29 #include <stdint.h>
30 
31 #include <osmocom/core/bits.h>
32 
33 /*! possibe termination types
34  *
35  * The termination type will determine which state the encoder/decoder
36  * can start/end with. This is mostly taken care of in the high level API
37  * call. So if you use the low level API, you must take care of making the
38  * proper calls yourself.
39  */
41  CONV_TERM_FLUSH = 0, /*!< Flush encoder state */
42  CONV_TERM_TRUNCATION, /*!< Direct truncation */
43  CONV_TERM_TAIL_BITING, /*!< Tail biting */
44 };
45 
46 /*! structure describing a given convolutional code
47  *
48  * The only required fields are N,K and the next_output/next_state arrays. The
49  * other can be left to default value of zero depending on what the code does.
50  * If 'len' is left at 0 then only the low level API can be used.
51  */
53  int N; /*!< Inverse of code rate */
54  int K; /*!< Constraint length */
55  int len; /*!< # of data bits */
56 
57  enum osmo_conv_term term; /*!< Termination type */
58 
59  const uint8_t (*next_output)[2];/*!< Next output array */
60  const uint8_t (*next_state)[2]; /*!< Next state array */
61 
62  const uint8_t *next_term_output;/*!< Flush termination output */
63  const uint8_t *next_term_state; /*!< Flush termination state */
64 
65  const int *puncture; /*!< Punctured bits indexes */
66 };
67 
68 
69 /* Common */
70 
71 int osmo_conv_get_input_length(const struct osmo_conv_code *code, int len);
72 int osmo_conv_get_output_length(const struct osmo_conv_code *code, int len);
73 
74 
75 /* Encoding */
76 
77  /* Low level API */
78 
79 /*! convolutional encoder state */
81  const struct osmo_conv_code *code; /*!< for which code? */
82  int i_idx; /*!< Next input bit index */
83  int p_idx; /*!< Current puncture index */
84  uint8_t state; /*!< Current state */
85 };
86 
87 void osmo_conv_encode_init(struct osmo_conv_encoder *encoder,
88  const struct osmo_conv_code *code);
90  const ubit_t *input);
91 int osmo_conv_encode_raw(struct osmo_conv_encoder *encoder,
92  const ubit_t *input, ubit_t *output, int n);
93 int osmo_conv_encode_flush(struct osmo_conv_encoder *encoder, ubit_t *output);
94 
95  /* All-in-one */
96 int osmo_conv_encode(const struct osmo_conv_code *code,
97  const ubit_t *input, ubit_t *output);
98 
99 
100 /* Decoding */
101 
102  /* Low level API */
103 
104 /*! convolutional decoder state */
106  const struct osmo_conv_code *code; /*!< for which code? */
107 
108  int n_states; /*!< number of states */
109 
110  int len; /*!< Max o_idx (excl. termination) */
111 
112  int o_idx; /*!< output index */
113  int p_idx; /*!< puncture index */
114 
115  unsigned int *ae; /*!< accumulated error */
116  unsigned int *ae_next; /*!< next accumulated error (tmp in scan) */
117  uint8_t *state_history; /*!< state history [len][n_states] */
118 };
119 
120 void osmo_conv_decode_init(struct osmo_conv_decoder *decoder,
121  const struct osmo_conv_code *code,
122  int len, int start_state);
123 void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder, int start_state);
124 void osmo_conv_decode_rewind(struct osmo_conv_decoder *decoder);
125 void osmo_conv_decode_deinit(struct osmo_conv_decoder *decoder);
126 
127 int osmo_conv_decode_scan(struct osmo_conv_decoder *decoder,
128  const sbit_t *input, int n);
129 int osmo_conv_decode_flush(struct osmo_conv_decoder *decoder,
130  const sbit_t *input);
132  ubit_t *output, int has_flush, int end_state);
133 
134  /* All-in-one */
135 int osmo_conv_decode(const struct osmo_conv_code *code,
136  const sbit_t *input, ubit_t *output);
137 
138 
139 /*! @} */
osmo_conv_decoder::state_history
uint8_t * state_history
Definition: conv.h:117
osmo_conv_encoder::i_idx
int i_idx
Definition: conv.h:82
osmo_conv_decoder::p_idx
int p_idx
Definition: conv.h:113
CONV_TERM_TRUNCATION
@ CONV_TERM_TRUNCATION
Definition: conv.h:42
osmo_conv_encoder::p_idx
int p_idx
Definition: conv.h:83
osmo_conv_code::term
enum osmo_conv_term term
Definition: conv.h:57
osmo_conv_decoder::ae_next
unsigned int * ae_next
Definition: conv.h:116
osmo_conv_encoder::state
uint8_t state
Definition: conv.h:84
osmo_conv_encode_init
void osmo_conv_encode_init(struct osmo_conv_encoder *encoder, const struct osmo_conv_code *code)
osmo_conv_decode_reset
void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder, int start_state)
osmo_conv_decoder::len
int len
Definition: conv.h:110
osmo_conv_encoder
Definition: conv.h:80
osmo_conv_decode_get_output
int osmo_conv_decode_get_output(struct osmo_conv_decoder *decoder, ubit_t *output, int has_flush, int end_state)
osmo_conv_code::next_term_state
const uint8_t * next_term_state
Definition: conv.h:63
osmo_conv_decoder::o_idx
int o_idx
Definition: conv.h:112
osmo_conv_encode
int osmo_conv_encode(const struct osmo_conv_code *code, const ubit_t *input, ubit_t *output)
osmo_conv_decoder::code
const struct osmo_conv_code * code
Definition: conv.h:106
osmo_conv_decoder::ae
unsigned int * ae
Definition: conv.h:115
osmo_conv_term
osmo_conv_term
Definition: conv.h:40
sbit_t
int8_t sbit_t
Definition: bits.h:21
bits.h
osmo_conv_code::next_output
const uint8_t(* next_output)[2]
Definition: conv.h:59
osmo_conv_decoder
Definition: conv.h:105
osmo_conv_encode_load_state
void osmo_conv_encode_load_state(struct osmo_conv_encoder *encoder, const ubit_t *input)
CONV_TERM_TAIL_BITING
@ CONV_TERM_TAIL_BITING
Definition: conv.h:43
osmo_conv_get_output_length
int osmo_conv_get_output_length(const struct osmo_conv_code *code, int len)
osmo_conv_encode_flush
int osmo_conv_encode_flush(struct osmo_conv_encoder *encoder, ubit_t *output)
osmo_conv_decode_scan
int osmo_conv_decode_scan(struct osmo_conv_decoder *decoder, const sbit_t *input, int n)
osmo_conv_decode_rewind
void osmo_conv_decode_rewind(struct osmo_conv_decoder *decoder)
osmo_conv_decode
int osmo_conv_decode(const struct osmo_conv_code *code, const sbit_t *input, ubit_t *output)
osmo_conv_decode_flush
int osmo_conv_decode_flush(struct osmo_conv_decoder *decoder, const sbit_t *input)
osmo_conv_code::next_state
const uint8_t(* next_state)[2]
Definition: conv.h:60
osmo_conv_encoder::code
const struct osmo_conv_code * code
Definition: conv.h:81
CONV_TERM_FLUSH
@ CONV_TERM_FLUSH
Definition: conv.h:41
osmo_conv_code::K
int K
Definition: conv.h:54
osmo_conv_decode_init
void osmo_conv_decode_init(struct osmo_conv_decoder *decoder, const struct osmo_conv_code *code, int len, int start_state)
osmo_conv_get_input_length
int osmo_conv_get_input_length(const struct osmo_conv_code *code, int len)
osmo_conv_code::puncture
const int * puncture
Definition: conv.h:65
ubit_t
uint8_t ubit_t
Definition: bits.h:24
osmo_conv_code::N
int N
Definition: conv.h:53
osmo_conv_code::next_term_output
const uint8_t * next_term_output
Definition: conv.h:62
osmo_conv_encode_raw
int osmo_conv_encode_raw(struct osmo_conv_encoder *encoder, const ubit_t *input, ubit_t *output, int n)
osmo_conv_code::len
int len
Definition: conv.h:55
osmo_conv_decoder::n_states
int n_states
Definition: conv.h:108
osmo_conv_decode_deinit
void osmo_conv_decode_deinit(struct osmo_conv_decoder *decoder)
osmo_conv_code
Definition: conv.h:52