1 /* -*- c++ -*- */
2 /*
3  * Copyright 2015 Free Software Foundation, Inc.
4  *
5  * This is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3, or (at your option)
8  * any later version.
9  *
10  * This software is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this software; see the file COPYING.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef INCLUDED_DTV_DVBT2_FRAMEMAPPER_CC_IMPL_H
22 #define INCLUDED_DTV_DVBT2_FRAMEMAPPER_CC_IMPL_H
23 
24 #include "../dvb/dvb_defines.h"
25 
26 #include <gnuradio/dtv/dvbt2_framemapper_cc.h>
27 
28 #define KBCH_1_4 3072
29 #define NBCH_1_4 3240
30 #define KBCH_1_2 7032
31 #define NBCH_1_2 7200
32 
33 #define KSIG_PRE 200
34 #define KSIG_POST 350
35 #define NBCH_PARITY 168
36 
37 typedef struct {
38     int type;
39     int bwt_ext;
40     int s1;
41     int s2;
42     int l1_repetition_flag;
43     int guard_interval;
44     int papr;
45     int l1_mod;
46     int l1_cod;
47     int l1_fec_type;
48     int l1_post_size;
49     int l1_post_info_size;
50     int pilot_pattern;
51     int tx_id_availability;
52     int cell_id;
53     int network_id;
54     int t2_system_id;
55     int num_t2_frames;
56     int num_data_symbols;
57     int regen_flag;
58     int l1_post_extension;
59     int num_rf;
60     int current_rf_index;
61     int t2_version;
62     int l1_post_scrambled;
63     int t2_base_lite;
64     int reserved;
65     int crc_32;
66 } L1Pre;
67 
68 typedef struct {
69     int sub_slices_per_frame;
70     int num_plp;
71     int num_aux;
72     int aux_config_rfu;
73     int rf_idx;
74     int frequency;
75     int plp_id;
76     int plp_type;
77     int plp_payload_type;
78     int ff_flag;
79     int first_rf_idx;
80     int first_frame_idx;
81     int plp_group_id;
82     int plp_cod;
83     int plp_mod;
84     int plp_rotation;
85     int plp_fec_type;
86     int plp_num_blocks_max;
87     int frame_interval;
88     int time_il_length;
89     int time_il_type;
90     int in_band_a_flag;
91     int in_band_b_flag;
92     int reserved_1;
93     int plp_mode;
94     int static_flag;
95     int static_padding_flag;
96     int fef_length_msb;
97     int reserved_2;
98     int frame_idx;
99     int sub_slice_interval;
100     int type_2_start;
101     int l1_change_counter;
102     int start_rf_idx;
103     int reserved_3;
104     int plp_id_dynamic;
105     int plp_start;
106     int plp_num_blocks;
107     int reserved_4;
108     int reserved_5;
109 } L1Post;
110 
111 typedef struct {
112     L1Pre l1pre_data;
113     L1Post l1post_data;
114 } L1Signalling;
115 
116 typedef struct {
117     int table_length;
118     int d[LDPC_ENCODE_TABLE_LENGTH];
119     int p[LDPC_ENCODE_TABLE_LENGTH];
120 } l1pre_ldpc_encode_table;
121 
122 typedef struct {
123     int table_length;
124     int d[LDPC_ENCODE_TABLE_LENGTH];
125     int p[LDPC_ENCODE_TABLE_LENGTH];
126 } l1post_ldpc_encode_table;
127 
128 namespace gr {
129 namespace dtv {
130 
131 class dvbt2_framemapper_cc_impl : public dvbt2_framemapper_cc
132 {
133 private:
134     int cell_size;
135     int stream_items;
136     int mapped_items;
137     int l1_constellation;
138     int fft_size;
139     int eta_mod;
140     int t2_frames;
141     int t2_frame_num;
142     int l1_scrambled;
143     int N_P2;
144     int C_P2;
145     int N_FC;
146     int C_FC;
147     int C_DATA;
148     int N_post;
149     int N_punc;
150     L1Signalling L1_Signalling[1];
151     void add_l1pre(gr_complex*);
152     void add_l1post(gr_complex*, int);
153     int add_crc32_bits(unsigned char*, int);
154     unsigned int m_poly_s_12[6];
155     int poly_mult(const int*, int, const int*, int, int*);
156     void poly_pack(const int*, unsigned int*, int);
157     void poly_reverse(int*, int*, int);
158     inline void reg_6_shift(unsigned int*);
159     void bch_poly_build_tables(void);
160     void l1pre_ldpc_lookup_generate(void);
161     void l1post_ldpc_lookup_generate(void);
162     void init_dummy_randomizer(void);
163     void init_l1_randomizer(void);
164     l1pre_ldpc_encode_table l1pre_ldpc_encode;
165     l1post_ldpc_encode_table l1post_ldpc_encode;
166     unsigned char l1_temp[FRAME_SIZE_SHORT];
167     unsigned char l1_interleave[FRAME_SIZE_SHORT];
168     unsigned char l1_map[KBCH_1_2];
169     unsigned char l1_randomize[KBCH_1_2];
170     gr_complex* zigzag_interleave;
171     gr_complex* dummy_randomize;
172     gr_complex l1pre_cache[1840];
173     gr_complex unmodulated;
174     gr_complex m_bpsk[2];
175     gr_complex m_qpsk[4];
176     gr_complex m_16qam[16];
177     gr_complex m_64qam[64];
178 
179     const static int ldpc_tab_1_4S[9][13];
180     const static int ldpc_tab_1_2S[20][9];
181 
182     const static int pre_puncture[36];
183     const static int post_padding_bqpsk[20];
184     const static int post_padding_16qam[20];
185     const static int post_padding_64qam[20];
186     const static int post_puncture_bqpsk[25];
187     const static int post_puncture_16qam[25];
188     const static int post_puncture_64qam[25];
189 
190     const static int mux16[8];
191     const static int mux64[12];
192 
193 public:
194     dvbt2_framemapper_cc_impl(dvb_framesize_t framesize,
195                               dvb_code_rate_t rate,
196                               dvb_constellation_t constellation,
197                               dvbt2_rotation_t rotation,
198                               int fecblocks,
199                               int tiblocks,
200                               dvbt2_extended_carrier_t carriermode,
201                               dvbt2_fftsize_t fftsize,
202                               dvb_guardinterval_t guardinterval,
203                               dvbt2_l1constellation_t l1constellation,
204                               dvbt2_pilotpattern_t pilotpattern,
205                               int t2frames,
206                               int numdatasyms,
207                               dvbt2_papr_t paprmode,
208                               dvbt2_version_t version,
209                               dvbt2_preamble_t preamble,
210                               dvbt2_inputmode_t inputmode,
211                               dvbt2_reservedbiasbits_t reservedbiasbits,
212                               dvbt2_l1scrambled_t l1scrambled,
213                               dvbt2_inband_t inband);
214     ~dvbt2_framemapper_cc_impl();
215 
216     void forecast(int noutput_items, gr_vector_int& ninput_items_required);
217 
218     int general_work(int noutput_items,
219                      gr_vector_int& ninput_items,
220                      gr_vector_const_void_star& input_items,
221                      gr_vector_void_star& output_items);
222 };
223 
224 } // namespace dtv
225 } // namespace gr
226 
227 #endif /* INCLUDED_DTV_DVBT2_FRAMEMAPPER_CC_IMPL_H */
228