dlsch_coding.c 16.2 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21 22

/*! \file PHY/LTE_TRANSPORT/dlsch_coding.c
23
 * \brief Top-level routines for implementing Turbo-coded (DLSCH) transport channels from 36-212, V8.6 2009-03, V14.1 2017 (includes FeMBMS support)
laurent's avatar
laurent committed
24 25 26 27
 * \author R. Knopp
 * \date 2011
 * \version 0.1
 * \company Eurecom
28
 * \email: knopp@eurecom.fr, jaiver.morgade@ieee.org
laurent's avatar
laurent committed
29 30 31
 * \note
 * \warning
 */
32

33 34 35 36
#include "PHY/defs_eNB.h"
#include "PHY/phy_extern.h"
#include "PHY/CODING/coding_defs.h"
#include "PHY/CODING/coding_extern.h"
37
#include "PHY/CODING/lte_interleaver_inline.h"
38 39 40
#include "PHY/LTE_TRANSPORT/transport_eNB.h"
#include "PHY/LTE_TRANSPORT/transport_proto.h"
#include "SCHED/sched_eNB.h"
41 42
#include "common/utils/LOG/vcd_signal_dumper.h"
#include "common/utils/LOG/log.h"
43
#include "targets/RT/USER/lte-softmodem.h"
44
#include <syscall.h>
45
#include "targets/RT/USER/rt_wrapper.h"
laurent's avatar
laurent committed
46
#include <common/utils/threadPool/thread-pool.h>
47

48
//#define DEBUG_DLSCH_CODING
49 50 51
//#define DEBUG_DLSCH_FREE 1

/*
laurent's avatar
laurent committed
52
  #define is_not_pilot(pilots,first_pilot,re) (pilots==0) || \
53 54
  ((pilots==1)&&(first_pilot==1)&&(((re>2)&&(re<6))||((re>8)&&(re<12)))) || \
  ((pilots==1)&&(first_pilot==0)&&(((re<3))||((re>5)&&(re<9)))) \
55 56
*/
#define is_not_pilot(pilots,first_pilot,re) (1)
Wang Tsu-Han's avatar
Wang Tsu-Han committed
57
/*extern void thread_top_init(char *thread_name,
laurent's avatar
laurent committed
58 59 60 61
  int affinity,
  uint64_t runtime,
  uint64_t deadline,
  uint64_t period);*/
62

63
extern volatile int oai_exit;
64

65
void free_eNB_dlsch(LTE_eNB_DLSCH_t *dlsch) {
66
  int i, r, aa, layer;
67 68

  if (dlsch) {
69 70
    for (layer=0; layer<4; layer++) {
      for (aa=0; aa<64; aa++) free16(dlsch->ue_spec_bf_weights[layer][aa], OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t));
71 72

      free16(dlsch->ue_spec_bf_weights[layer], 64*sizeof(int32_t *));
73
    }
74

75
    for (i=0; i<dlsch->Mdlharq; i++) {
76
      if (dlsch->harq_processes[i]) {
77 78 79 80
        if (dlsch->harq_processes[i]->b) {
          free16(dlsch->harq_processes[i]->b,MAX_DLSCH_PAYLOAD_BYTES);
          dlsch->harq_processes[i]->b = NULL;
        }
81

82 83 84 85 86
        for (r=0; r<MAX_NUM_DLSCH_SEGMENTS; r++) {
          if (dlsch->harq_processes[i]->c[r]) {
            free16(dlsch->harq_processes[i]->c[r],((r==0)?8:0) + 3+768);
            dlsch->harq_processes[i]->c[r] = NULL;
          }
87 88 89 90
        }

        free16(dlsch->harq_processes[i],sizeof(LTE_DL_eNB_HARQ_t));
        dlsch->harq_processes[i] = NULL;
91 92
      }
    }
93

94
    free16(dlsch,sizeof(LTE_eNB_DLSCH_t));
95
  }
96 97
}

