Sylvain Munaut | 19dc5c9 | 2011-04-23 16:09:19 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | #ifndef __OSMO_CONV_H__ |
| 24 | #define __OSMO_CONV_H__ |
| 25 | |
| 26 | #include <stdint.h> |
| 27 | |
| 28 | #include <osmocom/core/bits.h> |
| 29 | |
| 30 | struct osmo_conv_code { |
| 31 | int N; |
| 32 | int K; |
| 33 | int len; |
| 34 | |
| 35 | const uint8_t (*next_output)[2]; |
| 36 | const uint8_t (*next_state)[2]; |
| 37 | |
| 38 | const uint8_t *next_term_output; |
| 39 | const uint8_t *next_term_state; |
| 40 | |
| 41 | const int *puncture; |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | /* Encoding */ |
| 46 | |
| 47 | /* Low level API */ |
| 48 | struct osmo_conv_encoder { |
| 49 | const struct osmo_conv_code *code; |
| 50 | int i_idx; /* Next input bit index */ |
| 51 | int p_idx; /* Current puncture index */ |
| 52 | uint8_t state; /* Current state */ |
| 53 | }; |
| 54 | |
| 55 | void osmo_conv_encode_init(struct osmo_conv_encoder *encoder, |
| 56 | const struct osmo_conv_code *code); |
| 57 | int osmo_conv_encode_raw(struct osmo_conv_encoder *encoder, |
| 58 | const ubit_t *input, ubit_t *output, int n); |
| 59 | int osmo_conv_encode_finish(struct osmo_conv_encoder *encoder, ubit_t *output); |
| 60 | |
| 61 | /* All-in-one */ |
| 62 | int osmo_conv_encode(const struct osmo_conv_code *code, |
| 63 | const ubit_t *input, ubit_t *output); |
| 64 | |
| 65 | |
| 66 | /* Decoding */ |
| 67 | |
| 68 | /* Low level API */ |
| 69 | struct osmo_conv_decoder { |
| 70 | const struct osmo_conv_code *code; |
| 71 | |
| 72 | int n_states; |
| 73 | |
| 74 | int len; /* Max o_idx (excl. termination) */ |
| 75 | |
| 76 | int o_idx; /* output index */ |
| 77 | int p_idx; /* puncture index */ |
| 78 | |
| 79 | unsigned int *ae; /* accumulater error */ |
| 80 | unsigned int *ae_next; /* next accumulated error (tmp in scan) */ |
| 81 | uint8_t *state_history; /* state history [len][n_states] */ |
| 82 | }; |
| 83 | |
| 84 | void osmo_conv_decode_init(struct osmo_conv_decoder *decoder, |
| 85 | const struct osmo_conv_code *code, int len); |
| 86 | void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder); |
| 87 | void osmo_conv_decode_deinit(struct osmo_conv_decoder *decoder); |
| 88 | |
| 89 | int osmo_conv_decode_scan(struct osmo_conv_decoder *decoder, |
| 90 | const sbit_t *input, int n); |
| 91 | int osmo_conv_decode_finish(struct osmo_conv_decoder *decoder, |
| 92 | const sbit_t *input); |
| 93 | int osmo_conv_decode_get_output(struct osmo_conv_decoder *decoder, |
| 94 | ubit_t *output, int has_finish); |
| 95 | |
| 96 | /* All-in-one */ |
| 97 | int osmo_conv_decode(const struct osmo_conv_code *code, |
| 98 | const sbit_t *input, ubit_t *output); |
| 99 | |
| 100 | |
| 101 | #endif /* __OSMO_CONV_H__ */ |