This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C6670: TMS320C6670

Part Number: TMS320C6670

 

/*
 *  ======== mutex.c ========
 *  This example shows the use of two tasks and one semaphore to perform
 *  mutual exclusive data access.
 */
#include<stdio.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include"../INCLUDE/generate_pbch.h"
#include"../INCLUDE/phy_var.h"
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>


#include"../INCLUDE/generate_pbch.h"
#include<string.h>
#include<stdint.h>

extern ccodelte_encode (int32_t numbits,
        uint8_t add_crc,
        uint8_t *inPtr,
        uint8_t *outPtr,
        uint16_t rnti);
extern uint32_t lte_rate_matching_cc(uint32_t RCC,
        uint16_t E,
        uint8_t *w,
        uint8_t *e);
#define bzero(s,n) (memset((s),0,(n)))
#define LTE_NULL 2
extern uint32_t sub_block_interleaving_cc(uint32_t D, uint8_t *d,uint8_t *w);
extern int write_output(const char *fname,const char *vname,void *data,int length,int dec,char format);
extern void pbch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
        uint8_t *pbch_e,
        uint32_t length);
extern int allocate_pbch_REs_in_RB(LTE_DL_FRAME_PARMS *frame_parms,
        int32_t **txdataF,
        uint32_t *jj,
        uint16_t re_offset,
        uint32_t symbol_offset,
        uint8_t *x0,
        uint8_t pilots,
        int16_t amp,
        uint32_t *re_allocated);






#include <xdc/cfg/global.h>

#define AMP 128

extern unsigned int             poly24a;
extern unsigned int             poly8;
extern unsigned int crcbit (unsigned char * inputptr, int octetlen, unsigned int poly);
extern unsigned int crc24a (unsigned char * inptr, int bitlen);
extern unsigned int crc8 (unsigned char * inptr, int bitlen);
extern void crcTableInit ();
extern int generate_pbch(LTE_eNB_PBCH *eNB_pbch,
        int32_t **txdataF,
        int amp,
        LTE_DL_FRAME_PARMS *frame_parms,
        uint8_t *pbch_pdu,
        uint8_t frame_mod4);
extern int generate_pbch(LTE_eNB_PBCH *eNB_pbch,
        int32_t **txdataF,
        int amp,
        LTE_DL_FRAME_PARMS *frame_parms,
        uint8_t *pbch_pdu,
        uint8_t frame_mod4);


      unsigned char pbch_pdu[6];
PHY_VARS_eNB *PHY_vars_eNB,*PHY_vars_eNB1,*PHY_vars_eNB2;

Void task1(UArg arg0, UArg arg1);



Task_Handle tsk1;

Void main()
{ 
    Task_Params taskParams;


    /* Create two tasks that share a resource*/
    Task_Params_init(&taskParams);
    taskParams.priority = 1;
    tsk1 = Task_create (task1, &taskParams, NULL);
    
    printf("INSIDE MAIN");

    BIOS_start();
}

/*
 *  ======== task1 ========
 */
