/*******************************************************************************
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 .
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 DEBUG
#include
#include
#include
#include
#endif
#include "PHY/defs.h"
//#define DEBUG_PHY 1
unsigned int ps0, ps1, ps2, pb;
//----------------------------------------------
//
/*!\brief Tausworthe Uniform Random Generator. This is based on the hardware implementation described in
Lee et al, "A Hardware Gaussian Noise Generator Usign the Box-Muller Method and its Error Analysis," IEEE Trans. on Computers, 2006.
*/
//
static inline void pset_taus_seed(unsigned int off)
{
ps0 = (unsigned int)0x1e23d852 + (off<<4);
ps1 = (unsigned int)0x81f38a1c + (off<<4);
ps2 = (unsigned int)0xfe1a133e + (off<<4);
}
static inline unsigned int ptaus(void)
{
pb = (((ps0 << 13) ^ ps0) >> 19);
ps0 = (((ps0 & 0xFFFFFFFE) << 12)^ pb);
pb = (((ps1 << 2) ^ ps1) >> 25);
ps1 = (((ps1 & 0xFFFFFFF8) << 4)^ pb);
pb = (((ps2 << 3) ^ ps2) >> 11);
ps2 = (((ps2 & 0xFFFFFFF0) << 17)^ pb);
return ps0 ^ ps1 ^ ps2;
}
int rate_matching(unsigned int N_coded,
unsigned int N_input,
unsigned char *inPtr,
unsigned char N_bps,
unsigned int off)
{
unsigned int i,j,U,Umod,rep_flag=0;
unsigned int N_coded2,N_input2,Mod_input2;
int N_punctured;
if ((9*N_coded<(N_input<<2)) || (N_input<(N_coded>>1))) {
// check validity of parameters
// the first condition represents the case where the rate is greater than 2/3
// the second condition represents the case where the rate is less than 1/4
msg("[PHY][CODING] Rate matching parameter error (N_coded %d, N_input %d, N_bps %d), exiting\n",N_coded,N_input,N_bps);
return(-1);
}
//initialize all bits as transmitted
for (i=0; i=N_input2);
for (j=0; j>1))) {
// check validity of parameters
// the first condition represents the case where the rate is greater than 2/3
// the second condition represents the case where the rate is less than 1/4
msg("[PHY][CODING] Rate matching parameter error (N_coded %d, N_input %d), exiting\n",N_coded,N_input);
return(-1);
}
//initialize all bits as transmitted
for (i=0; i=N_input);
if (rep_flag == 0)
inPtr[Umod] &= 0x7f; // clear MSB to indicate bit is punctured
else
inPtr[Umod] |= 0xc0; // set MSB-1 to indicate bit is repeated
/*
#ifdef USER_MODE
#ifdef DEBUG_PHY
printf("rate_matching : i= %d, U = %d\n",i,Umod);
#endif
#endif
*/
i++;
}
return(0);
}
#ifdef MAIN
void main(int argc,char **argv)
{
unsigned char input[1024];
if (argc == 1) {
printf("Provide an input\n");
exit(-1);
}
memset(input,0,1024);
rate_matching(4*157,4*256,input,atoi(argv[1]),0);
}
#endif