98 99 100 101 102 103 104 105

LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,
                               unsigned char Mdlharq,
                               uint32_t Nsoft,
                               unsigned char N_RB_DL,
                               uint8_t abstraction_flag,
                               LTE_DL_FRAME_PARMS *frame_parms)
{
106
  LTE_eNB_DLSCH_t *dlsch;
laurent's avatar
laurent committed
107
  unsigned char exit_flag = 0,i,r,aa,layer;
108
  int re;
109
  unsigned char bw_scaling =1;
110 111

  switch (N_RB_DL) {
laurent's avatar
laurent committed
112 113 114
  case 6:
    bw_scaling =16;
    break;
115

laurent's avatar
laurent committed
116 117 118
  case 25:
    bw_scaling =4;
    break;
119

laurent's avatar
laurent committed
120 121 122
  case 50:
    bw_scaling =2;
    break;
123

laurent's avatar
laurent committed
124 125 126
  default:
    bw_scaling =1;
    break;
127
  }
128

129
  dlsch = (LTE_eNB_DLSCH_t *)malloc16(sizeof(LTE_eNB_DLSCH_t));
130

131 132 133 134
  if (dlsch) {
    bzero(dlsch,sizeof(LTE_eNB_DLSCH_t));
    dlsch->Kmimo = Kmimo;
    dlsch->Mdlharq = Mdlharq;
islam.galal's avatar
islam.galal committed
135
    dlsch->Mlimit = 8;
136
    dlsch->Nsoft = Nsoft;
137

138
    for (layer=0; layer<4; layer++) {
139 140
      dlsch->ue_spec_bf_weights[layer] = (int32_t **)malloc16(64*sizeof(int32_t *));

141
      for (aa=0; aa<64; aa++) {
142 143 144 145 146
        dlsch->ue_spec_bf_weights[layer][aa] = (int32_t *)malloc16(OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t));

        for (re=0; re<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; re++) {
          dlsch->ue_spec_bf_weights[layer][aa][re] = 0x00007fff;
        }
147 148
      }
    }
149

150 151
    // NOTE: THIS HAS TO BE REVISED FOR RU, commenting to remove memory leak !!!!!
    /*
laurent's avatar
laurent committed
152 153 154
      dlsch->calib_dl_ch_estimates = (int32_t**)malloc16(frame_parms->nb_antennas_tx*sizeof(int32_t*));
      for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
      dlsch->calib_dl_ch_estimates[aa] = (int32_t *)malloc16(OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t));
155

laurent's avatar
laurent committed
156
      }*/
157

Wang Tsu-Han's avatar
Wang Tsu-Han committed
158 159
    for (i=0; i<20; i++)
      dlsch->harq_ids[i/10][i%10] = Mdlharq;
160

161
    for (i=0; i<Mdlharq; i++) {
162
      dlsch->harq_processes[i] = (LTE_DL_eNB_HARQ_t *)malloc16(sizeof(LTE_DL_eNB_HARQ_t));
163
      LOG_T(PHY, "Required mem size %d (bw scaling %d), dlsch->harq_processes[%d] %p\n",
164 165
            MAX_DLSCH_PAYLOAD_BYTES/bw_scaling,bw_scaling, i,dlsch->harq_processes[i]);

166
      if (dlsch->harq_processes[i]) {
167 168
        bzero(dlsch->harq_processes[i],sizeof(LTE_DL_eNB_HARQ_t));
        //    dlsch->harq_processes[i]->first_tx=1;
169
        dlsch->harq_processes[i]->b = (unsigned char *)malloc16(MAX_DLSCH_PAYLOAD_BYTES/bw_scaling);
170 171 172 173

        if (dlsch->harq_processes[i]->b) {
          bzero(dlsch->harq_processes[i]->b,MAX_DLSCH_PAYLOAD_BYTES/bw_scaling);
        } else {
174
          printf("Can't get b\n");
175 176 177 178 179 180
          exit_flag=1;
        }

        if (abstraction_flag==0) {
          for (r=0; r<MAX_NUM_DLSCH_SEGMENTS/bw_scaling; r++) {
            // account for filler in first segment and CRCs for multiple segment case
181 182
            dlsch->harq_processes[i]->c[r] = (uint8_t *)malloc16(((r==0)?8:0) + 3+ 768);

183 184 185
            if (dlsch->harq_processes[i]->c[r]) {
              bzero(dlsch->harq_processes[i]->c[r],((r==0)?8:0) + 3+ 768);
            } else {
186
              printf("Can't get c\n");
187 188
              exit_flag=2;
            }
189
          }
190 191
        }
      } else {
192
        printf("Can't get harq_p %d\n",i);
193
        exit_flag=3;
194 195
      }
    }
196

197
    if (exit_flag==0) {
198 199
      for (i=0; i<Mdlharq; i++) {
        dlsch->harq_processes[i]->round=0;
200
      }
201

202 203 204
      return(dlsch);
    }
  }