Void task1(UArg arg0, UArg arg1)
{

	int a=10;
	int b=10;
	unsigned char test[] = "hey";

	printf("%d\n",a+b);

printf("INSIDE TASK\n");


 crcTableInit();

 printf("%x\n", crcbit(test, sizeof(test) - 1, poly8));
 printf("%x\n", crc8(test, (sizeof(test) - 1)*8));

 printf("%x\n", crcbit(test, sizeof(test) - 1, poly24a));
 printf("%x\n", crc24a(test, (sizeof(test) - 1)*8));

 generate_pbch(&PHY_vars_eNB1->lte_eNB_pbch,
                    PHY_vars_eNB1->lte_eNB_common_vars.txdataF[0],
                    AMP,
                    &PHY_vars_eNB1->lte_frame_parms,
                    pbch_pdu,
                    0);

}

 int generate_pbch(LTE_eNB_PBCH *eNB_pbch,
                   int32_t **txdataF,
                   int amp,
                   LTE_DL_FRAME_PARMS *frame_parms,
                   uint8_t *pbch_pdu,
                   uint8_t frame_mod4)
 {

   int i, l;

   uint32_t  pbch_D,pbch_E;//,pbch_coded_bytes;
   uint8_t pbch_a[PBCH_A>>3];
   uint8_t RCC;

   uint32_t nsymb = (frame_parms->Ncp==NORMAL) ? 14:12;
   uint32_t pilots;
 #ifdef INTERFERENCE_MITIGATION
   uint32_t pilots_2;
 #endif
   uint32_t second_pilot = (frame_parms->Ncp==NORMAL) ? 4 : 3;
   uint32_t jj=0;
   uint32_t re_allocated=0;
   uint32_t rb, re_offset, symbol_offset;
   uint16_t amask=0;

   pbch_D    = 16+PBCH_A;

   pbch_E  = (frame_parms->Ncp==NORMAL) ? 1920 : 1728; //RE/RB * #RB * bits/RB (QPSK)
   //  pbch_E_bytes = pbch_coded_bits>>3;

   if (frame_mod4==0) {
     bzero(pbch_a,PBCH_A>>3);
     bzero(eNB_pbch->pbch_e,pbch_E);
     memset(eNB_pbch->pbch_d,LTE_NULL,96);
     // Encode data

     // CRC attachment
    //  crc = (uint16_t) (crc16(pbch_pdu, pbch_crc_bits-16) >> 16);

     /*
     // scramble crc with PBCH CRC mask (Table 5.3.1.1-1 of 3GPP 36.212-860)
     switch (frame_parms->nb_antennas_tx_eNB) {
     case 1:
     crc = crc ^ (uint16_t) 0;
     break;
     case 2:
     crc = crc ^ (uint16_t) 0xFFFF;
     break;
     case 4:
     crc = crc ^ (uint16_t) 0xAAAA;
     break;
     default:
     msg("[PBCH] Unknown number of TX antennas!\n");
     break;
     }
     */

     // Fix byte endian of PBCH (bit 23 goes in first)
     for (i=0; i<(PBCH_A>>3); i++)
       pbch_a[(PBCH_A>>3)-i-1] = pbch_pdu[i];

     //  pbch_data[i] = ((char*) &crc)[0];
     //  pbch_data[i+1] = ((char*) &crc)[1];
 #ifdef DEBUG_PBCH

     for (i=0; i<(PBCH_A>>3); i++)
       msg("[PBCH] pbch_data[%d] = %x\n",i,pbch_a[i]);

 #endif

     if (frame_parms->mode1_flag == 1)
       amask = 0x0000;
     else {
       switch (frame_parms->nb_antennas_tx_eNB) {
       case 1:
         amask = 0x0000;
         break;

       case 2:
         amask = 0xffff;
         break;

       case 4:
         amask = 0x5555;
       }
     }

     ccodelte_encode(PBCH_A,2,pbch_a,eNB_pbch->pbch_d+96,amask);


 #ifdef DEBUG_PBCH_ENCODING

     for (i=0; i<16+PBCH_A; i++)
       msg("%d : (%d,%d,%d)\n",i,*(eNB_pbch->pbch_d+96+(3*i)),*(eNB_pbch->pbch_d+97+(3*i)),*(eNB_pbch->pbch_d+98+(3*i)));

 #endif //DEBUG_PBCH_ENCODING

     // Bit collection
     /*
       j2=0;
       for (j=0;j<pbch_crc_bits*3+12;j++) {
       if ((pbch_coded_data[j]&0x80) > 0) { // bit is to be transmitted
       pbch_coded_data2[j2++] = pbch_coded_data[j]&1;
       //Bit is repeated
       if ((pbch_coded_data[j]&0x40)>0)
       pbch_coded_data2[j2++] = pbch_coded_data[j]&1;
       }
       }

       #ifdef DEBUG_PBCH
       msg("[PBCH] rate matched bits=%d, pbch_coded_bits=%d, pbch_crc_bits=%d\n",j2,pbch_coded_bits,pbch_crc_bits);
       #endif

       #ifdef DEBUG_PBCH
       #ifdef USER_MODE
       write_output("pbch_encoded_output2.m","pbch_encoded_out2",
       pbch_coded_data2,
       pbch_coded_bits,
       1,
       4);
       #endif //USER_MODE
       #endif //DEBUG_PBCH
     */
 #ifdef DEBUG_PBCH_ENCODING
     msg("Doing PBCH interleaving for %d coded bits, e %p\n",pbch_D,eNB_pbch->pbch_e);
 #endif
     RCC = sub_block_interleaving_cc(pbch_D,eNB_pbch->pbch_d+96,eNB_pbch->pbch_w);

     lte_rate_matching_cc(RCC,pbch_E,eNB_pbch->pbch_w,eNB_pbch->pbch_e);

 #ifdef DEBUG_PBCH_ENCODING
     msg("PBCH_e:\n");

     for (i=0; i<pbch_E; i++)
       msg("%d %d\n",i,*(eNB_pbch->pbch_e+i));

     msg("\n");
 #endif



 #ifdef DEBUG_PBCH
 #ifdef USER_MODE

     if (frame_mod4==0) {
       write_output("pbch_e.m","pbch_e",
                    eNB_pbch->pbch_e,
                    pbch_E,
                    1,
                    4);

       for (i=0; i<16; i++)
         printf("e[%d] %d\n",i,eNB_pbch->pbch_e[i]);
     }

 #endif //USER_MODE
 #endif //DEBUG_PBCH
     // scrambling

     pbch_scrambling(frame_parms,
                     eNB_pbch->pbch_e,
                     pbch_E);
 #ifdef DEBUG_PBCH
 #ifdef USER_MODE

     if (frame_mod4==0) {
       write_output("pbch_e_s.m","pbch_e_s",
                    eNB_pbch->pbch_e,
                    pbch_E,
                    1,
                    4);

       for (i=0; i<16; i++)
         printf("e_s[%d] %d\n",i,eNB_pbch->pbch_e[i]);
     }

 #endif //USER_MODE
 #endif //DEBUG_PBCH
   } // frame_mod4==0

   // modulation and mapping (slot 1, symbols 0..3)
   for (l=(nsymb>>1); l<(nsymb>>1)+4; l++) {

     pilots=0;
 #ifdef INTERFERENCE_MITIGATION
     pilots_2 = 0;
 #endif

     if ((l==0) || (l==(nsymb>>1))) {
       pilots=1;
 #ifdef INTERFERENCE_MITIGATION
       pilots_2=1;
 #endif
     }

     if ((l==1) || (l==(nsymb>>1)+1)) {
       pilots=1;
     }

     if ((l==second_pilot)||(l==(second_pilot+(nsymb>>1)))) {
       pilots=1;
     }

 #ifdef DEBUG_PBCH
     msg("[PBCH] l=%d, pilots=%d\n",l,pilots);
 #endif


     re_offset = frame_parms->ofdm_symbol_size-3*12;
     symbol_offset = frame_parms->ofdm_symbol_size*l;

     for (rb=0; rb<6; rb++) {

 #ifdef DEBUG_PBCH
       msg("RB %d, jj %d, re_offset %d, symbol_offset %d, pilots %d, nushift %d\n",rb,jj,re_offset, symbol_offset, pilots,frame_parms->nushift);
 #endif
       allocate_pbch_REs_in_RB(frame_parms,
                               txdataF,
                               &jj,
                               re_offset,
                               symbol_offset,
                               &eNB_pbch->pbch_e[frame_mod4*(pbch_E>>2)],
                               pilots,
 #ifdef INTERFERENCE_MITIGATION
                               (pilots_2==1)?(amp/3):amp,
 #else
                               amp,
 #endif
                               &re_allocated);

       re_offset+=12; // go to next RB

       // check if we crossed the symbol boundary and skip DC

       if (re_offset >= frame_parms->ofdm_symbol_size)
         re_offset=1;
     }

     //    }
   }

 #ifdef DEBUG_PBCH
   printf("[PBCH] txdataF=\n");

   for (i=0; i<frame_parms->ofdm_symbol_size; i++) {
     printf("%d=>(%d,%d)",i,((short*)&txdataF[0][frame_parms->ofdm_symbol_size*(nsymb>>1)+i])[0],
            ((short*)&txdataF[0][frame_parms->ofdm_symbol_size*(nsymb>>1)+i])[1]);

     if (frame_parms->mode1_flag==0) {
       printf("(%d,%d)\n",((short*)&txdataF[1][frame_parms->ofdm_symbol_size*(nsymb>>1)+i])[0],
              ((short*)&txdataF[1][frame_parms->ofdm_symbol_size*(nsymb>>1)+i])[1]);
     } else {
       printf("\n");
     }
   }

 #endif


   return(0);
 }











