conv.h
Go to the documentation of this file.
/*
* 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.
*/
#pragma once
#include <stdint.h>
#include <osmocom/core/bits.h>
enum osmo_conv_term {
CONV_TERM_FLUSH = 0,
CONV_TERM_TRUNCATION,
CONV_TERM_TAIL_BITING,
};
struct osmo_conv_code {
int N;
int K;
int len;
enum osmo_conv_term term;
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;
};
/* Common */
int osmo_conv_get_input_length(const struct osmo_conv_code *code, int len);
int osmo_conv_get_output_length(const struct osmo_conv_code *code, int len);
/* Encoding */
/* Low level API */
struct osmo_conv_encoder {
const struct osmo_conv_code *code;
int i_idx;
int p_idx;
uint8_t state;
};
void osmo_conv_encode_init(struct osmo_conv_encoder *encoder,
const struct osmo_conv_code *code);
void osmo_conv_encode_load_state(struct osmo_conv_encoder *encoder,
const ubit_t *input);
int osmo_conv_encode_raw(struct osmo_conv_encoder *encoder,
const ubit_t *input, ubit_t *output, int n);
int osmo_conv_encode_flush(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 */
struct osmo_conv_decoder {
const struct osmo_conv_code *code;
int n_states;
int len;
int o_idx;
int p_idx;
unsigned int *ae;
unsigned int *ae_next;
uint8_t *state_history;
};
void osmo_conv_decode_init(struct osmo_conv_decoder *decoder,
const struct osmo_conv_code *code,
int len, int start_state);
void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder, int start_state);
void osmo_conv_decode_rewind(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_flush(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_flush, int end_state);
/* All-in-one */
int osmo_conv_decode(const struct osmo_conv_code *code,
const sbit_t *input, ubit_t *output);
osmo_conv_encoder::code
const struct osmo_conv_code * code
for which code?
Definition: conv.h:85
sbit_t
int8_t sbit_t
soft bit (-127...127)
Definition: bits.h:18
osmo_conv_encoder::p_idx
int p_idx
Current puncture index.
Definition: conv.h:87
osmo_conv_code::term
enum osmo_conv_term term
Termination type.
Definition: conv.h:61
osmo_conv_decoder::ae
unsigned int * ae
accumulated error
Definition: conv.h:119
osmo_conv_encoder
convolutional encoder state
Definition: conv.h:84
osmo_conv_code::next_term_state
const uint8_t * next_term_state
Flush termination state.
Definition: conv.h:67
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:87
osmo_conv_decoder::code
const struct osmo_conv_code * code
for which code?
Definition: conv.h:110
osmo_conv_decoder
convolutional decoder state
Definition: conv.h:109
osmo_conv_code::next_output
const uint8_t(* next_output)[2]
Next output array.
Definition: conv.h:63
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:603
osmo_conv_code
structure describing a given convolutional code
Definition: conv.h:56
osmo_conv_encoder::state
uint8_t state
Current state.
Definition: conv.h:88
CONV_TERM_TRUNCATION
Direct truncation.
Definition: conv.h:46
CONV_TERM_TAIL_BITING
Tail biting.
Definition: conv.h:47
osmo_conv_decoder::o_idx
int o_idx
output index
Definition: conv.h:116
osmo_conv_decoder::p_idx
int p_idx
puncture index
Definition: conv.h:117
osmo_conv_code::next_state
const uint8_t(* next_state)[2]
Next state array.
Definition: conv.h:64
osmo_conv_term
osmo_conv_term
possibe termination types
Definition: conv.h:44
osmo_conv_code::N
int N
Inverse of code rate.
Definition: conv.h:57
osmo_conv_code::puncture
const int * puncture
Punctured bits indexes.
Definition: conv.h:69
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:213
osmo_conv_code::K
int K
Constraint length.
Definition: conv.h:58
bits.h
Osmocom bit level support code.
CONV_TERM_FLUSH
Flush encoder state.
Definition: conv.h:45
osmo_conv_code::len
int len
of data bits
Definition: conv.h:59
osmo_conv_code::next_term_output
const uint8_t * next_term_output
Flush termination output.
Definition: conv.h:66
osmo_conv_decoder::ae_next
unsigned int * ae_next
next accumulated error (tmp in scan)
Definition: conv.h:120
osmo_conv_decoder::state_history
uint8_t * state_history
state history [len][n_states]
Definition: conv.h:121
osmo_conv_decoder::len
int len
Max o_idx (excl. termination)
Definition: conv.h:114
ubit_t
uint8_t ubit_t
unpacked bit (0 or 1)
Definition: bits.h:19
osmo_conv_encoder::i_idx
int i_idx
Next input bit index.
Definition: conv.h:86
osmo_conv_decoder::n_states
int n_states
number of states
Definition: conv.h:112