205

206
  LOG_D(PHY,"new_eNB_dlsch exit flag %d, size of  %ld\n",
207
        exit_flag, sizeof(LTE_eNB_DLSCH_t));
208 209 210 211
  free_eNB_dlsch(dlsch);
  return(NULL);
}

212

213
void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch) {
214
  unsigned char Mdlharq;
laurent's avatar
laurent committed
215
  unsigned char i;
216

217 218 219
  if (dlsch) {
    Mdlharq = dlsch->Mdlharq;
    dlsch->rnti = 0;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
220
#ifdef PHY_TX_THREAD
221

Wang Tsu-Han's avatar
Wang Tsu-Han committed
222 223
    for (i=0; i<10; i++)
      dlsch->active[i] = 0;
224

Wang Tsu-Han's avatar
Wang Tsu-Han committed
225
#else
226
    dlsch->active = 0;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
227
#endif
228
    dlsch->harq_mask = 0;
229

Wang Tsu-Han's avatar
Wang Tsu-Han committed
230 231
    for (i=0; i<20; i++)
      dlsch->harq_ids[i/10][i%10] = Mdlharq;
232

233
    for (i=0; i<Mdlharq; i++) {
234
      if (dlsch->harq_processes[i]) {
235 236 237 238
        //  dlsch->harq_processes[i]->Ndi    = 0;
        dlsch->harq_processes[i]->status = 0;
        dlsch->harq_processes[i]->round  = 0;

239 240 241 242 243
      }
    }
  }
}

244 245 246
void *te_thread(void *param) {
  return(NULL);
}
247

248
int dlsch_encoding_all(PHY_VARS_eNB *eNB,
laurent's avatar
laurent committed
249
		       L1_rxtx_proc_t *proc,
250 251 252 253 254 255 256 257 258 259 260 261
                       unsigned char *a,
                       uint8_t num_pdcch_symbols,
                       LTE_eNB_DLSCH_t *dlsch,
                       int frame,
                       uint8_t subframe,
                       time_stats_t *rm_stats,
                       time_stats_t *te_stats,
                       time_stats_t *te_wait_stats,
                       time_stats_t *te_main_stats,
                       time_stats_t *te_wakeup_stats0,
                       time_stats_t *te_wakeup_stats1,
                       time_stats_t *i_stats) {
262 263 264 265 266
  uint8_t harq_pid = dlsch->harq_ids[frame%2][subframe];
  if(harq_pid >= dlsch->Mdlharq) {
    LOG_E(PHY,"dlsch_encoding_all illegal harq_pid %d\n", harq_pid);
    return(-1);
  }
laurent's avatar
laurent committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
  
  LOG_D(PHY,"B %d, harq_pid %d\n",
	dlsch->harq_processes[harq_pid]->B,
	dlsch->harq_ids[frame%2][subframe]);

  return dlsch_encoding(eNB,
			proc,
			a,
			num_pdcch_symbols,
			dlsch,
			frame,
			subframe,
			rm_stats,
			te_stats,
			i_stats);
282

laurent's avatar
laurent committed
283
}
284