/*
 * scrambling.c
 *
 *  Created on: May 10, 2017
 *      Author: asmaitha
 */

#include<stdint.h>
#include"../INCLUDE/generate_pbch.h"

unsigned int lte_gold_generic(unsigned int *x1, unsigned int *x2, unsigned char reset)
{
  int n;

  if (reset) {
    *x1 = 1+ (1<<31);
    *x2=*x2 ^ ((*x2 ^ (*x2>>1) ^ (*x2>>2) ^ (*x2>>3))<<31);

    // skip first 50 double words (1600 bits)
    //      printf("n=0 : x1 %x, x2 %x\n",x1,x2);
    for (n=1; n<50; n++) {
      *x1 = (*x1>>1) ^ (*x1>>4);
      *x1 = *x1 ^ (*x1<<31) ^ (*x1<<28);
      *x2 = (*x2>>1) ^ (*x2>>2) ^ (*x2>>3) ^ (*x2>>4);
      *x2 = *x2 ^ (*x2<<31) ^ (*x2<<30) ^ (*x2<<29) ^ (*x2<<28);
    }
  }

  *x1 = (*x1>>1) ^ (*x1>>4);
  *x1 = *x1 ^ (*x1<<31) ^ (*x1<<28);
  *x2 = (*x2>>1) ^ (*x2>>2) ^ (*x2>>3) ^ (*x2>>4);
  *x2 = *x2 ^ (*x2<<31) ^ (*x2<<30) ^ (*x2<<29) ^ (*x2<<28);
  return(*x1^*x2);
  //  printf("n=%d : c %x\n",n,x1^x2);

}

void pbch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
                     uint8_t *pbch_e,
                     uint32_t length)
{
  int i;
  uint8_t reset;
  uint32_t x1, x2, s=0;

  reset = 1;
  // x1 is set in lte_gold_generic
  x2 = frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.6.1
  //  msg("pbch_scrambling: Nid_cell = %d\n",x2);

  for (i=0; i<length; i++) {
    if ((i&0x1f)==0) {
      s = lte_gold_generic(&x1, &x2, reset);
      //      printf("lte_gold[%d]=%x\n",i,s);
      reset = 0;
    }

    pbch_e[i] = (pbch_e[i]&1) ^ ((s>>(i&0x1f))&1);

  }
}
/*
 * rate_matching.c
 *
 *  Created on: May 10, 2017
 *      Author: asmaitha
 */

