2015-01-29 16:15:09 -08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \section COPYRIGHT
|
|
|
|
*
|
|
|
|
* Copyright 2013-2014 The libLTE Developers. See the
|
|
|
|
* COPYRIGHT file at the top-level directory of this distribution.
|
|
|
|
*
|
|
|
|
* \section LICENSE
|
|
|
|
*
|
|
|
|
* This file is part of the libLTE library.
|
|
|
|
*
|
|
|
|
* libLTE is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* libLTE 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 Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* A copy of the GNU Lesser General Public License can be found in
|
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2015-03-18 05:31:13 -07:00
|
|
|
#include "srslte/srslte.h"
|
2015-03-18 05:16:28 -07:00
|
|
|
#include "srslte/mex/mexutils.h"
|
2015-01-29 16:15:09 -08:00
|
|
|
|
|
|
|
#define UECFG prhs[0]
|
|
|
|
#define PUSCHCFG prhs[1]
|
|
|
|
#define OUTLEN prhs[2]
|
|
|
|
#define TRBLKIN prhs[3]
|
|
|
|
#define NOF_INPUTS 4
|
|
|
|
|
|
|
|
void help()
|
|
|
|
{
|
|
|
|
mexErrMsgTxt
|
2015-03-18 05:16:28 -07:00
|
|
|
("[cwout] = srslte_dlsch_encode(ue, chs, outlen, trblkin)\n\n");
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the gateway function */
|
|
|
|
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
|
|
|
{
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_sch_t dlsch;
|
2015-01-29 16:15:09 -08:00
|
|
|
uint8_t *trblkin;
|
2015-04-27 09:14:28 -07:00
|
|
|
srslte_pdsch_cfg_t cfg;
|
|
|
|
srslte_softbuffer_tx_t softbuffer;
|
2015-01-29 16:15:09 -08:00
|
|
|
|
|
|
|
if (nrhs < NOF_INPUTS) {
|
|
|
|
help();
|
|
|
|
return;
|
|
|
|
}
|
2015-04-27 09:14:28 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
if (srslte_sch_init(&dlsch)) {
|
2015-01-29 16:15:09 -08:00
|
|
|
mexErrMsgTxt("Error initiating DL-SCH\n");
|
|
|
|
return;
|
|
|
|
}
|
2015-03-18 05:41:50 -07:00
|
|
|
srslte_cell_t cell;
|
2015-01-29 16:15:09 -08:00
|
|
|
cell.nof_prb = 100;
|
|
|
|
cell.id=1;
|
2015-04-27 09:14:28 -07:00
|
|
|
|
|
|
|
cfg.grant.mcs.tbs = mexutils_read_uint8(TRBLKIN, &trblkin);
|
|
|
|
if (cfg.grant.mcs.tbs == 0) {
|
2015-01-29 16:15:09 -08:00
|
|
|
mexErrMsgTxt("Error trblklen is zero\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-27 09:14:28 -07:00
|
|
|
if (mexutils_read_uint32_struct(PUSCHCFG, "RV", &cfg.rv)) {
|
2015-01-29 16:15:09 -08:00
|
|
|
mexErrMsgTxt("Field RV not found in dlsch config\n");
|
|
|
|
return;
|
|
|
|
}
|
2015-02-13 02:13:56 -08:00
|
|
|
|
2015-01-29 16:15:09 -08:00
|
|
|
char *mod_str = mexutils_get_char_struct(PUSCHCFG, "Modulation");
|
|
|
|
|
|
|
|
if (!strcmp(mod_str, "QPSK")) {
|
2015-04-27 09:14:28 -07:00
|
|
|
cfg.grant.mcs.mod = SRSLTE_MOD_QPSK;
|
|
|
|
cfg.grant.Qm = 2;
|
2015-01-29 16:15:09 -08:00
|
|
|
} else if (!strcmp(mod_str, "16QAM")) {
|
2015-04-27 09:14:28 -07:00
|
|
|
cfg.grant.mcs.mod = SRSLTE_MOD_16QAM;
|
|
|
|
cfg.grant.Qm = 4;
|
2015-01-29 16:15:09 -08:00
|
|
|
} else if (!strcmp(mod_str, "64QAM")) {
|
2015-04-27 09:14:28 -07:00
|
|
|
cfg.grant.mcs.mod = SRSLTE_MOD_64QAM;
|
|
|
|
cfg.grant.Qm = 6;
|
2015-01-29 16:15:09 -08:00
|
|
|
} else {
|
|
|
|
mexErrMsgTxt("Unknown modulation\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mxFree(mod_str);
|
2015-04-27 09:14:28 -07:00
|
|
|
|
|
|
|
if (srslte_softbuffer_tx_init(&softbuffer, cell)) {
|
|
|
|
mexErrMsgTxt("Error initiating DL-SCH soft buffer\n");
|
|
|
|
return;
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
2015-04-27 09:14:28 -07:00
|
|
|
|
|
|
|
cfg.grant.nof_bits = mxGetScalar(OUTLEN);
|
|
|
|
uint8_t *e_bits = srslte_vec_malloc(cfg.grant.nof_bits * sizeof(uint8_t));
|
2015-01-29 16:15:09 -08:00
|
|
|
if (!e_bits) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-27 09:14:28 -07:00
|
|
|
if (srslte_cbsegm(&cfg.cb_segm, cfg.grant.mcs.tbs)) {
|
|
|
|
mexErrMsgTxt("Error computing CB segmentation\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (srslte_dlsch_encode(&dlsch, &cfg, &softbuffer, trblkin, e_bits)) {
|
2015-01-29 16:15:09 -08:00
|
|
|
mexErrMsgTxt("Error encoding TB\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nlhs >= 1) {
|
2015-04-27 09:14:28 -07:00
|
|
|
mexutils_write_uint8(e_bits, &plhs[0], cfg.grant.nof_bits, 1);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_sch_free(&dlsch);
|
2015-01-29 16:15:09 -08:00
|
|
|
|
|
|
|
free(trblkin);
|
|
|
|
free(e_bits);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|