laurent's avatar
laurent committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
static void TPencode(void * arg) {
  turboEncode_t * rdata=(turboEncode_t *) arg;
  unsigned char harq_pid = rdata->harq_pid;
  LTE_DL_eNB_HARQ_t *hadlsch=rdata->dlsch->harq_processes[harq_pid];
  
  if ( rdata-> round == 0) {
    uint8_t tmp[96+12+3+3*6144];
    memset(tmp,LTE_NULL, TURBO_SIMD_SOFTBITS);
    start_meas(rdata->te_stats);
    encoder(rdata->input,
	    rdata->Kr_bytes,
	    tmp+96,//&dlsch->harq_processes[harq_pid]->d[r][96],
	    rdata->filler);
    stop_meas(rdata->te_stats);
    start_meas(rdata->i_stats);
    hadlsch->RTC[rdata->r] =
      sub_block_interleaving_turbo(4+(rdata->Kr_bytes*8),
				   tmp+96,
				   hadlsch->w[rdata->r]);
    stop_meas(rdata->i_stats);
305
  }
laurent's avatar
laurent committed
306 307 308 309 310 311 312
  
  // Fill in the "e"-sequence from 36-212, V8.6 2009-03, p. 16-17 (for each "e") and concatenate the
  // outputs for each code segment, see Section 5.1.5 p.20
    start_meas(rdata->rm_stats);
  lte_rate_matching_turbo(hadlsch->RTC[rdata->r],
			  rdata->G,  //G
			  hadlsch->w[rdata->r],
laurent's avatar
laurent committed
313
			  hadlsch->eDL+rdata->r_offset,
laurent's avatar
laurent committed
314 315 316 317 318 319 320 321 322 323
			  hadlsch->C, // C
			  rdata->dlsch->Nsoft,                    // Nsoft,
			  rdata->dlsch->Mdlharq,
			  rdata->dlsch->Kmimo,
			  hadlsch->rvidx,
			  hadlsch->Qm,
			  hadlsch->Nl,
			  rdata->r,
			  hadlsch->nb_rb);
    stop_meas(rdata->rm_stats);
324 325
}

326
int dlsch_encoding(PHY_VARS_eNB *eNB,
laurent's avatar
laurent committed
327
                   L1_rxtx_proc_t *proc,
328
                   unsigned char *a,
329 330 331 332 333 334
                   uint8_t num_pdcch_symbols,
                   LTE_eNB_DLSCH_t *dlsch,
                   int frame,
                   uint8_t subframe,
                   time_stats_t *rm_stats,
                   time_stats_t *te_stats,
335
                   time_stats_t *i_stats) {
336
  LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
337
  unsigned char harq_pid = dlsch->harq_ids[frame%2][subframe];
338 339
  if((harq_pid < 0) || (harq_pid >= dlsch->Mdlharq)) {
    LOG_E(PHY,"dlsch_encoding illegal harq_pid %d %s:%d\n", harq_pid, __FILE__, __LINE__);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
340 341
    return(-1);
  }
342

laurent's avatar
laurent committed
343
  LTE_DL_eNB_HARQ_t *hadlsch=dlsch->harq_processes[harq_pid];
344 345 346
  uint8_t beamforming_mode=0;
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_IN);

laurent's avatar
laurent committed
347
  if(hadlsch->mimo_mode == TM7)
348
    beamforming_mode = 7;
laurent's avatar
laurent committed
349
  else if(hadlsch->mimo_mode == TM8)
350
    beamforming_mode = 8;
laurent's avatar
laurent committed
351
  else if(hadlsch->mimo_mode == TM9_10)
352 353
    beamforming_mode = 9;

