libosmocore 1.13.1.1-afb4 Osmocom core library

conv.h
Go to the documentation of this file.
1
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
23#pragma once
24
25#include <stdint.h>
26
27#include <osmocom/core/bits.h>
28
36 enum osmo_conv_term {
37 CONV_TERM_FLUSH = 0,
38 CONV_TERM_TRUNCATION,
39 CONV_TERM_TAIL_BITING,
40};
41
48 struct osmo_conv_code {
49 int N;
50 int K;
51 int len;
53 enum osmo_conv_term term;
55 const uint8_t (*next_output)[2];
56 const uint8_t (*next_state)[2];
58 const uint8_t *next_term_output;
59 const uint8_t *next_term_state;
61 const int *puncture;
62};
63
64
65/* Common */
66
67 int osmo_conv_get_input_length(const struct osmo_conv_code *code, int len);
68 int osmo_conv_get_output_length(const struct osmo_conv_code *code, int len);
69
70
71/* Encoding */
72
73 /* Low level API */
74
76 struct osmo_conv_encoder {
77 const struct osmo_conv_code *code;
78 int i_idx;
79 int p_idx;
80 uint8_t state;
81};
82
83 void osmo_conv_encode_init(struct osmo_conv_encoder *encoder,
84 const struct osmo_conv_code *code);
85 void osmo_conv_encode_load_state(struct osmo_conv_encoder *encoder,
86 const ubit_t *input);
87 int osmo_conv_encode_raw(struct osmo_conv_encoder *encoder,
88 const ubit_t *input, ubit_t *output, int n);
89 int osmo_conv_encode_flush(struct osmo_conv_encoder *encoder, ubit_t *output);
90
91 /* All-in-one */
92 int osmo_conv_encode(const struct osmo_conv_code *code,
93 const ubit_t *input, ubit_t *output);
94
95
96/* Decoding */
97
98 /* Low level API */
99
101 struct osmo_conv_decoder {
102 const struct osmo_conv_code *code;
104 int n_states;
106 int len;
108 int o_idx;
109 int p_idx;
111 unsigned int *ae;
112 unsigned int *ae_next;
113 uint8_t *state_history;
114};
115
116 void osmo_conv_decode_init(struct osmo_conv_decoder *decoder,
117 const struct osmo_conv_code *code,
118 int len, int start_state);
119 void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder, int start_state);
120 void osmo_conv_decode_rewind(struct osmo_conv_decoder *decoder);
121 void osmo_conv_decode_deinit(struct osmo_conv_decoder *decoder);
122
123 int osmo_conv_decode_scan(struct osmo_conv_decoder *decoder,
124 const sbit_t *input, int n);
125 int osmo_conv_decode_flush(struct osmo_conv_decoder *decoder,
126 const sbit_t *input);
127 int osmo_conv_decode_get_best_end_state(struct osmo_conv_decoder *decoder);
128 int osmo_conv_decode_get_output(struct osmo_conv_decoder *decoder,
129 ubit_t *output, int has_flush, int end_state);
130
131 /* All-in-one */
132 int osmo_conv_decode(const struct osmo_conv_code *code,
133 const sbit_t *input, ubit_t *output);
134
135
bits.h
Osmocom bit level support code.
ubit_t
uint8_t ubit_t
unpacked bit (0 or 1): 1 bit per byte
Definition: bits.h:24
sbit_t
int8_t sbit_t
soft bit with value (-127...127), as commonly used in communications receivers such as [viterbi] deco...
Definition: bits.h:21
len
static size_t len(const char *str)
n
write Write running configuration to or terminal n Write configuration to the copy running config startup Copy configuration n Copy running config to n Copy running config to startup write Write running configuration to or terminal n Write to terminal n
osmo_conv_decode_rewind
void osmo_conv_decode_rewind(struct osmo_conv_decoder *decoder)
Definition: conv.c:291
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)
Definition: conv.c:578
osmo_conv_encode_raw
int osmo_conv_encode_raw(struct osmo_conv_encoder *encoder, const ubit_t *input, ubit_t *output, int n)
Definition: conv.c:133
osmo_conv_get_output_length
int osmo_conv_get_output_length(const struct osmo_conv_code *code, int len)
Definition: conv.c:51
osmo_conv_decode_reset
void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder, int start_state)
Definition: conv.c:270
osmo_conv_encode_init
void osmo_conv_encode_init(struct osmo_conv_encoder *encoder, const struct osmo_conv_code *code)
Initialize a convolutional encoder.
Definition: conv.c:83
osmo_conv_decode_scan
int osmo_conv_decode_scan(struct osmo_conv_decoder *decoder, const sbit_t *input, int n)
Definition: conv.c:321
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)
Definition: conv.c:241
osmo_conv_decode
int osmo_conv_decode(const struct osmo_conv_code *code, const sbit_t *input, ubit_t *output)
All-in-one convolutional decoding function.
Definition: conv.c:642
osmo_conv_encode
int osmo_conv_encode(const struct osmo_conv_code *code, const ubit_t *input, ubit_t *output)
All-in-one convolutional encoding function.
Definition: conv.c:207
osmo_conv_get_input_length
int osmo_conv_get_input_length(const struct osmo_conv_code *code, int len)
Definition: conv.c:45
osmo_conv_encode_flush
int osmo_conv_encode_flush(struct osmo_conv_encoder *encoder, ubit_t *output)
Definition: conv.c:162
osmo_conv_decode_deinit
void osmo_conv_decode_deinit(struct osmo_conv_decoder *decoder)
Definition: conv.c:311
osmo_conv_encode_load_state
void osmo_conv_encode_load_state(struct osmo_conv_encoder *encoder, const ubit_t *input)
Definition: conv.c:92
osmo_conv_decode_get_best_end_state
int osmo_conv_decode_get_best_end_state(struct osmo_conv_decoder *decoder)
Definition: conv.c:519
osmo_conv_decode_flush
int osmo_conv_decode_flush(struct osmo_conv_decoder *decoder, const sbit_t *input)
Definition: conv.c:418
osmo_conv_term
osmo_conv_term
possibe termination types
Definition: conv.h:36
CONV_TERM_FLUSH
@ CONV_TERM_FLUSH
Flush encoder state.
Definition: conv.h:37
CONV_TERM_TAIL_BITING
@ CONV_TERM_TAIL_BITING
Tail biting.
Definition: conv.h:39
CONV_TERM_TRUNCATION
@ CONV_TERM_TRUNCATION
Direct truncation.
Definition: conv.h:38
osmo_conv_code
structure describing a given convolutional code
Definition: conv.h:48
osmo_conv_code::len
int len
Definition: conv.h:51
osmo_conv_code::next_output
const uint8_t(* next_output)[2]
Next output array.
Definition: conv.h:55
osmo_conv_code::next_term_state
const uint8_t * next_term_state
Flush termination state
Definition: conv.h:59
osmo_conv_code::N
int N
Inverse of code rate.
Definition: conv.h:49
osmo_conv_code::term
enum osmo_conv_term term
Termination type.
Definition: conv.h:53
osmo_conv_code::puncture
const int * puncture
Punctured bits indexes.
Definition: conv.h:61
osmo_conv_code::K
int K
Constraint length.
Definition: conv.h:50
osmo_conv_code::next_term_output
const uint8_t * next_term_output
Flush termination output.
Definition: conv.h:58
osmo_conv_code::next_state
const uint8_t(* next_state)[2]
Next state array
Definition: conv.h:56
osmo_conv_decoder
convolutional decoder state
Definition: conv.h:101
osmo_conv_decoder::code
const struct osmo_conv_code * code
for which code?
Definition: conv.h:102
osmo_conv_decoder::state_history
uint8_t * state_history
state history [len][n_states]
Definition: conv.h:113
osmo_conv_decoder::ae
unsigned int * ae
accumulated error
Definition: conv.h:111
osmo_conv_decoder::len
int len
Max o_idx (excl.
Definition: conv.h:106
osmo_conv_decoder::ae_next
unsigned int * ae_next
next accumulated error (tmp in scan)
Definition: conv.h:112
osmo_conv_decoder::o_idx
int o_idx
output index
Definition: conv.h:108
osmo_conv_decoder::n_states
int n_states
number of states
Definition: conv.h:104
osmo_conv_decoder::p_idx
int p_idx
puncture index
Definition: conv.h:109
osmo_conv_encoder
convolutional encoder state
Definition: conv.h:76
osmo_conv_encoder::code
const struct osmo_conv_code * code
for which code?
Definition: conv.h:77
osmo_conv_encoder::state
uint8_t state
Current state.
Definition: conv.h:80
osmo_conv_encoder::p_idx
int p_idx
Current puncture index.
Definition: conv.h:79
osmo_conv_encoder::i_idx
int i_idx
Next input bit index.
Definition: conv.h:78