www.pudn.com > wimax_ofdm_implementation_code.rar > frame_enc.c


/*****************************************************************************/
/*   FIle Name : frame_enc.c                                                 */
/*   Description : WiMax SC  downlink frame encoder                          */
/*   author : miffie                                                         */
/*   Date   : oct/13/05                                                      */
/*   Copyright (c) 2005 miffie   All rights reserved.                        */
/*****************************************************************************/
//This frame encoder can have only a single payload burst.
//DIUC=0 set for frame control 
//DIUC=1 will be selected randomly

struct complexset frame_enc( struct binaryset datain,
                             struct Downlink_Burst_Profile diuc1   ) { // 

int 	ii , jj , nn ;
struct  binaryset bset0, bset1 , btop ;
struct  complexset cset0, cset1 , ctop ;
short 	tmp1 ;
int     length ;
struct  Downlink_Burst_Profile diuc[8] ;
struct  DLFP_IE   dlfp[4] ;
char 	PHY_type = 0x01 ; //0:TDD 1:FDD
char 	Frame_duration = 0x01 ; //1: 0.5ms 2:1  3:2 4-0xf:reserved
char 	fec_code_type  ; 
short   pilot_shifter ;
char    subchannel_index ;
char    Nbpsc ;
short   Nsub, Ndbps, Nbps ;
//bit per subchannel per symbol before FEC
char    Nbpss[] = { 6, 12, 18, 24, 36, 48, 54 } ;
char    rs_cc_block[] =  { 12, 24, 36, 48, 72, 96, 108 } ;
char    btc_block[] =  { 23, 35, 58, 77, 96, 120 } ;
char    ctc_block[] =  { 6, 8, 9, 12, 18, 24, 27 } ;


char    CP ;
short   randomizer_seed ;
short 	BSID = 1 ;
short 	DIUC = 7 ;
short 	frame_number = 1 ;


static char QPSK = 1 ;
static char QAM16 = 2 ;
static char QAM64 = 3 ;

 //DCD 
 //DIUC=0 well-known

 PRINTF(" frame_enc  DIUC1 fec_code_type=%d size=0x%x\n",  diuc1.fec_code_type, datain.size ) ;

 /////////////////////////////////////////////////////////////////////////
 //CALCULATE xfr SIZE
 // This xfr size calculation is just for test purpose.
 // In real system, you may need to find another way to calculate 
 // frame size.
 /////////////////////////////////////////////////////////////////////////
 subchannel_index = 0x10 ;
 CP = 64 ;
 Nsub = (subchannel_index&0x1) ? 1 :
        (subchannel_index&0x2) ? 2 :
        (subchannel_index&0x4) ? 4 :
        (subchannel_index&0x8) ? 8 :
        (subchannel_index==0x10) ? 16 : 0 ;
 fec_code_type = diuc1.fec_code_type ;
 if (fec_code_type<=6) { //RS-CC
   Ndbps = Nsub * Nbpss[ fec_code_type ] ;
   length = (datain.size+1 + rs_cc_block[ fec_code_type ]-1) / 
             rs_cc_block[ fec_code_type ] ;
   length = (length * rs_cc_block[ fec_code_type ])  ;
 } else if (fec_code_type<=12) { //BTC
   Ndbps = btc_block[ fec_code_type-7 ] *8 ;
   length = (datain.size + btc_block[ fec_code_type-7 ] -1) / 
             btc_block[ fec_code_type-7 ] ;
   length = (length * btc_block[ fec_code_type-7 ])  ;
 } else if (fec_code_type<=19) { //CTC
   Ndbps = ctc_block[ fec_code_type-13 ] *Nsub ;
   length = (datain.size + ctc_block[ fec_code_type-13 ] -1) / 
             ctc_block[ fec_code_type-13 ] ;
   length = (length * ctc_block[ fec_code_type-13 ])  ;
 }
 //DL_FP_ELEMENT
 //DL_FP_ELEMENT
 //HCS example: pp452
 //dlfp[0].DIUC = 1 ; 
 //dlfp[0].Preamble_present = 0 ;
 //dlfp[0].Length = 204 ; 
 //dlfp[1].DIUC = 1 ;
 //dlfp[1].Preamble_present = 1 ;
 //dlfp[1].Length = 50 ; 
 //dlfp[2].DIUC = 0 ; 
 //dlfp[2].Length = 0 ; 
 //dlfp[3].DIUC = 0 ; 
 //dlfp[3].Length = 0 ; 

 dlfp[0].DIUC = 1 ; //diuc1.fec_code_type ; //diuc1
 dlfp[0].Preamble_present = 0 ;
 dlfp[0].Length =  ( (length*8) + Ndbps-1) / Ndbps ;
 dlfp[1].DIUC = 0 ;
 dlfp[1].Length = 0 ;
 dlfp[2].DIUC = 0 ; 
 dlfp[2].Length = 0 ; 
 dlfp[3].DIUC = 0 ; 
 dlfp[3].Length = 0 ; 
 
 
 /////////////////////////////////////////////////////////////////////////
 //ENCODING
 /////////////////////////////////////////////////////////////////////////
  //1.preamble
    pilot_shifter = 0x7ff ;
    ctop = preamble( CP ) ;
    //print_complexset( ctop ) ;

  //2.frame control
    fec_code_type = 0 ;
    Nbpsc = 1 ;
    Nbps = Nsub * Nbpsc*12 ;
    bset0 = frameprefix( &dlfp[0] , BSID, frame_number ) ;
    print_binaryset( bset0 ) ;
    //FEC
    randomizer_seed = 0x00a9 ;
    bset0 = fecenc( bset0, fec_code_type , &randomizer_seed ) ;
    print_binaryset( bset0 ) ;
    for (nn=0;nn0) { //subsequent bursts
      DIUC = dlfp[ii].DIUC ;
      randomizer_seed= (BSID<<11) + (0x3<<9) + (DIUC<<5) + (0x1<<4) + frame_number ;
      randomizer_seed = swap_short( randomizer_seed ) >> 1 ;
    } //subsequent bursts
    if (fec_code_type<=6) {
      bset0 = pad_binaryset(length -  datain.size -1 ) ;
      bset0.format = 1 ;
      for (nn=0;nn