laurent's avatar
laurent committed
354 355 356 357 358 359
  unsigned int G = get_G(frame_parms,hadlsch->nb_rb,
	    hadlsch->rb_alloc,
	    hadlsch->Qm, // mod order
	    hadlsch->Nl,
	    num_pdcch_symbols,
	    frame,subframe,beamforming_mode);
360

laurent's avatar
laurent committed
361 362 363
  proc->nbEncode=0;

  //  if (hadlsch->Ndi == 1) {  // this is a new packet
364
  if (hadlsch->round == 0) {  // this is a new packet
365
    // Add 24-bit crc (polynomial A) to payload
laurent's avatar
laurent committed
366 367
    unsigned int A=hadlsch->TBS; //6228;
    unsigned int crc = crc24a(a,
368
                 A)>>8;
369 370 371
    a[A>>3] = ((uint8_t *)&crc)[2];
    a[1+(A>>3)] = ((uint8_t *)&crc)[1];
    a[2+(A>>3)] = ((uint8_t *)&crc)[0];
372
    //    printf("CRC %x (A %d)\n",crc,A);
laurent's avatar
laurent committed
373 374 375 376 377 378 379 380 381 382 383 384 385
    hadlsch->B = A+24;
    //    hadlsch->b = a;
    memcpy(hadlsch->b,a,(A/8)+4);
    
    if (lte_segmentation(hadlsch->b,
                         hadlsch->c,
                         hadlsch->B,
                         &hadlsch->C,
                         &hadlsch->Cplus,
                         &hadlsch->Cminus,
                         &hadlsch->Kplus,
                         &hadlsch->Kminus,
                         &hadlsch->F)<0)
386 387
      return(-1);
  }
laurent's avatar
laurent committed
388 389 390 391
 
  for (int r=0, r_offset=0; r<hadlsch->C; r++) {
    
    union turboReqUnion id= {.s={dlsch->rnti,frame,subframe,r,0}};
laurent's avatar
laurent committed
392
    notifiedFIFO_elt_t *req=newNotifiedFIFO_elt(sizeof(turboEncode_t), id.p, proc->respEncode, TPencode);
laurent's avatar
laurent committed
393 394 395 396 397 398 399 400 401 402
    turboEncode_t * rdata=(turboEncode_t *) NotifiedFifoData(req);
    rdata->input=hadlsch->c[r];
    rdata->Kr_bytes= ( r<hadlsch->Cminus ? hadlsch->Kminus : hadlsch->Kplus) >>3;
    rdata->filler=(r==0) ? hadlsch->F : 0;
    rdata->r=r;
    rdata->harq_pid=harq_pid;
    rdata->dlsch=dlsch;
    rdata->rm_stats=rm_stats;
    rdata->te_stats=te_stats;
    rdata->i_stats=i_stats;
403
    rdata->round=hadlsch->round;
laurent's avatar
laurent committed
404 405 406
    rdata->r_offset=r_offset;
    rdata->G=G;
    
laurent's avatar
laurent committed
407 408
    if (  proc->threadPool->activated ) {
      pushTpool(proc->threadPool,req);
laurent's avatar
laurent committed
409 410 411
      proc->nbEncode++;
    } else {
      TPencode(rdata);
412
      delNotifiedFIFO_elt(req);
laurent's avatar
laurent committed
413 414 415 416 417 418 419 420 421 422 423
    }
    
    int Qm=hadlsch->Qm;
    int C=hadlsch->C;
    int Nl=hadlsch->Nl;
    int Gp = G/Nl/Qm;
    int GpmodC = Gp%C;
    if (r < (C-(GpmodC)))
      r_offset += Nl*Qm * (Gp/C);
    else
      r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C));
424
  }
425
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_OUT);
426 427
  return(0);
}
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532