#include<stdint.h>

#define LTE_NULL 2
uint32_t lte_rate_matching_cc(uint32_t RCC,
                              uint16_t E,
                              uint8_t *w,
                              uint8_t *e)
{


  uint32_t ind=0,k;

  uint16_t Kw = 3*(RCC<<5);

#ifdef RM_DEBUG_CC
  uint32_t nulled=0;

  printf("lte_rate_matching_cc: Kw %d, E %d\n",Kw, E);
#endif

  for (k=0; k<E; k++) {


    while(w[ind] == LTE_NULL) {

#ifdef RM_DEBUG_CC
      nulled++;
      printf("RM_TX_CC : ind %d, NULL\n",ind);
#endif
      ind++;

      if (ind==Kw)
        ind=0;
    }


    e[k] = w[ind];
#ifdef RM_DEBUG_CC
    //    printf("k %d ind %d, w %c(%d)\n",k,ind,w[ind],w[ind]);
    printf("RM_TX_CC %d Ind: %d (%d)\n",k,ind,e[k]);
#endif
    ind++;

    if (ind==Kw)
      ind=0;
  }

#ifdef RM_DEBUG_CC
  printf("nulled %d\n",nulled);
#endif
  return(E);
}
/*
 * pbch_res_allocate.c
 *
 *  Created on: May 10, 2017
 *      Author: asmaitha
 */

#include<stdint.h>
#include"../INCLUDE/generate_pbch.h"
#include"../INCLUDE/phy_var.h"
#define ONE_OVER_SQRT2_Q15 23170
uint8_t is_not_pilot(uint8_t pilots, uint8_t re, uint8_t nushift, uint8_t use2ndpilots);
int allocate_pbch_REs_in_RB(LTE_DL_FRAME_PARMS *frame_parms,
                            int32_t **txdataF,
                            uint32_t *jj,
                            uint16_t re_offset,
                            uint32_t symbol_offset,
                            uint8_t *x0,
                            uint8_t pilots,
                            int16_t amp,
                            uint32_t *re_allocated)
{

  MIMO_mode_t mimo_mode   = (frame_parms->mode1_flag==1)?SISO:ALAMOUTI;


  uint32_t tti_offset,aa;
  uint8_t re;
  int16_t gain_lin_QPSK;
  int16_t re_off=re_offset;

  uint8_t first_re,last_re;
  int32_t tmp_sample1,tmp_sample2;

  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);

  first_re=0;
  last_re=12;

  for (re=first_re; re<last_re; re++) {

    tti_offset = symbol_offset + re_off + re;

    // check that RE is not from Cell-specific RS

    if (is_not_pilot(pilots,re,frame_parms->nushift,0)==1) {
      //      printf("re %d (jj %d)\n",re,*jj);
      if (mimo_mode == SISO) {  //SISO mapping
        *re_allocated = *re_allocated + 1;

        //    printf("%d(%d) : %d,%d => ",tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
        for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
          ((int16_t*)&txdataF[aa][tti_offset])[0] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
        }

        *jj = *jj + 1;

        for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
          ((int16_t*)&txdataF[aa][tti_offset])[1] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
        }

        *jj = *jj + 1;
      } else if (mimo_mode == ALAMOUTI) {
        *re_allocated = *re_allocated + 1;

        ((int16_t*)&tmp_sample1)[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
        *jj=*jj+1;
        ((int16_t*)&tmp_sample1)[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
        *jj=*jj+1;

        // second antenna position n -> -x1*

        ((int16_t*)&tmp_sample2)[0] = (x0[*jj]==1) ? (gain_lin_QPSK) : -gain_lin_QPSK;
        *jj=*jj+1;
        ((int16_t*)&tmp_sample2)[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
        *jj=*jj+1;

        // normalization for 2 tx antennas
        ((int16_t*)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
        ((int16_t*)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*ONE_OVER_SQRT2_Q15)>>15);
        ((int16_t*)&txdataF[1][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample2)[0]*ONE_OVER_SQRT2_Q15)>>15);
        ((int16_t*)&txdataF[1][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample2)[1]*ONE_OVER_SQRT2_Q15)>>15);

        // fill in the rest of the ALAMOUTI precoding
        if (is_not_pilot(pilots,re + 1,frame_parms->nushift,0)==1) {
          ((int16_t *)&txdataF[0][tti_offset+1])[0] += -((int16_t *)&txdataF[1][tti_offset])[0]; //x1
          ((int16_t *)&txdataF[0][tti_offset+1])[1] += ((int16_t *)&txdataF[1][tti_offset])[1];
          ((int16_t *)&txdataF[1][tti_offset+1])[0] += ((int16_t *)&txdataF[0][tti_offset])[0];  //x0*
          ((int16_t *)&txdataF[1][tti_offset+1])[1] += -((int16_t *)&txdataF[0][tti_offset])[1];
        } else {
          ((int16_t *)&txdataF[0][tti_offset+2])[0] += -((int16_t *)&txdataF[1][tti_offset])[0]; //x1
          ((int16_t *)&txdataF[0][tti_offset+2])[1] += ((int16_t *)&txdataF[1][tti_offset])[1];
          ((int16_t *)&txdataF[1][tti_offset+2])[0] += ((int16_t *)&txdataF[0][tti_offset])[0];  //x0*
          ((int16_t *)&txdataF[1][tti_offset+2])[1] += -((int16_t *)&txdataF[0][tti_offset])[1];
        }

        re++;  // adjacent carriers are taken care of by precoding
        *re_allocated = *re_allocated + 1;

        if (is_not_pilot(pilots,re,frame_parms->nushift,0)==0) { // skip pilots
          re++;
          *re_allocated = *re_allocated + 1;
        }
      }
    }
  }

  return(0);
}


