diff --git a/matlab/tests/pucch_test.m b/matlab/tests/pucch_test.m index 441131f55..5aa094cda 100644 --- a/matlab/tests/pucch_test.m +++ b/matlab/tests/pucch_test.m @@ -1,13 +1,13 @@ clear ueConfig=struct('NCellID',25,'RNTI',11,'NULRB',6,'NSubframe',1,'CyclicPrefixUL','Normal','NTxAnts',1,'Hopping','Off'); -pucchConfig=struct('NLayers',1,'OrthCover','Off','Shortened',0,'ResourceSize',0); +pucchConfig=struct('NLayers',1,'OrthCover','Off','Shortened',1,'ResourceSize',0); addpath('../../build/srslte/lib/phch/test') format_str={'1','1a','1b','2','2a','2b'}; k=1; -for f=1:5 +for f=0:2 for n=0:7:130 for d=1:3 for ncs=0:d:7 @@ -48,7 +48,8 @@ for f=1:5 if (error_sym > 1e-5) disp(info) - plot(abs(sym-sym_mat)) + plot(1:length(sym),sym,1:length(sym_mat),sym_mat) + legend('srsLTE','Matlab') error('Error in symbols'); end if (error_dmrs > 1e-5) diff --git a/srsapps/common/include/srsapps/common/log.h b/srsapps/common/include/srsapps/common/log.h index bcba58745..06a0b2652 100644 --- a/srsapps/common/include/srsapps/common/log.h +++ b/srsapps/common/include/srsapps/common/log.h @@ -40,10 +40,10 @@ #ifndef LOG_H #define LOG_H -#define Error(fmt, ...) log_h->error(__FILE__, __LINE__, fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) log_h->warning(__FILE__, __LINE__, fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(__FILE__, __LINE__, fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) log_h->warning_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__) namespace srslte { @@ -78,10 +78,10 @@ public: virtual void debug(std::string message, ...) = 0; // Same with line and file info -// virtual void error(std::string file, int line, std::string message, ...) = 0; -// virtual void warning(std::string file, int line, std::string message, ...) = 0; -// virtual void info(std::string file, int line, std::string message, ...) = 0; -// virtual void debug(std::string file, int line, std::string message, ...) = 0; + virtual void error_line(std::string file, int line, std::string message, ...) = 0; + virtual void warning_line(std::string file, int line, std::string message, ...) = 0; + virtual void info_line(std::string file, int line, std::string message, ...) = 0; + virtual void debug_line(std::string file, int line, std::string message, ...) = 0; protected: std::string get_service_name() { return service_name; } diff --git a/srsapps/common/include/srsapps/common/log_stdout.h b/srsapps/common/include/srsapps/common/log_stdout.h index df5ac809d..89408c60a 100644 --- a/srsapps/common/include/srsapps/common/log_stdout.h +++ b/srsapps/common/include/srsapps/common/log_stdout.h @@ -59,10 +59,10 @@ public: void debug(string message, ...); // Same with line and file info - void error(string file, int line, string message, ...); - void warning(string file, int line, string message, ...); - void info(string file, int line, string message, ...); - void debug(string file, int line, string message, ...); + void error_line(string file, int line, string message, ...); + void warning_line(string file, int line, string message, ...); + void info_line(string file, int line, string message, ...); + void debug_line(string file, int line, string message, ...); private: typedef enum { diff --git a/srsapps/common/src/log_stdout.cc b/srsapps/common/src/log_stdout.cc index 81e6e51d1..c8422197d 100644 --- a/srsapps/common/src/log_stdout.cc +++ b/srsapps/common/src/log_stdout.cc @@ -96,7 +96,7 @@ void log_stdout::warning(string msg, ...) } -void log_stdout::error(string file, int line, string msg, ...) +void log_stdout::error_line(string file, int line, string msg, ...) { va_list args; va_start(args, msg); @@ -104,7 +104,7 @@ void log_stdout::error(string file, int line, string msg, ...) va_end(args); } -void log_stdout::info(string file, int line, string msg, ...) +void log_stdout::info_line(string file, int line, string msg, ...) { if (level >= LOG_LEVEL_INFO) { va_list args; @@ -114,7 +114,7 @@ void log_stdout::info(string file, int line, string msg, ...) } } -void log_stdout::debug(string file, int line, string msg, ...) +void log_stdout::debug_line(string file, int line, string msg, ...) { if (level >= LOG_LEVEL_DEBUG) { va_list args; @@ -124,7 +124,7 @@ void log_stdout::debug(string file, int line, string msg, ...) } } -void log_stdout::warning(string file, int line, string msg, ...) +void log_stdout::warning_line(string file, int line, string msg, ...) { va_list args; va_start(args, msg); diff --git a/srsapps/ue/phy/src/phy.cc b/srsapps/ue/phy/src/phy.cc index 3ad6699d4..752840f29 100644 --- a/srsapps/ue/phy/src/phy.cc +++ b/srsapps/ue/phy/src/phy.cc @@ -199,7 +199,7 @@ bool phy::sr_is_ready_to_send(uint32_t tti_) { if (srslte_ue_ul_sr_send_tti(I_sr, tti_)) { sr_enabled = false; sr_tx_tti = tti_; - Info("SR sending at TTI=%d\n", tti_); + Info("SR transmission at TTI=%d\n", tti_); return true; } } diff --git a/srsapps/ue/phy/src/ul_buffer.cc b/srsapps/ue/phy/src/ul_buffer.cc index 729dfbcb8..eaa9aafb1 100644 --- a/srsapps/ue/phy/src/ul_buffer.cc +++ b/srsapps/ue/phy/src/ul_buffer.cc @@ -102,7 +102,6 @@ bool ul_buffer::generate_cqi_report() bool ul_buffer::generate_sr() { uci_data.scheduling_request = true; uci_pending = true; - Debug("SR Generating\n"); return true; } @@ -154,6 +153,14 @@ bool ul_buffer::generate_data(ul_sched_grant *grant, srslte_softbuffer_tx_t *sof pusch_hopping.current_tx_nb = grant->get_current_tx_nb(); } + bool is_shortened = false; + if (params_db->get_param(phy_params::SRS_IS_CS_CONFIGURED)) { + if (srslte_refsignal_srs_send_cs((uint32_t) params_db->get_param(phy_params::SRS_CS_SFCFG), tti%10) == 1) { + is_shortened = true; + Info("PUCCH/PUSCH Shortened\n"); + } + } + srslte_pucch_cfg_t pucch_cfg; bzero(&pucch_cfg, sizeof(srslte_pucch_cfg_t)); pucch_cfg.beta_pucch = (float) params_db->get_param(phy_params::PUCCH_BETA)/10; @@ -161,7 +168,8 @@ bool ul_buffer::generate_data(ul_sched_grant *grant, srslte_softbuffer_tx_t *sof pucch_cfg.group_hopping_en = dmrs_cfg.group_hopping_en; pucch_cfg.N_cs = params_db->get_param(phy_params::PUCCH_CYCLIC_SHIFT); pucch_cfg.n_rb_2 = params_db->get_param(phy_params::PUCCH_N_RB_2); - + pucch_cfg.shortened = is_shortened; + srslte_pucch_sched_t pucch_sched; bzero(&pucch_sched, sizeof(srslte_pucch_sched_t)); pucch_sched.n_cce = last_n_cce; @@ -178,22 +186,12 @@ bool ul_buffer::generate_data(ul_sched_grant *grant, srslte_softbuffer_tx_t *sof uci_data.I_offset_ack = params_db->get_param(phy_params::UCI_I_OFFSET_ACK); uci_data.I_offset_cqi = params_db->get_param(phy_params::UCI_I_OFFSET_CQI); uci_data.I_offset_ri = params_db->get_param(phy_params::UCI_I_OFFSET_RI); - + int n = 0; // Transmit on PUSCH if UL grant available, otherwise in PUCCH if (grant) { - /* - uint32_t N_srs = 0; - if (params_db->get_param(phy_params::SRS_IS_CS_CONFIGURED)) { - if (srslte_refsignal_srs_send_cs((uint32_t) params_db->get_param(phy_params::SRS_CS_SFCFG), tti%10) == 1) { - N_srs = 1; - printf("UL grant tti=%d is shortened. SF-CFG=%d\n", tti, - (int) params_db->get_param(phy_params::SRS_CS_SFCFG)); - } - } - */ - grant->to_pusch_cfg(tti%10, 0, &ue_ul); + grant->to_pusch_cfg(tti%10, is_shortened?1:0, &ue_ul); Info("PUSCH: TTI=%d, TBS=%d, mod=%s, rb_start=%d n_prb=%d, ack=%s, sr=%s, rnti=%d, sf_idx=%d\n", tti, grant->get_tbs(), srslte_mod_string(ue_ul.pusch_cfg.grant.mcs.mod), ue_ul.pusch_cfg.grant.n_prb[0], @@ -207,6 +205,7 @@ bool ul_buffer::generate_data(ul_sched_grant *grant, srslte_softbuffer_tx_t *sof grant->get_rnti(), signal_buffer); } else { + Info("PUCCH: TTI=%d n_cce=%d, sf_idx=%d, ack=%s, sr=%s\n", tti, last_n_cce, tti%10, uci_data.uci_ack_len>0?(uci_data.uci_ack?"1":"0"):"no",uci_data.scheduling_request?"yes":"no"); diff --git a/srslte/include/srslte/phch/pucch.h b/srslte/include/srslte/phch/pucch.h index 3c77b4426..b4399029c 100644 --- a/srslte/include/srslte/phch/pucch.h +++ b/srslte/include/srslte/phch/pucch.h @@ -70,6 +70,7 @@ typedef struct SRSLTE_API { uint32_t n_rb_2; uint32_t N_cs; bool group_hopping_en; + bool shortened; } srslte_pucch_cfg_t; /* PUSCH object */ @@ -100,6 +101,9 @@ SRSLTE_API bool srslte_pucch_set_cfg(srslte_pucch_t* q, SRSLTE_API int srslte_pucch_set_crnti(srslte_pucch_t *q, uint16_t c_rnti); +SRSLTE_API uint32_t srslte_pucch_nof_symbols(srslte_pucch_cfg_t *cfg, + srslte_pucch_format_t format); + SRSLTE_API int srslte_pucch_encode(srslte_pucch_t *q, srslte_pucch_format_t format, uint32_t n_pucch, // n_pucch_1 or n_pucch_2 depending on format diff --git a/srslte/lib/phch/src/pucch.c b/srslte/lib/phch/src/pucch.c index 65cf298dc..ef73e0bc7 100644 --- a/srslte/lib/phch/src/pucch.c +++ b/srslte/lib/phch/src/pucch.c @@ -49,10 +49,18 @@ uint32_t pucch_symbol_format1_cpext[4] = {0, 1, 4, 5}; uint32_t pucch_symbol_format2_cpnorm[5] = {0, 2, 3, 4, 6}; uint32_t pucch_symbol_format2_cpext[5] = {0, 1, 2, 4, 5}; -// Table 5.4.1-2 Orthogonal sequences w for N_sf=4 -float w_n_oc[3][4] = {{1, 1, 1, 1}, - {1,-1, 1,-1}, - {1,-1,-1,1}}; +float w_n_oc[2][3][4] = { + // Table 5.4.1-2 Orthogonal sequences w for N_sf=4 (complex argument) + {{0, 0, 0, 0}, + {0,M_PI, 0, M_PI}, + {0,M_PI, M_PI, 0}}, + // Table 5.4.1-3 Orthogonal sequences w for N_sf=3 + {{0, 0, 0, 0}, + {0,2*M_PI/3, 4*M_PI/3,0}, + {0,4*M_PI/3,2*M_PI/3,0}}, + +}; + /* Verify PUCCH configuration as given in Section 5.4 36.211 */ bool srslte_pucch_cfg_isvalid(srslte_pucch_cfg_t *cfg, uint32_t nof_prb) { @@ -80,12 +88,16 @@ void srslte_pucch_cfg_default(srslte_pucch_cfg_t *cfg) { cfg->delta_pucch_shift = 1; } -uint32_t get_N_sf(srslte_pucch_format_t format) { +uint32_t get_N_sf(srslte_pucch_format_t format, uint32_t slot_idx, bool shortened) { switch (format) { case SRSLTE_PUCCH_FORMAT_1: case SRSLTE_PUCCH_FORMAT_1A: case SRSLTE_PUCCH_FORMAT_1B: - return 4; + if (!slot_idx) { + return 4; + } else { + return shortened?3:4; + } case SRSLTE_PUCCH_FORMAT_2: case SRSLTE_PUCCH_FORMAT_2A: case SRSLTE_PUCCH_FORMAT_2B: @@ -94,6 +106,14 @@ uint32_t get_N_sf(srslte_pucch_format_t format) { return 0; } +uint32_t srslte_pucch_nof_symbols(srslte_pucch_cfg_t *cfg, srslte_pucch_format_t format) { + uint32_t len=0; + for (uint32_t ns=0;ns<2;ns++) { + len += SRSLTE_NRE*get_N_sf(format, ns, cfg->shortened); + } + return len; +} + // Number of bits per subframe (M_bit) Table 5.4-1 36.211 uint32_t srslte_pucch_nbits_format(srslte_pucch_format_t format) { switch(format) { @@ -271,8 +291,9 @@ static int pucch_put(srslte_pucch_t *q, srslte_pucch_format_t format, uint32_t n // Determine m uint32_t m = srslte_pucch_m(&q->pucch_cfg, format, n_pucch, q->cell.cp); - uint32_t N_sf = get_N_sf(format); + uint32_t N_sf_0 = get_N_sf(format, 0, q->pucch_cfg.shortened); for (uint32_t ns=0;ns<2;ns++) { + uint32_t N_sf = get_N_sf(format, ns%2, q->pucch_cfg.shortened); // Determine n_prb uint32_t n_prb = m/2; if ((m+ns)%2) { @@ -283,7 +304,7 @@ static int pucch_put(srslte_pucch_t *q, srslte_pucch_format_t format, uint32_t n for (uint32_t i=0;icell.cp); memcpy(&output[SRSLTE_RE_IDX(q->cell.nof_prb, l+ns*nsymbols, n_prb*SRSLTE_NRE)], - &q->z[i*SRSLTE_NRE+ns*N_sf*SRSLTE_NRE], + &q->z[i*SRSLTE_NRE+ns*N_sf_0*SRSLTE_NRE], SRSLTE_NRE*sizeof(cf_t)); } } else { @@ -467,9 +488,9 @@ int srslte_pucch_encode(srslte_pucch_t* q, srslte_pucch_format_t format, fprintf(stderr, "Error encoding PUCCH bits\n"); return SRSLTE_ERROR; } - - uint32_t N_sf=get_N_sf(format); + uint32_t N_sf_0 = get_N_sf(format, 0, q->pucch_cfg.shortened); for (uint32_t ns=2*sf_idx;ns<2*(sf_idx+1);ns++) { + uint32_t N_sf = get_N_sf(format, ns%2, q->pucch_cfg.shortened); // Get group hopping number u uint32_t f_gh=0; if (q->pucch_cfg.group_hopping_en) { @@ -478,7 +499,7 @@ int srslte_pucch_encode(srslte_pucch_t* q, srslte_pucch_format_t format, uint32_t u = (f_gh + (q->cell.id%30))%30; srslte_refsignal_r_uv_arg_1prb(q->tmp_arg, u); - + uint32_t N_sf_widx = N_sf==3?1:0; for (uint32_t m=0;mcell.cp); uint32_t n_prime_ns; @@ -499,8 +520,8 @@ int srslte_pucch_encode(srslte_pucch_t* q, srslte_pucch_format_t format, DEBUG("PUCCH d_0: %.1f+%.1fi, alpha: %.1f, n_oc: %d, n_prime_ns: %d, n_rb_2=%d\n", __real__ q->d[0], __imag__ q->d[0], alpha, n_oc, n_prime_ns, q->pucch_cfg.n_rb_2); for (uint32_t n=0;nz[(ns%2)*N_sf*SRSLTE_PUCCH_N_SEQ+m*SRSLTE_PUCCH_N_SEQ+n] = q->pucch_cfg.beta_pucch - *q->d[0]*w_n_oc[n_oc%3][m]*cexpf(I*(q->tmp_arg[n]+alpha*n+S_ns)); + q->z[(ns%2)*N_sf_0*SRSLTE_PUCCH_N_SEQ+m*SRSLTE_PUCCH_N_SEQ+n] = q->pucch_cfg.beta_pucch + *q->d[0]*cexpf(I*(w_n_oc[N_sf_widx][n_oc%3][m]+q->tmp_arg[n]+alpha*n+S_ns)); } } } diff --git a/srslte/lib/phch/test/pucch_encode_test_mex.c b/srslte/lib/phch/test/pucch_encode_test_mex.c index c9ecb8d0b..96abfcabd 100644 --- a/srslte/lib/phch/test/pucch_encode_test_mex.c +++ b/srslte/lib/phch/test/pucch_encode_test_mex.c @@ -109,6 +109,13 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mxFree(hop); } + pucch_cfg.shortened = false; + uint32_t sh = 0; + mexutils_read_uint32_struct(PUCCHCFG, "Shortened", &sh); + if (sh == 1) { + pucch_cfg.shortened = true; + } + uint8_t bits[SRSLTE_PUCCH_MAX_BITS]; uint8_t pucch2_bits[2]; float *bits_ptr; @@ -167,10 +174,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) } if (nlhs >= 1) { - uint32_t n_bits = 96; - if (format >= SRSLTE_PUCCH_FORMAT_2) { - n_bits = 120; - } + uint32_t n_bits = srslte_pucch_nof_symbols(&pucch_cfg, format); mexutils_write_cf(pucch.z, &plhs[0], n_bits, 1); }