int dlsch_encoding_fembms_pmch(PHY_VARS_eNB *eNB,
                   L1_rxtx_proc_t *proc,
                   unsigned char *a,
                   uint8_t num_pdcch_symbols,
                   LTE_eNB_DLSCH_t *dlsch,
                   int frame,
                   uint8_t subframe,
                   time_stats_t *rm_stats,
                   time_stats_t *te_stats,
                   time_stats_t *i_stats) {
  LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
  unsigned char harq_pid = dlsch->harq_ids[frame%2][subframe];
  if((harq_pid < 0) || (harq_pid >= dlsch->Mdlharq)) {
    LOG_E(PHY,"dlsch_encoding illegal harq_pid %d %s:%d\n", harq_pid, __FILE__, __LINE__);
    return(-1);
  }

  LTE_DL_eNB_HARQ_t *hadlsch=dlsch->harq_processes[harq_pid];
  uint8_t beamforming_mode=0;
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_IN);

  if(hadlsch->mimo_mode == TM7)
    beamforming_mode = 7;
  else if(hadlsch->mimo_mode == TM8)
    beamforming_mode = 8;
  else if(hadlsch->mimo_mode == TM9_10)
    beamforming_mode = 9;

  unsigned int G = get_G_khz_1dot25(frame_parms,hadlsch->nb_rb,
	    hadlsch->rb_alloc,
	    hadlsch->Qm, // mod order
	    hadlsch->Nl,
	    num_pdcch_symbols,
	    frame,subframe,beamforming_mode);

  proc->nbEncode=0;

  //  if (hadlsch->Ndi == 1) {  // this is a new packet
  if (hadlsch->round == 0) {  // this is a new packet
    // Add 24-bit crc (polynomial A) to payload
    unsigned int A=hadlsch->TBS; //6228;
    unsigned int crc = crc24a(a,
                 A)>>8;
    a[A>>3] = ((uint8_t *)&crc)[2];
    a[1+(A>>3)] = ((uint8_t *)&crc)[1];
    a[2+(A>>3)] = ((uint8_t *)&crc)[0];
    //    printf("CRC %x (A %d)\n",crc,A);
    hadlsch->B = A+24;
    //    hadlsch->b = a;
    memcpy(hadlsch->b,a,(A/8)+4);
    
    if (lte_segmentation(hadlsch->b,
                         hadlsch->c,
                         hadlsch->B,
                         &hadlsch->C,
                         &hadlsch->Cplus,
                         &hadlsch->Cminus,
                         &hadlsch->Kplus,
                         &hadlsch->Kminus,
                         &hadlsch->F)<0)
      return(-1);
  }
 
  for (int r=0, r_offset=0; r<hadlsch->C; r++) {
    
    union turboReqUnion id= {.s={dlsch->rnti,frame,subframe,r,0}};
    notifiedFIFO_elt_t *req=newNotifiedFIFO_elt(sizeof(turboEncode_t), id.p, proc->respEncode, TPencode);
    turboEncode_t * rdata=(turboEncode_t *) NotifiedFifoData(req);
    rdata->input=hadlsch->c[r];
    rdata->Kr_bytes= ( r<hadlsch->Cminus ? hadlsch->Kminus : hadlsch->Kplus) >>3;
    rdata->filler=(r==0) ? hadlsch->F : 0;
    rdata->r=r;
    rdata->harq_pid=harq_pid;
    rdata->dlsch=dlsch;
    rdata->rm_stats=rm_stats;
    rdata->te_stats=te_stats;
    rdata->i_stats=i_stats;
    rdata->round=hadlsch->round;
    rdata->r_offset=r_offset;
    rdata->G=G;
    
    if (  proc->threadPool->activated ) {
      pushTpool(proc->threadPool,req);
      proc->nbEncode++;
    } else {
      TPencode(rdata);
      delNotifiedFIFO_elt(req);
    }
    
    int Qm=hadlsch->Qm;
    int C=hadlsch->C;
    int Nl=hadlsch->Nl;
    int Gp = G/Nl/Qm;
    int GpmodC = Gp%C;
    if (r < (C-(GpmodC)))
      r_offset += Nl*Qm * (Gp/C);
    else
      r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C));
  }

  return(0);
}