uint8_t is_not_pilot(uint8_t pilots, uint8_t re, uint8_t nushift, uint8_t use2ndpilots)
{

  uint8_t offset = (pilots==2)?3:0;
  int nushiftmod3 = nushift%3;

  if (pilots==0)
    return(1);

  if (use2ndpilots==1) {  // This is for SISO (mode 1)
    if ((re!=nushift+offset) && (re!=((nushift+6+offset)%12)))
      return(1);
  } else { // 2 antenna pilots
    if ((re!=nushiftmod3) && (re!=nushiftmod3+6) && (re!=nushiftmod3+3) && (re!=nushiftmod3+9))
      return(1);
  }

  return(0);
}
/*
 * interleaving.c
 *
 *  Created on: May 10, 2017
 *      Author: asmaitha
 */
#include<stdint.h>

//static uint32_t bitrev[32]    = {0,16,8,24,4,20,12,28,2,18,10,26,6,22,14,30,1,17,9,25,5,21,13,29,3,19,11,27,7,23,15,31};
//static uint32_t bitrev_x3[32] = {0,48,24,72,12,60,36,84,6,54,30,78,18,66,42,90,3,51,27,75,15,63,39,87,9,57,33,81,21,69,45,93};
static uint32_t bitrev_cc[32] = {1,17,9,25,5,21,13,29,3,19,11,27,7,23,15,31,0,16,8,24,4,20,12,28,2,18,10,26,6,22,14,30};


uint32_t sub_block_interleaving_cc(uint32_t D, uint8_t *d,uint8_t *w)
{

  uint32_t RCC = (D>>5), ND, ND3;
  uint32_t row,col,Kpi,index;
  uint32_t index3,k;
#ifdef RM_DEBUG_CC
  uint32_t nulled=0;
#endif

  if ((D&0x1f) > 0)
    RCC++;

  Kpi = (RCC<<5);
  //  Kpi3 = Kpi*3;
  ND = Kpi - D;
#ifdef RM_DEBUG_CC
  printf("sub_block_interleaving_cc : D = %d (%d), d %p, w %p\n",D,D*3,d,w);
  printf("RCC = %d, Kpi=%d, ND=%d\n",RCC,Kpi,ND);
#endif
  ND3 = ND*3;

  k=0;

  for (col=0; col<32; col++) {
#ifdef RM_DEBUG_CC
    printf("Col %d\n",col);
#endif
    index = bitrev_cc[col];
    index3 = 3*index;

    for (row=0; row<RCC; row++) {
      w[k]          =  d[(int32_t)index3-(int32_t)ND3];
      w[Kpi+k]     =   d[(int32_t)index3-(int32_t)ND3+1];
      w[(Kpi<<1)+k] =  d[(int32_t)index3-(int32_t)ND3+2];
#ifdef RM_DEBUG_CC
      printf("row %d, index %d k %d w(%d,%d,%d)\n",row,index,k,w[k],w[Kpi+k],w[(Kpi<<1)+k]);

      if (w[k]== LTE_NULL)
        nulled++;

      if (w[Kpi+k] ==LTE_NULL)
        nulled++;

      if (w[(Kpi<<1)+k] ==LTE_NULL)
        nulled++;

#endif
      index3+=96;
      index+=32;
      k++;
    }
  }

#ifdef RM_DEBUG_CC
  printf("RM_TX: Nulled %d\n",nulled);
#endif
  return(RCC);
}
/*
 * generate_pbch.c
 *
 *  Created on: May 10, 2017
 *      Author: asmaitha
 */
#include<stdio.h>

/*
 * file_output.c
 *
 *  Created on: May 10, 2017
 *      Author: asmaitha
 */
/*******************************************************************************
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr

  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE

 *******************************************************************************/
//#ifdef USER_MODE

#include <string.h>
#include <stdio.h>
#include <stdlib.h>


