Commit b9ddfe65 authored by Florian Kaltenberger's avatar Florian Kaltenberger

moving Matlab to extras


git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7223 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 7fe41b08
include $(OPENAIR_HOME)/common/utils/Makefile.inc
#include $(OPENAIR1_DIR)/SIMULATION/LTE_PHY/Makefile
COMMON_UTILS_DIR = $(OPENAIR_HOME)/common/utils
TOP_DIR = $(OPENAIR1_DIR)
OPENAIR1_TOP = $(OPENAIR1_DIR)
OPENAIR2_TOP = $(OPENAIR2_DIR)
OPENAIR3 = $(OPENAIR3_DIR)
CFLAGS += -DMAX_NUM_CCs=1 -Wall -DPHYSIM -DNODE_RG -DUSER_MODE -DNB_ANTENNAS_RX=2 -DNB_ANTENNAS_TXRX=2 -DNB_ANTENNAS_TX=2 -DPHY_CONTEXT=1 -DMALLOC_CHECK_=1 -DENABLE_VCD_FIFO
CFLAGS += -DOPENAIR_LTE -DNO_RRM -DOPENAIR1 #-DPHY_ABSTRACTION #-DOPENAIR2
CFLAGS += -I/usr/include/X11 -I/usr/X11R6/include
include $(COMMON_UTILS_DIR)/Makefile.inc
include $(TOP_DIR)/PHY/Makefile.inc
include $(TOP_DIR)/SCHED/Makefile.inc
SCHED_OBJS = $(TOP_DIR)/SCHED/phy_procedures_lte_common.o #$(TOP_DIR)/SCHED/phy_procedures_lte_eNb.o $(TOP_DIR)/SCHED/phy_procedures_lte_ue.o
include $(TOP_DIR)/SIMULATION/Makefile.inc
include $(OPENAIR2_DIR)/LAYER2/Makefile.inc
include $(OPENAIR2_DIR)/UTIL/Makefile.inc
include $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/Makefile.inc
ASN1_MSG_INC = $(OPENAIR2_DIR)/RRC/LITE/MESSAGES
CFLAGS += $(L2_incl) -I$(ASN1_MSG_INC) -I$(TOP_DIR) -I$(OPENAIR2_DIR) -I$(OPENAIR3) $(UTIL_incl) $(UTILS_incl)
CFLAGS += -DMEX -fPIC
CFLAGS += -I/opt/MATLAB/R2014a/extern/include/
# Set mex extension, can be determined with mexext function in Matlab
MEXEXT = mexglx
# Just compile all the PHY objects
OBJ = $(PHY_OBJS) $(TOP_DIR)/SIMULATION/TOOLS/taus.o $(LOG_DIR)/log.o $(LOG_DIR)/vcd_signal_dumper.o
# List of all mex-files to compile
MEX_FILES += ./PHY/LTE_TRANSPORT/mexfiles/get_tbs.$(MEXEXT)
MEX_FILES += ./PHY/LTE_TRANSPORT/mexfiles/dlsch_encoding.$(MEXEXT)
MEX_FILES += ./PHY/LTE_TRANSPORT/mexfiles/dlsch_decoding.$(MEXEXT)
MEX_FILES += ./PHY/LTE_TRANSPORT/mexfiles/dlsch_decoding_init.$(MEXEXT)
MEX_FILES += ./PHY/LTE_TRANSPORT/mexfiles/dlsch_channel_level_prec.$(MEXEXT)
MEX_FILES += ./PHY/LTE_TRANSPORT/mexfiles/dlsch_channel_compensation_prec.$(MEXEXT)
MEX_FILES += ./PHY/LTE_TRANSPORT/mexfiles/dlsch_dual_stream_correlation.$(MEXEXT)
MEX_FILES += ./PHY/LTE_TRANSPORT/mexfiles/dlsch_detection_mrc.$(MEXEXT)
MEX_FILES += ./PHY/LTE_TRANSPORT/mexfiles/dlsch_mu_mimo_llr.$(MEXEXT)
MEX_FILES += ./PHY/TOOLS/mexfiles/log2_approx.$(MEXEXT)
MEX_FILES += ./SIMULATION/TOOLS/mexfiles/taus.$(MEXEXT)
MEX_FILES += ./SIMULATION/TOOLS/mexfiles/set_taus_seed.$(MEXEXT)
# ===========================================================================================
# Commands to compile the static and shared lib for mex-files
# Libpath
LIBDIR := ./lib
LIBNAME := oai
sharedlib : $(OBJ)
@$(CC) -shared -Wl,-soname,lib$(LIBNAME).so.1 -o $(LIBDIR)/lib$(LIBNAME).so.1.0.1 $(OBJ) -lc
staticlib : $(OBJ)
@ar ruv $(LIBDIR)/lib$(LIBNAME).a $(OBJ)
libs : $(OBJ)
@$(CC) -shared -Wl,-soname,lib$(LIBNAME).so.1 -o $(LIBDIR)/lib$(LIBNAME).so.1.0.1 $(OBJ) -lc
@ar ruv $(LIBDIR)/lib$(LIBNAME).a $(OBJ)
$(MEX_FILES) : %.$(MEXEXT) : %.c
@echo
@echo Compiling $< ...
@mex CFLAGS="$(CFLAGS)" -l$(LIBNAME) -L$(LIBDIR) -output $@ $<
mex : $(MEX_FILES)
cleanlibs :
rm -f $(LIBDIR)/lib$(LIBNAME).*
cleanmex :
rm -f $(MEX_FILES)
clean:
rm -f $(OBJ)
cleanall: clean cleanlibs cleanmex
show :
echo $(ASN1_MSG_INC)
#include "../../../defs.h"
/*==============================================================================
* dlsch_channel_compensation_prec.c
*
* Returns the matched filter channel and the scaled channel magnitude.
*
* example: [ymf heff hmag hmagb] = dlsch_channel_compensation_prec(y,H,pmi,struct1,struct2,slot)
*
* Author: Sebastian Wagner
* Date: 23-07-2012
*
===============================================================================*/
// #define DEBUG_CHANNEL_COMP
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]
)
{
/* Declare */
int *H,*y,*dl_ch_estimates_ext[NB_ANTENNAS_RX*NB_ANTENNAS_TX],*rxdataF_ext[NB_ANTENNAS_RX*NB_ANTENNAS_TX],*ymf, *hmag, *hmagb,*dl_ch_mag[NB_ANTENNAS_RX*NB_ANTENNAS_TX],
*dl_ch_magb[NB_ANTENNAS_RX*NB_ANTENNAS_TX];
int *rxdataF_comp[NB_ANTENNAS_RX*NB_ANTENNAS_TX], *ymf_out, *hmag_out, *hmagb_out, *heff_out, *heff;
unsigned int nb_re_per_symbol, nb_re, nb_re_per_frame;
unsigned char *pmi_ext, mod_order, output_shift,dl_power_off;
unsigned char symbol;
int eNB_id = 0,i; // dummy
mxArray *tmp;
LTE_DL_FRAME_PARMS *frame_parms;
PHY_MEASUREMENTS *phy_measurements;
/* Check proper input and output. */
if(nrhs!=6)
mexErrMsgTxt("5 inputs required.");
else if(nlhs > 4)
mexErrMsgTxt("Too many output arguments.");
else if(!mxIsStruct(prhs[3]))
mexErrMsgTxt("Fourth input must be a structure.");
else if(!mxIsStruct(prhs[4]))
mexErrMsgTxt("Fifth input must be a structure.");
if(!mxIsInt16(prhs[0]))
mexErrMsgTxt("First argument must belong to Int16 class.");
if(!mxIsInt16(prhs[1]))
mexErrMsgTxt("Second argument must belong to Int16 class.");
if(!mxIsUint8(prhs[2]))
mexErrMsgTxt("Third argument must belong to Uint8 class.");
/* Allocate input */
y = (int*) mxGetData(prhs[0]);
H = (int*) mxGetData(prhs[1]);
pmi_ext = (unsigned char*) mxGetData(prhs[2]);
symbol = (unsigned char) mxGetScalar(prhs[5]);
tmp = mxGetField(prhs[4],0,"mod_order");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'mod_order' in input argument 5.");
} else {
mod_order = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[3],0,"log2_maxh");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'log2_maxh' in input argument 4.");
} else {
output_shift = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[3],0,"dl_power_offset");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'dl_power_offset' in input argument 4.");
} else {
dl_power_off = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[3],0,"nb_re");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'nb_re' in input argument 4.");
} else {
nb_re = (unsigned int) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[3],0,"nb_re_per_frame");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'nb_re_per_frame' in input argument 4.");
} else {
nb_re_per_frame = (unsigned int) mxGetScalar(tmp);
}
// Create a LTE_DL_FRAME_PARMS structure and assign required params
frame_parms = calloc(1,sizeof(LTE_DL_FRAME_PARMS));
tmp = mxGetField(prhs[3],0,"nb_rb");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'nb_rb' in input argument 4.");
} else {
frame_parms->N_RB_DL = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[3],0,"nb_antennas_rx");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'nb_antennas_rx' in input argument 4.");
} else {
frame_parms->nb_antennas_rx = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[3],0,"nb_antennas_tx");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'nb_antennas_tx' in input argument 4.");
} else {
frame_parms->nb_antennas_tx = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[3],0,"Ncp");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'Ncp' in input argument 4.");
} else {
frame_parms->Ncp = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[3],0,"ofdm_symbol_size");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'ofdm_symbol_size' in input argument 4.");
} else {
frame_parms->ofdm_symbol_size = (unsigned short) mxGetScalar(tmp);
}
// Create PHY_MEASUREMENTS structure and assign required params
phy_measurements = calloc(1,sizeof(PHY_MEASUREMENTS));
phy_measurements->n0_power[0] = 1; // dummy values
phy_measurements->n0_power[1] = 1;
phy_measurements->n0_power_tot = 1;
// Adapt the channel estimates and receive signal
nb_re_per_symbol = frame_parms->N_RB_DL*12;
// Assign pointers
rxdataF_ext[0] = y;
rxdataF_ext[1] = &y[nb_re_per_frame];
rxdataF_ext[2] = &y[2*nb_re_per_frame];
rxdataF_ext[3] = &y[3*nb_re_per_frame];
/* Allocate Output */
plhs[0] = mxCreateNumericMatrix(2*nb_re_per_symbol,NB_ANTENNAS_RX*NB_ANTENNAS_TX, mxINT16_CLASS, mxREAL);
ymf_out = (int*) mxGetPr(plhs[0]);
plhs[1] = mxCreateNumericMatrix(2*nb_re_per_symbol,NB_ANTENNAS_RX*NB_ANTENNAS_TX, mxINT16_CLASS, mxREAL);
heff_out = (int*) mxGetPr(plhs[1]);
plhs[2] = mxCreateNumericMatrix(2*nb_re_per_symbol,NB_ANTENNAS_RX*NB_ANTENNAS_TX, mxINT16_CLASS, mxREAL);
hmag_out = (int*) mxGetPr(plhs[2]);
plhs[3] = mxCreateNumericMatrix(2*nb_re_per_symbol,NB_ANTENNAS_RX*NB_ANTENNAS_TX, mxINT16_CLASS, mxREAL);
hmagb_out = (int*) mxGetPr(plhs[3]);
ymf = (int*) mxCalloc(nb_re_per_frame*NB_ANTENNAS_RX*NB_ANTENNAS_TX, sizeof(int));
heff = (int*) mxCalloc(nb_re_per_frame*NB_ANTENNAS_RX*NB_ANTENNAS_TX, sizeof(int));
hmag = (int*) mxCalloc(nb_re_per_frame*NB_ANTENNAS_RX*NB_ANTENNAS_TX, sizeof(int));
hmagb = (int*) mxCalloc(nb_re_per_frame*NB_ANTENNAS_RX*NB_ANTENNAS_TX, sizeof(int));
// copy input since it gets modified in function "dlsch_channel_compensation_prec"
memcpy(heff,H,(NB_ANTENNAS_RX*NB_ANTENNAS_TX*nb_re_per_frame)<<2);
rxdataF_comp[0] = ymf;
rxdataF_comp[1] = &ymf[nb_re_per_frame];
rxdataF_comp[2] = &ymf[2*nb_re_per_frame];
rxdataF_comp[3] = &ymf[3*nb_re_per_frame];
dl_ch_estimates_ext[0] = heff;
dl_ch_estimates_ext[1] = &heff[nb_re_per_frame];
dl_ch_estimates_ext[2] = &heff[2*nb_re_per_frame];
dl_ch_estimates_ext[3] = &heff[3*nb_re_per_frame];
dl_ch_mag[0] = hmag;
dl_ch_mag[1] = &hmag[nb_re_per_frame];
dl_ch_mag[2] = &hmag[2*nb_re_per_frame];
dl_ch_mag[3] = &hmag[3*nb_re_per_frame];
dl_ch_magb[0] = hmagb;
dl_ch_magb[1] = &hmagb[nb_re_per_frame];
dl_ch_magb[2] = &hmagb[2*nb_re_per_frame];
dl_ch_magb[3] = &hmagb[3*nb_re_per_frame];
#ifdef DEBUG_CHANNEL_COMP
mexPrintf("symbol = %d\n", symbol);
mexPrintf("nb_re_per_symbol = %d\n", nb_re_per_symbol);
mexPrintf("nb_re_per_frame = %d\n", nb_re_per_frame);
for(i=0; i<25; i++)
mexPrintf("pmi_ext = %d\n", pmi_ext[i]);
#endif
/* Algo */
dlsch_channel_compensation_prec(rxdataF_ext,
dl_ch_estimates_ext,
dl_ch_mag,
dl_ch_magb,
rxdataF_comp,
pmi_ext,
frame_parms,
phy_measurements,
eNB_id,
symbol,
mod_order,
frame_parms->N_RB_DL,
output_shift,
dl_power_off);
// memcpy copies bytes!
memcpy(ymf_out,&rxdataF_comp[0][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&ymf_out[nb_re_per_symbol],&rxdataF_comp[1][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&ymf_out[2*nb_re_per_symbol],&rxdataF_comp[2][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&ymf_out[3*nb_re_per_symbol],&rxdataF_comp[3][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(hmag_out,&dl_ch_mag[0][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&hmag_out[nb_re_per_symbol],&dl_ch_mag[1][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&hmag_out[2*nb_re_per_symbol],&dl_ch_mag[2][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&hmag_out[3*nb_re_per_symbol],&dl_ch_mag[3][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(hmagb_out, &dl_ch_magb[0][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&hmagb_out[nb_re_per_symbol],&dl_ch_magb[1][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&hmagb_out[2*nb_re_per_symbol],&dl_ch_magb[2][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&hmagb_out[3*nb_re_per_symbol],&dl_ch_magb[3][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(heff_out,&dl_ch_estimates_ext[0][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&heff_out[nb_re_per_symbol],&dl_ch_estimates_ext[1][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&heff_out[2*nb_re_per_symbol],&dl_ch_estimates_ext[2][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
memcpy(&heff_out[3*nb_re_per_symbol],&dl_ch_estimates_ext[3][symbol*frame_parms->N_RB_DL*12],nb_re_per_symbol<<2);
/* free */
free(frame_parms);
free(phy_measurements);
mxFree(ymf);
mxFree(heff);
mxFree(hmag);
mxFree(hmagb);
}
#include "../../../defs.h"
/*==============================================================================
* dlsch_channel_level_prec.c
*
* Returns average squared channel magnitude of effective channel.
*
* example: avg = dlsch_channel_level_prec(H,pmi,simparms);
*
* Author: Sebastian Wagner
* Date: 23-07-2012
*
===============================================================================*/
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]
)
{
/* Declare */
int *H,*dl_ch_estimates_ext[4];
unsigned int nb_re_per_frame;
unsigned char *pmi_ext;
unsigned char symbol_mod = 3;
int *avg;
mxArray *tmp;
LTE_DL_FRAME_PARMS *frame_parms;
/* Check proper input and output. */
if(nrhs!=3)
mexErrMsgTxt("Three inputs required.");
else if(nlhs > 1)
mexErrMsgTxt("Too many output arguments.");
else if(!mxIsStruct(prhs[2]))
mexErrMsgTxt("Third input must be a structure.");
if(!mxIsInt16(prhs[0]))
mexErrMsgTxt("First argument must belong to Int16 class.");
if(!mxIsUint8(prhs[1]))
mexErrMsgTxt("Second argument must belong to Uint8 class.");
/* Allocate input */
H = (int*) mxGetData(prhs[0]);
pmi_ext = (unsigned char*) mxGetData(prhs[1]);
// Create a LTE_DL_FRAME_PARMS structure and assign required params
frame_parms = calloc(1,sizeof(LTE_DL_FRAME_PARMS));
tmp = mxGetField(prhs[2],0,"nb_rb");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'nb_rb' in input argument 3.");
} else {
frame_parms->N_RB_DL = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[2],0,"nb_antennas_rx");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'nb_antennas_rx' in input argument 3.");
} else {
frame_parms->nb_antennas_rx = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[2],0,"mode1_flag");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'mode1_flag' in input argument 3.");
} else {
frame_parms->mode1_flag = (unsigned char) mxGetScalar(tmp);
}
tmp = mxGetField(prhs[2],0,"Ncp");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'Ncp' in input argument 3.");
} else {
frame_parms->Ncp = (unsigned char) mxGetScalar(tmp);
}
// Adapt the channel estimates
tmp = mxGetField(prhs[2],0,"nb_re_per_frame");
if (tmp == NULL) {
mexErrMsgTxt("Non-existing field 'nb_re_per_frame' in input argument 3.");
} else {
nb_re_per_frame = (unsigned int) mxGetScalar(tmp);
}
dl_ch_estimates_ext[0] = (int*) H;
dl_ch_estimates_ext[1] = (int*) &H[nb_re_per_frame];
dl_ch_estimates_ext[2] = (int*) &H[2*nb_re_per_frame];
dl_ch_estimates_ext[3] = (int*) &H[3*nb_re_per_frame];
/* Allocate Output */
plhs[0] = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
avg = (int*) mxGetPr(plhs[0]);
/* Algo */
dlsch_channel_level_prec(dl_ch_estimates_ext, frame_parms, pmi_ext, avg, symbol_mod, frame_parms->N_RB_DL);
/* free */
free(frame_parms);
}
#include "../../../defs.h"
/*==============================================================================
* dlsch_encoding.c
*
* Returns the decoded bit sequence.
*
* example: e = dlsch_encoding(llrs,struct1,struct2)
*
* Author: Sebastian Wagner
* Date: 23-07-2012
*
===============================================================================*/
#define DEBUG_DLSCH_DECODING
void mexFunction( int mlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]
)
{
/* Declare */
short *dlsch_llr;
unsigned char mcs;
unsigned int *ret;
unsigned char mod_order;
unsigned char num_pdcch_symbols;
unsigned char harq_pid;
unsigned char subframe;
unsigned char Kmimo;
unsigned char Mdlharq;
unsigned char abstraction_flag;
LTE_UE_DLSCH_t* dlsch;
LTE_DL_FRAME_PARMS *frame_parms;
PHY_VARS_UE *phy_vars_ue;
extern int *pi2tab16[188],*pi5tab16[188],*pi4tab16[188],*pi6tab16[188];
unsigned long *ptr_td; //hack for 64bit
int *tmp[1];
/* Allocate input */
dlsch_llr = (short*) mxGetData(prhs[0]);
/* Create new dlsch */
Kmimo = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"Kmimo"));
Mdlharq = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"Mdlharq"));
abstraction_flag = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"abstraction_flag"));
mcs = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"mcs"));
#ifdef DEBUG_DLSCH_DECODING
mexPrintf("Kmimo %d\n",Kmimo);
mexPrintf("Mdlharq %d\n",Mdlharq);
mexPrintf("abstraction_flag %d\n",abstraction_flag);
mexPrintf("mcs %d\n",mcs);
#endif
/* Create new dlsch */
dlsch = new_ue_dlsch(Kmimo,Mdlharq,8,25,abstraction_flag);
// Init CRC tables
crcTableInit();
// init_td();
// copy the pointers to memory allocated in dlsch_decoding_init
ptr_td = (unsigned int*) mxGetData(mxGetField(prhs[1],0,"ptr_td"));
#ifdef DEBUG_DLSCH_DECODING
mexPrintf("ptr_td0 %p\n",ptr_td[0]);
mexPrintf("ptr_td1 %p\n",ptr_td[1]);
mexPrintf("ptr_td2 %p\n",ptr_td[2]);
mexPrintf("ptr_td3 %p\n",ptr_td[3]);
#endif
memcpy(&tmp[0], &ptr_td[0], sizeof(ptr_td[0]));
memcpy(&pi2tab16[0], tmp[0], 188*sizeof(pi2tab16[0]));
memcpy(&tmp[0], &ptr_td[1], sizeof(ptr_td[1]));
memcpy(&pi4tab16[0], tmp[0], 188*sizeof(pi4tab16[0]));
memcpy(&tmp[0], &ptr_td[2], sizeof(ptr_td[2]));
memcpy(&pi5tab16[0], tmp[0], 188*sizeof(pi5tab16[0]));
memcpy(&tmp[0], &ptr_td[3], sizeof(ptr_td[3]));
memcpy(&pi6tab16[0], tmp[0], 188*sizeof(pi6tab16[0]));
harq_pid = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"harq_pid"));
dlsch->current_harq_pid = harq_pid;
dlsch->harq_processes[harq_pid]->rvidx = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"rvidx"));
dlsch->harq_processes[harq_pid]->Nl = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"Nl"));
//dlsch->harq_processes[harq_pid]->Ndi = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"Ndi"));
dlsch->harq_processes[harq_pid]->mcs = mcs;
dlsch->harq_processes[harq_pid]->rb_alloc[0] = (unsigned int) mxGetScalar(mxGetField(prhs[1],0,"rb_alloc"));
dlsch->harq_processes[harq_pid]->nb_rb = (unsigned short) mxGetScalar(mxGetField(prhs[1],0,"nb_rb"));
dlsch->harq_processes[harq_pid]->TBS = dlsch_tbs25[get_I_TBS(mcs)][dlsch->harq_processes[harq_pid]->nb_rb-1];
num_pdcch_symbols = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"num_pdcch_symbols"));
subframe = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"subframe"));
phy_vars_ue = calloc(1,sizeof(PHY_VARS_UE));
// Create a LTE_DL_FRAME_PARMS structure and assign required params
frame_parms = calloc(1,sizeof(LTE_DL_FRAME_PARMS));
frame_parms->N_RB_DL = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"nb_rb"));
frame_parms->frame_type = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"frame_type"));
frame_parms->mode1_flag = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"mode1_flag"));
frame_parms->Ncp = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"Ncp"));
mod_order = get_Qm(dlsch->harq_processes[harq_pid]->mcs);
dlsch->harq_processes[harq_pid]->G = get_G(frame_parms,dlsch->harq_processes[harq_pid]->nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,
0,subframe);
#ifdef DEBUG_DLSCH_DECODING
mexPrintf("TBS %d\n",dlsch->harq_processes[harq_pid]->TBS);
mexPrintf("nb_rb %d\n",dlsch->harq_processes[harq_pid]->nb_rb);
mexPrintf("ncs %d\n",dlsch->harq_processes[harq_pid]->mcs);
mexPrintf("num_pdcch_symbols %d\n",num_pdcch_symbols);
mexPrintf("subframe %d\n",subframe);
mexPrintf("G %d\n",dlsch->harq_processes[harq_pid]->G);
#endif
if (dlsch->harq_processes[harq_pid]->G != mxGetM(prhs[0])) {
free_ue_dlsch(dlsch);
free(frame_parms);
free(phy_vars_ue);
mexErrMsgTxt("Length of the LLR vector is incorrect.");
}
/* Allocate Output */
plhs[0] = mxCreateNumericMatrix(1, 1, mxUINT32_CLASS, mxREAL);
ret = (unsigned int*) mxGetPr(plhs[0]);
/* Algo */
*ret = dlsch_decoding(phy_vars_ue, dlsch_llr, frame_parms, dlsch, dlsch->harq_processes[harq_pid], subframe, dlsch->current_harq_pid, 1,0);
/* free dlsch */
free_ue_dlsch(dlsch);
free(frame_parms);
free(phy_vars_ue);
// free_td();
}
#include "../../../defs.h"
/*==============================================================================
* dlsch_encoding_init.c
*
* Returns the decoded bit sequence.
*
* example: dlsch_decoding_init(struct1)
*
* Author: Sebastian Wagner
* Date: 23-07-2012
*
===============================================================================*/
#define DEBUG_DLSCH_DECODING_INIT
void mexFunction( int mlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]
)
{
extern int *pi2tab16[188],*pi5tab16[188],*pi4tab16[188],*pi6tab16[188];
int i;
unsigned long *ptr; //hack for 64bit
int **tmp[1];
// Init CRC tables
// crcTableInit();
init_td16();
// assign output
plhs[0] = mxCreateNumericMatrix(4,1, mxUINT64_CLASS, mxREAL);
ptr = (unsigned int*) mxGetData(plhs[0]);
tmp[0] = &pi2tab16[0];
memcpy(&ptr[0], tmp, sizeof(tmp[0]));
tmp[0] = &pi4tab16[0];
memcpy(&ptr[1], tmp, sizeof(tmp[0]));
tmp[0] = &pi5tab16[0];
memcpy(&ptr[2], tmp, sizeof(tmp[0]));
tmp[0] = &pi6tab16[0];
memcpy(&ptr[3], tmp, sizeof(tmp[0]));
#ifdef DEBUG_DLSCH_DECODING_INIT
mexPrintf("pi2tab %p\n",&pi2tab16[0]);
mexPrintf("pi4tab %p\n",&pi4tab16[0]);
mexPrintf("pi5tab %p\n",&pi5tab16[0]);
mexPrintf("pi6tab %p\n",&pi6tab16[0]);
mexPrintf("ptr0 %p\n",ptr[0]);
mexPrintf("ptr1 %p\n",ptr[1]);
mexPrintf("ptr2 %p\n",ptr[2]);
mexPrintf("ptr3 %p\n",ptr[3]);
#endif
// The memory here is never explictly freed via mxFree. It is implicitly taken
// care of by clear functions at the beginning of the simulation.
for (i=0; i<188; i++) {
mexMakeMemoryPersistent((void *) pi2tab16[i]);