diff --git a/lib/include/srsran/phy/utils/debug.h b/lib/include/srsran/phy/utils/debug.h index 114734a61..33763d33b 100644 --- a/lib/include/srsran/phy/utils/debug.h +++ b/lib/include/srsran/phy/utils/debug.h @@ -24,18 +24,24 @@ #include "phy_logger.h" #include "srsran/config.h" #include +#include + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus #define SRSRAN_VERBOSE_DEBUG 2 #define SRSRAN_VERBOSE_INFO 1 #define SRSRAN_VERBOSE_NONE 0 -#include SRSRAN_API void get_time_interval(struct timeval* tdata); #define SRSRAN_DEBUG_ENABLED 1 SRSRAN_API extern int srsran_verbose; -SRSRAN_API extern int handler_registered; + +SRSRAN_API bool is_handler_registered(void); +SRSRAN_API void set_handler_enabled(bool enable); #define SRSRAN_VERBOSE_ISINFO() (srsran_verbose >= SRSRAN_VERBOSE_INFO) #define SRSRAN_VERBOSE_ISDEBUG() (srsran_verbose >= SRSRAN_VERBOSE_DEBUG) @@ -47,7 +53,7 @@ SRSRAN_API extern int handler_registered; #define DEBUG(_fmt, ...) \ do { \ - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { \ + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { \ fprintf(stdout, "[DEBUG]: " _fmt "\n", ##__VA_ARGS__); \ } else { \ srsran_phy_log_print(LOG_LEVEL_DEBUG_S, _fmt, ##__VA_ARGS__); \ @@ -56,7 +62,7 @@ SRSRAN_API extern int handler_registered; #define INFO(_fmt, ...) \ do { \ - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { \ + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { \ fprintf(stdout, "[INFO]: " _fmt "\n", ##__VA_ARGS__); \ } else { \ srsran_phy_log_print(LOG_LEVEL_INFO_S, _fmt, ##__VA_ARGS__); \ @@ -67,7 +73,7 @@ SRSRAN_API extern int handler_registered; /* In debug mode, it prints out the */ #define ERROR(_fmt, ...) \ do { \ - if (!handler_registered) { \ + if (!is_handler_registered()) { \ fprintf(stderr, "\e[31m%s:%d: " _fmt "\e[0m\n", __FILE__, __LINE__, ##__VA_ARGS__); \ } else { \ srsran_phy_log_print(LOG_LEVEL_ERROR_S, _fmt, ##__VA_ARGS__); \ @@ -75,11 +81,15 @@ SRSRAN_API extern int handler_registered; } while (0) #else #define ERROR(_fmt, ...) \ - if (!handler_registered) { \ + if (!is_handler_registered()) { \ fprintf(stderr, "[ERROR in %s]:" _fmt "\n", __FUNCTION__, ##__VA_ARGS__); \ } else { \ srsran_phy_log_print(LOG_LEVEL_ERROR, _fmt, ##__VA_ARGS__); \ } // #endif /* CMAKE_BUILD_TYPE==Debug */ +#ifdef __cplusplus +} +#endif // __cplusplus + #endif // SRSRAN_DEBUG_H diff --git a/lib/src/phy/ch_estimation/dmrs_pdcch.c b/lib/src/phy/ch_estimation/dmrs_pdcch.c index 0a7ca935c..b08e52a0e 100644 --- a/lib/src/phy/ch_estimation/dmrs_pdcch.c +++ b/lib/src/phy/ch_estimation/dmrs_pdcch.c @@ -440,7 +440,7 @@ int srsran_dmrs_pdcch_get_measure(const srsran_dmrs_pdcch_estimator_t* q, nof_pilots += NOF_PILOTS_X_RB; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DMRS_PDCCH_DEBUG_RX("Measuring PDCCH l=%d; lse=", l); srsran_vec_fprint_c(stdout, tmp, nof_pilots); } diff --git a/lib/src/phy/fec/test/crc_test.c b/lib/src/phy/fec/test/crc_test.c index 9f4416a87..539f00a90 100644 --- a/lib/src/phy/fec/test/crc_test.c +++ b/lib/src/phy/fec/test/crc_test.c @@ -87,7 +87,7 @@ int main(int argc, char** argv) data[i] = rand() % 2; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { INFO("data="); srsran_vec_fprint_b(stdout, data, num_bits); } diff --git a/lib/src/phy/phch/pbch_nr.c b/lib/src/phy/phch/pbch_nr.c index 3b20a0aaa..a457e73ed 100644 --- a/lib/src/phy/phch/pbch_nr.c +++ b/lib/src/phy/phch/pbch_nr.c @@ -222,7 +222,7 @@ pbch_nr_pbch_msg_pack(const srsran_pbch_nr_cfg_t* cfg, const srsran_pbch_msg_nr_ a[G[13]] = 0; // Reserved } - if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { PBCH_NR_DEBUG_TX("Packed PBCH bits: "); srsran_vec_fprint_byte(stdout, a, PBCH_NR_A); } @@ -230,7 +230,7 @@ pbch_nr_pbch_msg_pack(const srsran_pbch_nr_cfg_t* cfg, const srsran_pbch_msg_nr_ static void pbch_nr_pbch_msg_unpack(const srsran_pbch_nr_cfg_t* cfg, const uint8_t a[PBCH_NR_A], srsran_pbch_msg_nr_t* msg) { - if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { PBCH_NR_DEBUG_RX("Packed PBCH bits: "); srsran_vec_fprint_byte(stdout, a, PBCH_NR_A); } @@ -330,7 +330,7 @@ static int pbch_nr_polar_encode(srsran_pbch_nr_t* q, const uint8_t c[PBCH_NR_K], return SRSRAN_ERROR; } - if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { PBCH_NR_DEBUG_TX("Allocated: "); srsran_vec_fprint_byte(stdout, allocated, PBCH_NR_N); } @@ -347,7 +347,7 @@ static int pbch_nr_polar_decode(srsran_pbch_nr_t* q, const int8_t d[PBCH_NR_N], return SRSRAN_ERROR; } - if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { PBCH_NR_DEBUG_RX("Allocated: "); srsran_vec_fprint_byte(stdout, allocated, PBCH_NR_N); } @@ -369,7 +369,7 @@ static int pbch_nr_polar_rm_tx(srsran_pbch_nr_t* q, const uint8_t d[PBCH_NR_N], return SRSRAN_ERROR; } - if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { PBCH_NR_DEBUG_TX("d: "); srsran_vec_fprint_byte(stdout, d, PBCH_NR_N); } @@ -389,7 +389,7 @@ static int pbch_nr_polar_rm_rx(srsran_pbch_nr_t* q, const int8_t llr[PBCH_NR_E], d[i] *= -1; } - if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { PBCH_NR_DEBUG_RX("d: "); srsran_vec_fprint_bs(stdout, d, PBCH_NR_N); } @@ -497,7 +497,7 @@ pbch_nr_mapping(const srsran_pbch_nr_cfg_t* cfg, const cf_t symbols[PBCH_NR_M], ssb_grid[3 * SRSRAN_SSB_BW_SUBC + k] = symbols[count++]; } - // if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + // if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { // PBCH_NR_DEBUG_TX("Symbols: "); // srsran_vec_fprint_c(stdout, symbols, PBCH_NR_M); // } @@ -549,7 +549,7 @@ pbch_nr_demapping(const srsran_pbch_nr_cfg_t* cfg, const cf_t ssb_grid[SRSRAN_SS symbols[count++] = ssb_grid[3 * SRSRAN_SSB_BW_SUBC + k]; } - // if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + // if (srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { // PBCH_NR_DEBUG_RX("Symbols: "); // srsran_vec_fprint_c(stdout, symbols, PBCH_NR_M); // } diff --git a/lib/src/phy/phch/pdcch_nr.c b/lib/src/phy/phch/pdcch_nr.c index 3f0dabd1e..0cf8f0974 100644 --- a/lib/src/phy/phch/pdcch_nr.c +++ b/lib/src/phy/phch/pdcch_nr.c @@ -321,9 +321,9 @@ static int pdcch_nr_cce_to_reg_mapping_non_interleaved(const srsran_coreset_t* const srsran_dci_location_t* dci_location, bool rb_mask[SRSRAN_MAX_PRB_NR]) { - uint32_t nof_cce = 1U << dci_location->L; - uint32_t L = 6; - uint32_t nof_reg_bundle = 6 / L; + uint32_t nof_cce = 1U << dci_location->L; + uint32_t L = 6; + uint32_t nof_reg_bundle = 6 / L; // For each CCE j in the PDCCH transmission for (uint32_t j = dci_location->ncce; j < dci_location->ncce + nof_cce; j++) { @@ -364,8 +364,8 @@ static int pdcch_nr_cce_to_reg_mapping_interleaved(const srsran_coreset_t* return 0; } - uint32_t nof_cce = 1U << dci_location->L; - uint32_t nof_reg_bundle = 6 / L; + uint32_t nof_cce = 1U << dci_location->L; + uint32_t nof_reg_bundle = 6 / L; // For each CCE j in the PDCCH transmission for (uint32_t j = dci_location->ncce; j < dci_location->ncce + nof_cce; j++) { @@ -521,7 +521,7 @@ int srsran_pdcch_nr_encode(srsran_pdcch_nr_t* q, const srsran_dci_msg_nr_t* dci_ srsran_polar_interleaver_run_u8(c, c_prime, q->K, true); // Print c and c_prime (after interleaving) - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { PDCCH_INFO_TX("c="); srsran_vec_fprint_hex(stdout, c, q->K); PDCCH_INFO_TX("c_prime="); @@ -537,7 +537,7 @@ int srsran_pdcch_nr_encode(srsran_pdcch_nr_t* q, const srsran_dci_msg_nr_t* dci_ } // Print d - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { PDCCH_INFO_TX("d="); srsran_vec_fprint_byte(stdout, q->d, q->code.N); } @@ -564,7 +564,7 @@ int srsran_pdcch_nr_encode(srsran_pdcch_nr_t* q, const srsran_dci_msg_nr_t* dci_ q->meas_time_us = (uint32_t)t[0].tv_usec; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { char str[128] = {}; srsran_pdcch_nr_info(q, NULL, str, sizeof(str)); PDCCH_INFO_TX("%s", str); @@ -613,7 +613,7 @@ int srsran_pdcch_nr_decode(srsran_pdcch_nr_t* q, } // Print channel estimates if enabled - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { PDCCH_DEBUG_RX("ce="); srsran_vec_fprint_c(stdout, ce->ce, q->M); } @@ -622,7 +622,7 @@ int srsran_pdcch_nr_decode(srsran_pdcch_nr_t* q, srsran_predecoding_single(q->symbols, ce->ce, q->symbols, NULL, q->M, 1.0f, ce->noise_var); // Print symbols if enabled - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { PDCCH_DEBUG_RX("symbols="); srsran_vec_fprint_c(stdout, q->symbols, q->M); } @@ -653,7 +653,7 @@ int srsran_pdcch_nr_decode(srsran_pdcch_nr_t* q, } // Print d - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { PDCCH_DEBUG_RX("d="); srsran_vec_fprint_bs(stdout, d, q->K); } @@ -676,7 +676,7 @@ int srsran_pdcch_nr_decode(srsran_pdcch_nr_t* q, srsran_polar_interleaver_run_u8(c_prime, c, q->K, false); // Print c - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { PDCCH_INFO_RX("c_prime="); srsran_vec_fprint_hex(stdout, c_prime, q->K); PDCCH_INFO_RX("c="); @@ -697,7 +697,7 @@ int srsran_pdcch_nr_decode(srsran_pdcch_nr_t* q, uint32_t checksum2 = srsran_bit_pack(&ptr, 24); res->crc = checksum1 == checksum2; - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { PDCCH_INFO_RX("CRC={%06x, %06x}; msg=", checksum1, checksum2); srsran_vec_fprint_hex(stdout, c, dci_msg->nof_bits); } @@ -711,7 +711,7 @@ int srsran_pdcch_nr_decode(srsran_pdcch_nr_t* q, q->meas_time_us = (uint32_t)t[0].tv_usec; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { char str[128] = {}; srsran_pdcch_nr_info(q, res, str, sizeof(str)); PDCCH_INFO_RX("%s", str); diff --git a/lib/src/phy/phch/pdsch_nr.c b/lib/src/phy/phch/pdsch_nr.c index 22076a106..3d8ebf3f7 100644 --- a/lib/src/phy/phch/pdsch_nr.c +++ b/lib/src/phy/phch/pdsch_nr.c @@ -321,7 +321,7 @@ static inline int pdsch_nr_encode_codeword(srsran_pdsch_nr_t* q, return SRSRAN_ERROR; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("b="); srsran_vec_fprint_b(stdout, q->b[tb->cw_idx], tb->nof_bits); } @@ -333,7 +333,7 @@ static inline int pdsch_nr_encode_codeword(srsran_pdsch_nr_t* q, // 7.3.1.2 Modulation srsran_mod_modulate(&q->modem_tables[tb->mod], q->b[tb->cw_idx], q->d[tb->cw_idx], tb->nof_bits); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("d="); srsran_vec_fprint_c(stdout, q->d[tb->cw_idx], tb->nof_re); } @@ -437,7 +437,7 @@ static inline int pdsch_nr_decode_codeword(srsran_pdsch_nr_t* q, return SRSRAN_ERROR_OUT_OF_BOUNDS; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("d="); srsran_vec_fprint_c(stdout, q->d[tb->cw_idx], tb->nof_re); } @@ -460,7 +460,7 @@ static inline int pdsch_nr_decode_codeword(srsran_pdsch_nr_t* q, // Descrambling srsran_sequence_apply_c(llr, llr, tb->nof_bits, pdsch_nr_cinit(&q->carrier, cfg, rnti, tb->cw_idx)); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("b="); srsran_vec_fprint_b(stdout, q->b[tb->cw_idx], tb->nof_bits); } @@ -516,7 +516,7 @@ int srsran_pdsch_nr_decode(srsran_pdsch_nr_t* q, return SRSRAN_ERROR; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("ce="); srsran_vec_fprint_c(stdout, channel->ce[0][0], nof_re); DEBUG("x="); diff --git a/lib/src/phy/phch/pucch_nr.c b/lib/src/phy/phch/pucch_nr.c index b8c2005b2..21132238e 100644 --- a/lib/src/phy/phch/pucch_nr.c +++ b/lib/src/phy/phch/pucch_nr.c @@ -643,7 +643,7 @@ static int pucch_nr_format2_decode(srsran_pucch_nr_t* q, } } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { INFO("d="); srsran_vec_fprint_c(stdout, q->d, resource->nof_symbols * resource->nof_prb * (SRSRAN_NRE - 4)); INFO("ce="); diff --git a/lib/src/phy/phch/pusch_nr.c b/lib/src/phy/phch/pusch_nr.c index 775f6c4b0..b839dc0ce 100644 --- a/lib/src/phy/phch/pusch_nr.c +++ b/lib/src/phy/phch/pusch_nr.c @@ -556,7 +556,7 @@ static int pusch_nr_gen_mux_uci(srsran_pusch_nr_t* q, const srsran_uci_cfg_nr_t* } // Print debug information if configured for ity - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { if (m_ulsch_count != 0) { DEBUG("UL-SCH bit positions:"); srsran_vec_fprint_i(stdout, (int*)pos_ulsch, m_ulsch_count); @@ -662,7 +662,7 @@ static inline int pusch_nr_encode_codeword(srsran_pusch_nr_t* q, } } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("b="); srsran_vec_fprint_b(stdout, b, nof_bits); } @@ -688,7 +688,7 @@ static inline int pusch_nr_encode_codeword(srsran_pusch_nr_t* q, // 7.3.1.2 Modulation srsran_mod_modulate(&q->modem_tables[tb->mod], q->b[tb->cw_idx], q->d[tb->cw_idx], nof_bits); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("d="); srsran_vec_fprint_c(stdout, q->d[tb->cw_idx], tb->nof_re); } @@ -794,7 +794,7 @@ static inline int pusch_nr_decode_codeword(srsran_pusch_nr_t* q, return SRSRAN_ERROR_OUT_OF_BOUNDS; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("d="); srsran_vec_fprint_c(stdout, q->d[tb->cw_idx], tb->nof_re); } @@ -842,7 +842,7 @@ static inline int pusch_nr_decode_codeword(srsran_pusch_nr_t* q, // Descrambling srsran_sequence_apply_c(llr, llr, nof_bits, pusch_nr_cinit(&q->carrier, cfg, rnti, tb->cw_idx)); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("b="); srsran_vec_fprint_bs(stdout, llr, nof_bits); } @@ -968,7 +968,7 @@ int srsran_pusch_nr_decode(srsran_pusch_nr_t* q, return SRSRAN_ERROR; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("ce="); srsran_vec_fprint_c(stdout, channel->ce[0][0], nof_re); DEBUG("x="); diff --git a/lib/src/phy/phch/sch_nr.c b/lib/src/phy/phch/sch_nr.c index 003b381cd..05d13a196 100644 --- a/lib/src/phy/phch/sch_nr.c +++ b/lib/src/phy/phch/sch_nr.c @@ -454,7 +454,7 @@ static inline int sch_nr_encode(srsran_sch_nr_t* q, // Calculate TB CRC uint32_t checksum_tb = srsran_crc_checksum_byte(crc_tb, data, tb->tbs); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("tb="); srsran_vec_fprint_byte(stdout, data, tb->tbs / 8); } @@ -489,7 +489,7 @@ static inline int sch_nr_encode(srsran_sch_nr_t* q, srsran_bit_unpack_vector(input_ptr, q->temp_cb, (int)cb_len); } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("cb%d=", r); srsran_vec_fprint_byte(stdout, input_ptr, cb_len / 8); } @@ -510,7 +510,7 @@ static inline int sch_nr_encode(srsran_sch_nr_t* q, // Encode code block srsran_ldpc_encoder_encode(encoder, q->temp_cb, rm_buffer, cfg.Kr); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("encoded="); srsran_vec_fprint_b(stdout, rm_buffer, encoder->liftN - 2 * encoder->ls); } @@ -668,7 +668,7 @@ static int sch_nr_decode(srsran_sch_nr_t* q, SCH_INFO_RX("CB %d/%d iter=%d CRC=%s", r, cfg.C, n_iter_cb, tb->softbuffer.rx->cb_crc[r] ? "OK" : "KO"); // CB Debug trace - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("CB %d/%d:", r, cfg.C); srsran_vec_fprint_hex(stdout, q->temp_cb, cb_len); } @@ -731,7 +731,7 @@ static int sch_nr_decode(srsran_sch_nr_t* q, SCH_INFO_RX("TB: TBS=%d; CRC={%06x, %06x}", tb->tbs, checksum1, checksum2); } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !is_handler_registered()) { DEBUG("Decode: "); srsran_vec_fprint_byte(stdout, res->payload, tb->tbs / 8); } diff --git a/lib/src/phy/phch/uci_nr.c b/lib/src/phy/phch/uci_nr.c index 31638d696..f1115fc4d 100644 --- a/lib/src/phy/phch/uci_nr.c +++ b/lib/src/phy/phch/uci_nr.c @@ -198,7 +198,7 @@ static int uci_nr_pack_ack_sr(const srsran_uci_cfg_nr_t* cfg, const srsran_uci_v srsran_bit_unpack(value->sr, &bits, cfg->o_sr); A += cfg->o_sr; - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_TX("Packed UCI bits: "); srsran_vec_fprint_byte(stdout, sequence, A); } @@ -219,7 +219,7 @@ static int uci_nr_unpack_ack_sr(const srsran_uci_cfg_nr_t* cfg, uint8_t* sequenc value->sr = srsran_bit_pack(&bits, cfg->o_sr); A += cfg->o_sr; - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_RX("Unpacked UCI bits: "); srsran_vec_fprint_byte(stdout, sequence, A); } @@ -248,7 +248,7 @@ static int uci_nr_pack_ack_sr_csi(const srsran_uci_cfg_nr_t* cfg, const srsran_u } A += n; - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_TX("Packed UCI bits: "); srsran_vec_fprint_byte(stdout, sequence, A); } @@ -269,7 +269,7 @@ static int uci_nr_unpack_ack_sr_csi(const srsran_uci_cfg_nr_t* cfg, uint8_t* seq value->sr = srsran_bit_pack(&bits, cfg->o_sr); A += cfg->o_sr; - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_RX("Unpacked UCI bits: "); srsran_vec_fprint_byte(stdout, sequence, A); } @@ -393,7 +393,7 @@ static int uci_nr_encode_1bit(srsran_uci_nr_t* q, const srsran_uci_cfg_nr_t* cfg return SRSRAN_ERROR; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_TX("One bit encoded NR-UCI; o="); srsran_vec_fprint_b(stdout, o, E); } @@ -434,7 +434,7 @@ static int uci_nr_decode_1_bit(srsran_uci_nr_t* q, // Save decoded bit q->bit_sequence[0] = (corr < 0) ? 0 : 1; - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_RX("One bit decoding NR-UCI llr="); srsran_vec_fprint_bs(stdout, llr, E); UCI_NR_INFO_RX("One bit decoding NR-UCI A=%d; E=%d; pwr=%f; corr=%f; norm=%f; thr=%f; %s", @@ -539,7 +539,7 @@ static int uci_nr_encode_2bit(srsran_uci_nr_t* q, const srsran_uci_cfg_nr_t* cfg return SRSRAN_ERROR; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_TX("Two bit encoded NR-UCI; E=%d; o=", E); srsran_vec_fprint_b(stdout, o, E); } @@ -585,7 +585,7 @@ static int uci_nr_decode_2_bit(srsran_uci_nr_t* q, q->bit_sequence[0] = c0 ? 1 : 0; q->bit_sequence[1] = c1 ? 1 : 0; - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_RX("Two bit decoding NR-UCI llr="); srsran_vec_fprint_bs(stdout, llr, E); UCI_NR_INFO_RX("Two bit decoding NR-UCI A=%d; E=%d; Qm=%d; c0=%d; c1=%d; c2=%d %s", @@ -606,7 +606,7 @@ uci_nr_encode_3_11_bit(srsran_uci_nr_t* q, const srsran_uci_cfg_nr_t* cfg, uint3 { srsran_block_encode(q->bit_sequence, A, o, E); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_TX("Block encoded UCI bits; o="); srsran_vec_fprint_b(stdout, o, E); } @@ -649,7 +649,7 @@ static int uci_nr_decode_3_11_bit(srsran_uci_nr_t* q, // Take decoded decision with threshold *decoded_ok = (corr > q->block_code_threshold); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_RX("Block decoding NR-UCI llr="); srsran_vec_fprint_bs(stdout, llr, E); UCI_NR_INFO_RX("Block decoding NR-UCI A=%d; E=%d; pwr=%f; corr=%f; norm=%f; thr=%f; %s", @@ -713,7 +713,7 @@ uci_nr_encode_11_1706_bit(srsran_uci_nr_t* q, const srsran_uci_cfg_nr_t* cfg, ui srsran_crc_attach(crc, q->c, A_prime / C); UCI_NR_INFO_TX("Attaching %d/%d CRC%d=%" PRIx64, r, C, L, srsran_crc_checksum_get(crc)); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_TX("Polar cb %d/%d c=", r, C); srsran_vec_fprint_byte(stdout, q->c, K_r); } @@ -721,7 +721,7 @@ uci_nr_encode_11_1706_bit(srsran_uci_nr_t* q, const srsran_uci_cfg_nr_t* cfg, ui // Allocate channel srsran_polar_chanalloc_tx(q->c, q->allocated, q->code.N, q->code.K, q->code.nPC, q->code.K_set, q->code.PC_set); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_TX("Polar alloc %d/%d ", r, C); srsran_vec_fprint_byte(stdout, q->allocated, q->code.N); } @@ -731,7 +731,7 @@ uci_nr_encode_11_1706_bit(srsran_uci_nr_t* q, const srsran_uci_cfg_nr_t* cfg, ui return SRSRAN_ERROR; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_TX("Polar encoded %d/%d ", r, C); srsran_vec_fprint_byte(stdout, q->d, q->code.N); } @@ -739,7 +739,7 @@ uci_nr_encode_11_1706_bit(srsran_uci_nr_t* q, const srsran_uci_cfg_nr_t* cfg, ui // Rate matching srsran_polar_rm_tx(&q->rm_tx, q->d, &o[E_r * r], q->code.n, E_r, K_r, UCI_NR_POLAR_RM_IBIL); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_TX("Polar RM cw %d/%d ", r, C); srsran_vec_fprint_byte(stdout, &o[E_r * r], E_r); } @@ -790,7 +790,7 @@ static int uci_nr_decode_11_1706_bit(srsran_uci_nr_t* q, for (uint32_t r = 0, s = 0; r < C; r++) { uint32_t k = 0; - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_RX("Polar LLR %d/%d ", r, C); srsran_vec_fprint_bs(stdout, &llr[E_r * r], q->code.N); } @@ -805,7 +805,7 @@ static int uci_nr_decode_11_1706_bit(srsran_uci_nr_t* q, return SRSRAN_ERROR; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_RX("Polar alloc %d/%d ", r, C); srsran_vec_fprint_byte(stdout, q->allocated, q->code.N); } @@ -813,7 +813,7 @@ static int uci_nr_decode_11_1706_bit(srsran_uci_nr_t* q, // Undo channel allocation srsran_polar_chanalloc_rx(q->allocated, q->c, q->code.K, q->code.nPC, q->code.K_set, q->code.PC_set); - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { UCI_NR_INFO_RX("Polar cb %d/%d c=", r, C); srsran_vec_fprint_byte(stdout, q->c, K_r); } diff --git a/lib/src/phy/resampling/resampler.c b/lib/src/phy/resampling/resampler.c index 676eac2f3..2669b507f 100644 --- a/lib/src/phy/resampling/resampler.c +++ b/lib/src/phy/resampling/resampler.c @@ -145,7 +145,7 @@ int srsran_resampler_fft_init(srsran_resampler_fft_t* q, srsran_resampler_mode_t q->in_buffer[i] = (float)h; } - if (srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { printf("h_%s=", q->mode == SRSRAN_RESAMPLER_MODE_INTERPOLATE ? "interp" : "decimate"); srsran_vec_fprint_c(stdout, q->in_buffer, high_size); } diff --git a/lib/src/phy/resampling/test/resampler_test.c b/lib/src/phy/resampling/test/resampler_test.c index df3061ed0..0d65954c3 100644 --- a/lib/src/phy/resampling/test/resampler_test.c +++ b/lib/src/phy/resampling/test/resampler_test.c @@ -129,7 +129,7 @@ int main(int argc, char** argv) break; } - if (srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { printf("signal="); srsran_vec_fprint_c(stdout, src, buffer_size); } @@ -143,7 +143,7 @@ int main(int argc, char** argv) get_time_interval(t); uint64_t duration_us = (uint64_t)(t[0].tv_sec * 1000000UL + t[0].tv_usec); - if (srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { printf("interp="); srsran_vec_fprint_c(stdout, interpolated, buffer_size * factor); printf("decim="); @@ -156,7 +156,7 @@ int main(int argc, char** argv) srsran_vec_sub_ccc(src, &decimated[delay], interpolated, nsamples); float mse = sqrtf(srsran_vec_avg_power_cf(interpolated, nsamples)); - if (srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { printf("recovered="); srsran_vec_fprint_c(stdout, &decimated[delay], nsamples); } diff --git a/lib/src/phy/ue/ue_dl_nr.c b/lib/src/phy/ue/ue_dl_nr.c index fb0a851f7..19551ddd1 100644 --- a/lib/src/phy/ue/ue_dl_nr.c +++ b/lib/src/phy/ue/ue_dl_nr.c @@ -375,7 +375,7 @@ static int ue_dl_nr_find_dci_ss(srsran_ue_dl_nr_t* q, // Calculate possible PDCCH DCI candidates uint32_t candidates[SRSRAN_SEARCH_SPACE_MAX_NOF_CANDIDATES_NR] = {}; int nof_candidates = srsran_pdcch_nr_locations_coreset( - coreset, search_space, rnti, L, SRSRAN_SLOT_NR_MOD(q->carrier.scs, slot_cfg->idx), candidates); + coreset, search_space, rnti, L, SRSRAN_SLOT_NR_MOD(q->carrier.scs, slot_cfg->idx), candidates); if (nof_candidates < SRSRAN_SUCCESS) { ERROR("Error calculating DCI candidate location"); return SRSRAN_ERROR; @@ -567,7 +567,7 @@ int srsran_ue_dl_nr_decode_pdsch(srsran_ue_dl_nr_t* q, return SRSRAN_ERROR; } - if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !handler_registered) { + if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_INFO && !is_handler_registered()) { char str[512]; srsran_ue_dl_nr_pdsch_info(q, cfg, res, str, sizeof(str)); INFO("PDSCH: %s", str); diff --git a/lib/src/phy/utils/debug.c b/lib/src/phy/utils/debug.c index 671c9eecd..6aa886ba5 100644 --- a/lib/src/phy/utils/debug.c +++ b/lib/src/phy/utils/debug.c @@ -13,8 +13,18 @@ #include "srsran/phy/utils/debug.h" #include -int srsran_verbose = 0; -int handler_registered = 0; +int srsran_verbose = 0; +static bool handler_registered = false; + +bool is_handler_registered(void) +{ + return handler_registered; +} + +void set_handler_enabled(bool enable) +{ + handler_registered = enable; +} void get_time_interval(struct timeval* tdata) { diff --git a/lib/src/phy/utils/phy_logger.c b/lib/src/phy/utils/phy_logger.c index 49c668887..2448ca1f2 100644 --- a/lib/src/phy/utils/phy_logger.c +++ b/lib/src/phy/utils/phy_logger.c @@ -29,7 +29,7 @@ void srsran_phy_log_register_handler(void* ctx, phy_log_handler_t handler) { phy_log_handler = handler; callback_ctx = ctx; - handler_registered++; + set_handler_enabled(true); } void srsran_phy_log_print(phy_logger_level_t log_level, const char* format, ...) diff --git a/test/phy/test_bench.h b/test/phy/test_bench.h index bd169475c..86c0718ba 100644 --- a/test/phy/test_bench.h +++ b/test/phy/test_bench.h @@ -111,7 +111,7 @@ public: } // Make sure PHY log is not set by UE or gNb PHY - handler_registered = 0; + set_handler_enabled(false); if (args.phy_lib_log_level == "info") { srsran_verbose = SRSRAN_VERBOSE_INFO; } else if (args.phy_lib_log_level == "debug") {