int write_output(const char *fname,const char *vname,void *data,int length,int dec,char format)
{

  FILE *fp=NULL;
  int i;


  printf("Writing %d elements of type %d to %s\n",length,format,fname);


  if (format == 10 || format ==11 || format == 12 ) {
    fp = fopen(fname,"a+");
  } else if (format != 10 && format !=11  && format != 12 ) {
    fp = fopen(fname,"w+");
  }



  if (fp== NULL) {
    printf("[OPENAIR][FILE OUTPUT] Cannot open file %s\n",fname);
    return(-1);
  }

  if (format != 10 && format !=11  && format != 12 )
    fprintf(fp,"%s = [",vname);


  switch (format) {
  case 0:   // real 16-bit

    for (i=0; i<length; i+=dec) {
      fprintf(fp,"%d\n",((short *)data)[i]);
    }

    break;

  case 1:  // complex 16-bit


    for (i=0; i<length<<1; i+=(2*dec)) {
      fprintf(fp,"%d + j*(%d)\n",((short *)data)[i],((short *)data)[i+1]);

    }


    break;

  case 2:  // real 32-bit
    for (i=0; i<length; i+=dec) {
      fprintf(fp,"%d\n",((int *)data)[i]);
    }

    break;

  case 3: // complex 32-bit
    for (i=0; i<length<<1; i+=(2*dec)) {
      fprintf(fp,"%d + j*(%d)\n",((int *)data)[i],((int *)data)[i+1]);
    }

    break;

  case 4: // real 8-bit
    for (i=0; i<length; i+=dec) {
      fprintf(fp,"%d\n",((char *)data)[i]);
    }

    break;

  case 5: // complex 8-bit
    for (i=0; i<length<<1; i+=(2*dec)) {
      fprintf(fp,"%d + j*(%d)\n",((char *)data)[i],((char *)data)[i+1]);
    }

    break;

  case 6:  // real 64-bit
    for (i=0; i<length; i+=dec) {
      fprintf(fp,"%lld\n",((long long*)data)[i]);
    }

    break;

  case 7: // real double
    for (i=0; i<length; i+=dec) {
      fprintf(fp,"%g\n",((double *)data)[i]);
    }

    break;

  case 8: // complex double
    for (i=0; i<length<<1; i+=2*dec) {
      fprintf(fp,"%g + j*(%g)\n",((double *)data)[i], ((double *)data)[i+1]);
    }

    break;

  case 9: // real unsigned 8-bit
    for (i=0; i<length; i+=dec) {
      fprintf(fp,"%d\n",((unsigned char *)data)[i]);
    }

    break;


  case 10 : // case eren 16 bit complex :

    for (i=0; i<length<<1; i+=(2*dec)) {

      if((i < 2*(length-1)) && (i > 0))
        fprintf(fp,"%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]);
      else if (i == 2*(length-1))
        fprintf(fp,"%d + j*(%d);",((short *)data)[i],((short *)data)[i+1]);
      else if (i == 0)
        fprintf(fp,"\n%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]);



    }

    break;

  case 11 : //case eren 16 bit real for channel magnitudes:
    for (i=0; i<length; i+=dec) {

      if((i <(length-1))&& (i > 0))
        fprintf(fp,"%d,",((short *)data)[i]);
      else if (i == (length-1))
        fprintf(fp,"%d;",((short *)data)[i]);
      else if (i == 0)
        fprintf(fp,"\n%d,",((short *)data)[i]);
    }

    printf("\n erennnnnnnnnnnnnnn: length :%d",length);
    break;

  case 12 : // case eren for log2_maxh real unsigned 8 bit
    fprintf(fp,"%d \n",((unsigned char *)&data)[0]);
    break;


  }

  if (format != 10 && format !=11 && format !=12 ) {
    fprintf(fp,"];\n");
    fclose(fp);
    return(0);
  } else if (format == 10 || format ==11 || format == 12 ) {
    fclose(fp);
    return(0);
  }

  return 0;
}

//#endif // USER_MODE




/*
 * crc_byte.c
 *
 *  Created on: May 10, 2017
 *      Author: asmaitha
 */
#include"../INCLUDE/poly.h"

unsigned int
crcbit (unsigned char * inputptr, int octetlen, unsigned int poly)
{
  unsigned int             i, crc = 0, c;

  while (octetlen-- > 0) {
    c = (*inputptr++) << 24;

    for (i = 8; i != 0; i--) {
      if ((1 << 31) & (c ^ crc))
        crc = (crc << 1) ^ poly;
      else
        crc <<= 1;

      c <<= 1;
    }
  }

  return crc;
}

/*********************************************************

crc table initialization

*********************************************************/
static unsigned int      crc24aTable[256];
static unsigned int      crc24bTable[256];
static unsigned short      crc16Table[256];
static unsigned short      crc12Table[256];
static unsigned char       crc8Table[256];

void crcTableInit ()
{
  unsigned char              c = 0;

  do {
    crc24aTable[c] = crcbit (&c, 1, poly24a);
    crc24bTable[c] = crcbit (&c, 1, poly24b);
    crc16Table[c] = (unsigned short) (crcbit (&c, 1, poly16) >> 16);
    crc12Table[c] = (unsigned short) (crcbit (&c, 1, poly12) >> 16);
    crc8Table[c] = (unsigned char) (crcbit (&c, 1, poly8) >> 24);
  } while (++c);
}
/*********************************************************

Byte by byte implementations,
assuming initial byte is 0 padded (in MSB) if necessary

*********************************************************/
unsigned int
crc24a (unsigned char * inptr, int bitlen)
{

  int             octetlen, resbit;
  unsigned int             crc = 0;
  octetlen = bitlen / 8;        /* Change in octets */
  resbit = (bitlen % 8);

  while (octetlen-- > 0) {
    //    printf("in %x => crc %x\n",crc,*inptr);
    crc = (crc << 8) ^ crc24aTable[(*inptr++) ^ (crc >> 24)];
  }

  if (resbit > 0)
    crc = (crc << resbit) ^ crc24aTable[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))];

  return crc;
}

