libosmocore  0.9.3
Osmocom core library
include/osmocom/core/conv.h
Go to the documentation of this file.
00001 /*
00002  * conv.h
00003  *
00004  * Copyright (C) 2011  Sylvain Munaut <tnt@246tNt.com>
00005  *
00006  * All Rights Reserved
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License along
00019  * with this program; if not, write to the Free Software Foundation, Inc.,
00020  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00021  */
00022 
00031 #pragma once
00032 
00033 #include <stdint.h>
00034 
00035 #include <osmocom/core/bits.h>
00036 
00044 enum osmo_conv_term {
00045         CONV_TERM_FLUSH = 0,    
00046         CONV_TERM_TRUNCATION,   
00047         CONV_TERM_TAIL_BITING,  
00048 };
00049 
00056 struct osmo_conv_code {
00057         int N;                          
00058         int K;                          
00059         int len;                        
00061         enum osmo_conv_term term;       
00063         const uint8_t (*next_output)[2];
00064         const uint8_t (*next_state)[2]; 
00066         const uint8_t *next_term_output;
00067         const uint8_t *next_term_state; 
00069         const int *puncture;            
00070 };
00071 
00072 
00073 /* Common */
00074 
00075 int osmo_conv_get_input_length(const struct osmo_conv_code *code, int len);
00076 int osmo_conv_get_output_length(const struct osmo_conv_code *code, int len);
00077 
00078 
00079 /* Encoding */
00080 
00081         /* Low level API */
00082 
00084 struct osmo_conv_encoder {
00085         const struct osmo_conv_code *code; 
00086         int i_idx;      
00087         int p_idx;      
00088         uint8_t state;  
00089 };
00090 
00091 void osmo_conv_encode_init(struct osmo_conv_encoder *encoder,
00092                            const struct osmo_conv_code *code);
00093 void osmo_conv_encode_load_state(struct osmo_conv_encoder *encoder,
00094                                  const ubit_t *input);
00095 int  osmo_conv_encode_raw(struct osmo_conv_encoder *encoder,
00096                           const ubit_t *input, ubit_t *output, int n);
00097 int  osmo_conv_encode_flush(struct osmo_conv_encoder *encoder, ubit_t *output);
00098 
00099         /* All-in-one */
00100 int  osmo_conv_encode(const struct osmo_conv_code *code,
00101                       const ubit_t *input, ubit_t *output);
00102 
00103 
00104 /* Decoding */
00105 
00106         /* Low level API */
00107 
00109 struct osmo_conv_decoder {
00110         const struct osmo_conv_code *code; 
00112         int n_states;           
00114         int len;                
00116         int o_idx;              
00117         int p_idx;              
00119         unsigned int *ae;       
00120         unsigned int *ae_next;  
00121         uint8_t *state_history; 
00122 };
00123 
00124 void osmo_conv_decode_init(struct osmo_conv_decoder *decoder,
00125                            const struct osmo_conv_code *code,
00126                            int len, int start_state);
00127 void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder, int start_state);
00128 void osmo_conv_decode_rewind(struct osmo_conv_decoder *decoder);
00129 void osmo_conv_decode_deinit(struct osmo_conv_decoder *decoder);
00130 
00131 int osmo_conv_decode_scan(struct osmo_conv_decoder *decoder,
00132                           const sbit_t *input, int n);
00133 int osmo_conv_decode_flush(struct osmo_conv_decoder *decoder,
00134                            const sbit_t *input);
00135 int osmo_conv_decode_get_output(struct osmo_conv_decoder *decoder,
00136                                 ubit_t *output, int has_flush, int end_state);
00137 
00138         /* All-in-one */
00139 int osmo_conv_decode(const struct osmo_conv_code *code,
00140                      const sbit_t *input, ubit_t *output);
00141 
00142