summaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/conv.h
blob: af676eedd69f349f2753d708b3a23521152b7e49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * 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.
 */

#ifndef __OSMO_CONV_H__
#define __OSMO_CONV_H__

#include <stdint.h>

#include <osmocom/core/bits.h>

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 */
struct osmo_conv_encoder {
	const struct osmo_conv_code *code;
	int i_idx;	/* Next input bit index */
	int p_idx;	/* Current puncture index */
	uint8_t state;	/* 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 */
struct osmo_conv_decoder {
	const struct osmo_conv_code *code;

	int n_states;

	int len;		/* Max o_idx (excl. termination) */

	int o_idx;		/* output index */
	int p_idx;		/* puncture index */

	unsigned int *ae;	/* accumulater error */
	unsigned int *ae_next;	/* next accumulated error (tmp in scan) */
	uint8_t *state_history;	/* 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__ */