unsigned int crc24b (unsigned char * inptr, int bitlen)
{

  int             octetlen, resbit;
  unsigned int             crc = 0;
  octetlen = bitlen / 8;        /* Change in octets */
  resbit = (bitlen % 8);

  while (octetlen-- > 0) {
    crc = (crc << 8) ^ crc24bTable[(*inptr++) ^ (crc >> 24)];
  }

  if (resbit > 0)
    crc = (crc << resbit) ^ crc24bTable[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))];

  return crc;
}

unsigned int
crc16 (unsigned char * inptr, int bitlen)
{
  int             octetlen, resbit;
  unsigned int             crc = 0;
  octetlen = bitlen / 8;        /* Change in octets */
  resbit = (bitlen % 8);

  while (octetlen-- > 0) {

    crc = (crc << 8) ^ (crc16Table[(*inptr++) ^ (crc >> 24)] << 16);
  }

  if (resbit > 0)
    crc = (crc << resbit) ^ (crc16Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 16);

  return crc;
}

unsigned int
crc12 (unsigned char * inptr, int bitlen)
{
  int             octetlen, resbit;
  unsigned int             crc = 0;
  octetlen = bitlen / 8;        /* Change in octets */
  resbit = (bitlen % 8);

  while (octetlen-- > 0) {
    crc = (crc << 8) ^ (crc12Table[(*inptr++) ^ (crc >> 24)] << 16);
  }

  if (resbit > 0)
    crc = (crc << resbit) ^ (crc12Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 16);

  return crc;
}

unsigned int
crc8 (unsigned char * inptr, int bitlen)
{
  int             octetlen, resbit;
  unsigned int             crc = 0;
  octetlen = bitlen / 8;        /* Change in octets */
  resbit = (bitlen % 8);

  while (octetlen-- > 0) {
    crc = crc8Table[(*inptr++) ^ (crc >> 24)] << 24;
  }

  if (resbit > 0)
    crc = (crc << resbit) ^ (crc8Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 24);

  return crc;
}

/*
 * ccode_encode.c
 *
 *  Created on: May 10, 2017
 *      Author: asmaitha
 */


#include<stdio.h>
#include<stdint.h>

unsigned short glte[] = { 0133, 0171, 0165 }; // {A,B}
unsigned short glte_rev[] = { 0155, 0117, 0127 }; // {A,B}
unsigned short gdab[] = { 0133, 0171, 0145 }; // {A,B}
unsigned short gdab_rev[] = { 0155, 0117, 0123 }; // {A,B}
unsigned char  ccodelte_table[128];      // for transmitter
unsigned char  ccodelte_table_rev[128];  // for receiver

extern unsigned int
crc16 (unsigned char * inptr, int bitlen);
extern unsigned int
crc8 (unsigned char * inptr, int bitlen);
void
ccodelte_encode (int32_t numbits,
                 uint8_t add_crc,
                 uint8_t *inPtr,
                 uint8_t *outPtr,
                 uint16_t rnti)
{
  uint32_t             state;

  uint8_t              c, out, first_bit;
  int8_t shiftbit=0;
  uint16_t c16;
  uint16_t next_last_byte=0;
  uint32_t crc=0;

#ifdef DEBUG_CCODE
  uint32_t  dummy=0;
#endif //DEBUG_CCODE

  /* The input bit is shifted in position 8 of the state.
     Shiftbit will take values between 1 and 8 */
  state = 0;

  if (add_crc == 1) {
    crc = crc8(inPtr,numbits);
    first_bit      = 2;
    c = (uint8_t)(crc>>24);
  } else if (add_crc == 2) {
    crc = crc16(inPtr,numbits);
#ifdef DEBUG_CCODE
    printf("ccode_lte : crc %x\n",crc);
#endif
    // scramble with RNTI
    crc ^= (((uint32_t)rnti)<<16);
#ifdef DEBUG_CCODE
    printf("ccode_lte : crc %x (rnti %x)\n",crc,rnti);
#endif
    first_bit      = 2;
    c = (uint8_t)((crc>>16)&0xff);
  } else {
    next_last_byte = numbits>>3;
    first_bit      = (numbits-6)&7;
    c = inPtr[next_last_byte-1];
  }

#ifdef DEBUG_CCODE
  printf("next_last_byte %x (numbits %d, %d)\n",c,numbits,next_last_byte);
#endif

  // Perform Tail-biting

  // get bits from last byte of input (or crc)
  //  for (shiftbit = first_bit; shiftbit<8; shiftbit++) {
  for (shiftbit = 0 ; shiftbit <(8-first_bit) ; shiftbit++) {
    if ((c&(1<<(7-first_bit-shiftbit))) != 0)
      state |= (1<<shiftbit);

#ifdef DEBUG_CCODE
    printf("shiftbit %d, %d -> %d \n",shiftbit,c&(1<<(7-first_bit-shiftbit)),state);
    dummy+=3;
#endif
  }

  // get bits from next to last byte of input (not when crc is added)
  if ((add_crc==0)&&((numbits&7)>0)) {
    c = inPtr[next_last_byte];

    //    printf("last_byte %x\n",c);
    //    for (shiftbit = 0 ; shiftbit < (numbits&7) ; shiftbit++) {
    for (shiftbit = (numbits&7)-1 ; shiftbit>=0 ; shiftbit--) {
      state >>= 1;

      if ((c&(1<<shiftbit)) != 0)
        state |= 64;

#ifdef DEBUG_CCODE
      printf("shiftbit %d, %d: %d -> %d \n",shiftbit,state>>6,dummy,state);
      dummy+=3;
#endif
    }
  }

  state = state & 0x3f;   // true initial state of Tail-biting CCode
  state<<=1;              // because of loop structure in CCode
#ifdef DEBUG_CCODE
  printf("Initial state %d\n",state);
  dummy = 0;
#endif //DEBUG_CCODE
  /* Do not increment inPtr until we read the next octet */




  while (numbits > 0) {

    c = *inPtr++;
#ifdef DEBUG_CCODE
    printf("** %x **\n",c);
#endif //DEBUG_CCODE


    //    for (shiftbit = 0; (shiftbit<8) && (numbits>0);shiftbit++,numbits--) {
    for (shiftbit = 7; (shiftbit>=0) && (numbits>0); shiftbit--,numbits--) {
      state >>= 1;

      if ((c&(1<<shiftbit)) != 0) {
        state |= 64;
      }

      out = ccodelte_table[state];

      *outPtr++ = out  & 1;
      *outPtr++ = (out>>1)&1;
      *outPtr++ = (out>>2)&1;

#ifdef DEBUG_CCODE
      printf("numbits %d, input %d, outbit %d: %d -> %d (%d%d%d)\n",numbits,state>>6,dummy,state,out,out&1,(out>>1)&1,(out>>2)&1);
      dummy+=3;
#endif //DEBUG_CCODE

    }

  }

  // now code 8-bit CRC for UCI
  if (add_crc == 1) {

    c = (uint8_t)(crc>>24);

    //    for (shiftbit = 0; (shiftbit<8);shiftbit++) {
    for (shiftbit = 7; (shiftbit>=0); shiftbit--) {
      state >>= 1;

      if ((c&(1<<shiftbit)) != 0) {
        state |= 64;
      }

      out = ccodelte_table[state];

      *outPtr++ = out  & 1;
      *outPtr++ = (out>>1)&1;
      *outPtr++ = (out>>2)&1;

#ifdef DEBUG_CCODE
      printf("crc bit %d input %d, outbit %d: %d -> %d (%d)\n",shiftbit,state>>6,dummy,state,out,ccodelte_table[state]);
      dummy+=3;
#endif //DEBUG_CCODE

    }
  }

  // now code 16-bit CRC for DCI
  if (add_crc == 2) {

    c16 = (uint16_t)(crc>>16);

    //    for (shiftbit = 0; (shiftbit<16);shiftbit++) {
    for (shiftbit = 15; (shiftbit>=0); shiftbit--) {
      state >>= 1;

      if ((c16&(1<<shiftbit)) != 0) {
        state |= 64;
      }

      out = ccodelte_table[state];

      *outPtr++ = out  & 1;
      *outPtr++ = (out>>1)&1;
      *outPtr++ = (out>>2)&1;

#ifdef DEBUG_CCODE
      printf("crc bit %d input %d, outbit %d: %d -> %d (%d)\n",shiftbit,state>>6,dummy,state,out,ccodelte_table[state]);
      dummy+=3;
#endif //DEBUG_CCODE

    }
  }
}
poly.hphy_var.hgenerate_pbch.hHi,

I'm using CCSv5 . I'm working on PBCH . My code is compiled and debugged correctly . The problem i'm facing is in running that code. When i'm creating a task and as i'm entering to a function inside that task it gets terminated over there. I've attached all the files. Kindly go through all these files and tell me the possible answer for that.

Thanks,

Lalit  

  • Hi Lalit,

    Can you localize the point in your project where the execution gets terminated? Add a breakpoint and step through the code or add some debug prints... reviewing all the files you've attached is quite time consuming task.

    Best Regards,
    Yordan
  • Hi Yordan,
    I've done that , i put breakpoints in function also and it is able to reach everywhere but now when i enhanced the code the problem is with GEL file , it is saying "Load Program Error: .out: a data verification error occurred, file load failed." Can you tell me how can i remove this error.
    Another question of mine is : Can we dump different codes in different CORES inspite of dumping complete code to each CORE i want to put only CORE specific code in it so that code may be optimized for each core CAN I...?
    Regards,
    LALIT
    ASMAITHA Wireless Networks.