From 0745ffb8b9687d9be0742fe42b5e267ddaa84931 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Wed, 31 Jan 2024 08:48:48 +0200 Subject: [PATCH 01/13] Add warning when C-style casts are used --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88c14cf53..f72e77a65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ endif() if(CMAKE_COMPILER_IS_GNUCXX) #enable warnings in Debug configurations - add_compile_options(-Wall -Wpedantic) + add_compile_options(-Wall -Wpedantic -Wold-style-cast) #symbols are only exported from libraries/modules explicitly add_compile_options(-fvisibility=hidden) @@ -90,7 +90,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) #disable gcc caller-saves flag for O2-O3 optimizations #workaround fix for gcc 9.3+ if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.3 OR + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 9.9) add_compile_options(-fno-caller-saves) endif() @@ -109,7 +109,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) endif() SET(ENABLE_SIMD_FLAGS "${DEFAULT_SIMD_FLAGS}" CACHE STRING "Set compiler SIMD flags") - SET_PROPERTY(CACHE ENABLE_SIMD_FLAGS PROPERTY STRINGS none native SSE3 SSE4.2 AVX AVX2) + SET_PROPERTY(CACHE ENABLE_SIMD_FLAGS PROPERTY STRINGS none native SSE3 SSE4.2 AVX AVX2) if(${ENABLE_SIMD_FLAGS} MATCHES "native") add_definitions(-march=native) @@ -140,7 +140,7 @@ if (MSVC) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_MULTITHREAD_COMPILE_FLAGS}" ) SET(ENABLE_SIMD_FLAGS "SSE2" CACHE STRING "Set compiler SIMD flags") - SET_PROPERTY(CACHE ENABLE_SIMD_FLAGS PROPERTY STRINGS none SSE2 AVX AVX2) + SET_PROPERTY(CACHE ENABLE_SIMD_FLAGS PROPERTY STRINGS none SSE2 AVX AVX2) if(${ENABLE_SIMD_FLAGS} MATCHES "AVX2") add_definitions(/arch:AVX2) @@ -241,7 +241,7 @@ add_feature_info(LimeSuiteDocAPI ENABLE_API_DOXYGEN "LMS API Doxygen documentati if (ENABLE_API_DOXYGEN) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/doxygen/DoxyfileAPI.in ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY) add_custom_target(docAPI ALL - ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile + ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMENT "Generating LMS API documentation with Doxygen" VERBATIM ) @@ -250,7 +250,7 @@ endif() if(DOXYGEN_FOUND) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/doxygen/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) add_custom_target(doc - ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMENT "Generating documentation with Doxygen" VERBATIM ) From 074f6aae45af04afe8750344ddb3d05cbf10edc1 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Wed, 31 Jan 2024 10:09:48 +0200 Subject: [PATCH 02/13] Use the warning on only C++ files --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f72e77a65..d73b5b534 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,12 +81,15 @@ endif() if(CMAKE_COMPILER_IS_GNUCXX) #enable warnings in Debug configurations - add_compile_options(-Wall -Wpedantic -Wold-style-cast) + add_compile_options(-Wall -Wpedantic) #symbols are only exported from libraries/modules explicitly add_compile_options(-fvisibility=hidden) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden") + # enable C-style cast warnings in C++ + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast") + #disable gcc caller-saves flag for O2-O3 optimizations #workaround fix for gcc 9.3+ if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") From 875dd5ea1a5ccb2ed47ebe95a921a7c4acbe7ef5 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Wed, 31 Jan 2024 11:25:35 +0200 Subject: [PATCH 03/13] Fix all the casting warnings --- amarisoft-plugin/trx_limesuite.cpp | 38 ++-- src/ADF4002/ADF4002.cpp | 64 +++--- src/ADF4002/ADF4002_wxgui.cpp | 4 +- src/CDCM6208/CDCM6208_Dev.cpp | 202 +++++++++--------- src/CDCM6208/CDCM6208_Dev.h | 7 +- src/CDCM6208/CDCM6208_panelgui.cpp | 40 ++-- src/DSP/Equalizer.cpp | 14 +- src/FPGA_common/FPGA_common.cpp | 10 +- src/LMS_Programing/LMS_Programing_wxgui.cpp | 31 ++- src/Si5351C/Si5351C.cpp | 23 +- src/Si5351C/Si5351C_wxgui.cpp | 16 +- src/boards/MMX8/MM_X8Entry.cpp | 2 +- src/boards_wxgui/pnlX3.cpp | 14 +- src/cli/limeTRX.cpp | 7 +- src/comms/PCIe/LitePCIe.cpp | 12 +- src/comms/PCIe/PCIeCommon.cpp | 3 +- src/comms/PCIe/TRXLooper_PCIE.cpp | 32 ++- src/comms/USB/LMS64C_FPGA_Over_USB.cpp | 3 +- src/examples/basicRX.cpp | 2 +- src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp | 2 +- src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp | 63 +++--- src/lms7002_wxgui/lms7002_pnlR3.cpp | 12 +- src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp | 14 +- src/lms7002m/LMS7002M.cpp | 66 +++--- src/lms7002m/LMS7002M_RxTxCalibrations.cpp | 6 +- src/lms7002m/MCU_BD.cpp | 16 +- src/lms7002m/MCU_File.cpp | 14 +- src/lms7suiteAppFrame.cpp | 2 +- .../common_src/lms7002m_calibrations.c | 83 +++---- .../common_src/lms7002m_controls.c | 16 +- src/mcu_program/common_src/lms7002m_filters.c | 47 ++-- src/oglGraph/GLFont.cpp | 124 +++++++---- src/oglGraph/OpenGLGraph.cpp | 24 ++- src/oglGraph/OpenGLGraph.h | 8 +- src/oglGraph/StaticFontHeader.h | 3 +- src/oglGraph/dlgMarkers.cpp | 8 +- src/protocols/BufferInterleaving.cpp | 11 +- src/protocols/LMS64CProtocol.cpp | 8 +- src/utilities/rfTest.cpp | 12 +- 39 files changed, 568 insertions(+), 495 deletions(-) diff --git a/amarisoft-plugin/trx_limesuite.cpp b/amarisoft-plugin/trx_limesuite.cpp index c4fa001a6..fb4a0b644 100644 --- a/amarisoft-plugin/trx_limesuite.cpp +++ b/amarisoft-plugin/trx_limesuite.cpp @@ -152,7 +152,7 @@ static inline int64_t ts_to_time(int64_t fs, int64_t ts) int n, r; n = (ts / fs); r = (ts % fs); - return (int64_t)n * 1000000 + (((int64_t)r * 1000000) / fs); + return static_cast(n) * 1000000 + ((static_cast(r) * 1000000) / fs); } struct PortChPair { @@ -299,7 +299,7 @@ static bool OnStreamStatusChange(bool isTx, const SDRDevice::StreamStats* s, voi static TRXStatistics trxstats; static int trx_lms7002m_get_stats(TRXState* s, TRXStatistics* m) { - LimeState* lime = (LimeState*)s->opaque; + LimeState* lime = static_cast(s->opaque); for (long p = 0; p < lime->deviceCount; ++p) { StreamStatus& stats = portStreamStates[p]; @@ -313,7 +313,7 @@ static int trx_lms7002m_get_stats(TRXState* s, TRXStatistics* m) /* Callback must allocate info buffer that will be displayed */ static void trx_lms7002m_dump_info(TRXState* s, trx_printf_cb cb, void* opaque) { - LimeState* lime = (LimeState*)s->opaque; + LimeState* lime = static_cast(s->opaque); std::stringstream ss; for (long p = 0; p < lime->deviceCount; ++p) { @@ -334,7 +334,7 @@ static void trx_lms7002m_dump_info(TRXState* s, trx_printf_cb cb, void* opaque) // TODO: read FIFO usage } const int len = ss.str().length(); - char* buffer = (char*)malloc(len + 1); + char* buffer = static_cast(malloc(len + 1)); cb(buffer, "%s\n", ss.str().c_str()); } @@ -353,7 +353,7 @@ static void trx_lms7002m_write( meta.flush = (md->flags & TRX_WRITE_MD_FLAG_END_OF_BURST); // samples format conversion is done internally - LimeState* lime = (LimeState*)s->opaque; + LimeState* lime = static_cast(s->opaque); int samplesConsumed = lime->device[port]->StreamTx(lime->chipIndex[port], reinterpret_cast(samples), count, &meta); if (logVerbosity == LogLevel::DEBUG && samplesConsumed != count) @@ -374,7 +374,7 @@ static void trx_lms7002m_write( // return number of samples produced static int trx_lms7002m_read(TRXState* s, trx_timestamp_t* ptimestamp, void** samples, int count, int port, TRXReadMetadata* md) { - LimeState* lime = (LimeState*)s->opaque; + LimeState* lime = static_cast(s->opaque); SDRDevice::StreamMeta meta; meta.useTimestamp = false; @@ -499,7 +499,7 @@ static int trx_lms7002m_get_sample_rate(TRXState* s1, TRXFraction* psample_rate, // !!! sometimes trx_lms7002m_write gets calls with samples count more than returned here static int trx_lms7002m_get_tx_samples_per_packet_func(TRXState* s1) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); int txExpectedSamples = lime->samplesInPacket[0]; if (lime->streamExtras[0] && lime->streamExtras[0]->txSamplesInPacket > 0) { @@ -511,7 +511,7 @@ static int trx_lms7002m_get_tx_samples_per_packet_func(TRXState* s1) static int trx_lms7002m_get_abs_rx_power_func(TRXState* s1, float* presult, int channel_num) { - LimeState* s = (LimeState*)s1->opaque; + LimeState* s = static_cast(s1->opaque); const PortChPair& pair = gMapTxChannelToPortCh[channel_num]; if (s->rxPowerAvailable[pair.port][pair.ch]) { @@ -524,7 +524,7 @@ static int trx_lms7002m_get_abs_rx_power_func(TRXState* s1, float* presult, int static int trx_lms7002m_get_abs_tx_power_func(TRXState* s1, float* presult, int channel_num) { - LimeState* s = (LimeState*)s1->opaque; + LimeState* s = static_cast(s1->opaque); const PortChPair& pair = gMapTxChannelToPortCh[channel_num]; if (s->txPowerAvailable[pair.port][pair.ch]) { @@ -539,9 +539,9 @@ static int trx_lms7002m_get_abs_tx_power_func(TRXState* s1, float* presult, int //max gain ~70-76 (higher will probably degrade signal quality to much) static void trx_lms7002m_set_tx_gain_func(TRXState* s1, double gain, int channel_num) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); int row = gain; - if (row < 0 || row >= (int)(sizeof(txGainTable) / sizeof(TxGainRow))) + if (row < 0 || row >= static_cast(sizeof(txGainTable) / sizeof(TxGainRow))) return; std::lock_guard lk(gainsMutex); @@ -562,9 +562,9 @@ static void trx_lms7002m_set_tx_gain_func(TRXState* s1, double gain, int channel static void trx_lms7002m_set_rx_gain_func(TRXState* s1, double gain, int channel_num) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); int row = gain; - if (row < 0 || row >= (int)(sizeof(rxGainTable) / sizeof(RxGainRow))) + if (row < 0 || row >= static_cast(sizeof(rxGainTable) / sizeof(RxGainRow))) return; std::lock_guard lk(gainsMutex); @@ -585,7 +585,7 @@ static void trx_lms7002m_set_rx_gain_func(TRXState* s1, double gain, int channel static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); try { @@ -600,7 +600,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) lime->tx_channel_count[p] = hostState->tx_port_channel_count[p]; lime->rx_channel_count[p] = hostState->rx_port_channel_count[p]; - const double samplingRate = (float)hostState->sample_rate[p].num / hostState->sample_rate[p].den; + const double samplingRate = static_cast(hostState->sample_rate[p].num) / hostState->sample_rate[p].den; config.channel[0].rx.sampleRate = samplingRate; config.channel[0].tx.sampleRate = samplingRate; config.channel[0].rx.oversample = lime->rxOversample[p]; @@ -651,7 +651,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) } else sprintf(loFreqStr, "LO: %.3f MHz", freq / 1.0e6); - gMapRxChannelToPortCh[rxChannelOffset + ch] = { (uint8_t)p, (uint8_t)ch }; + gMapRxChannelToPortCh[rxChannelOffset + ch] = { static_cast(p), static_cast(ch) }; Log(LogLevel::INFO, "Port[%i] Rx CH[%i] %s, SR: %.3f MHz BW: %.3f MHz | chipIndex: %i, path: %i('%s')\n", p, @@ -698,7 +698,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) } else sprintf(loFreqStr, "LO: %.3f MHz", freq / 1.0e6); - gMapTxChannelToPortCh[txChannelOffset + ch] = { (uint8_t)p, (uint8_t)ch }; + gMapTxChannelToPortCh[txChannelOffset + ch] = { static_cast(p), static_cast(ch) }; Log(LogLevel::INFO, "Port[%i] Tx CH[%i] %s, SR: %.3f MHz BW: %.3f MHz | chipIndex: %i, path: %i('%s')\n", p, @@ -788,7 +788,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) stream.txChannels[ch] = ch; stream.statusCallback = OnStreamStatusChange; - stream.userData = (void*)&portStreamStates[p]; + stream.userData = static_cast(&portStreamStates[p]); stream.hintSampleRate = samplingRate; stream.extraConfig = lime->streamExtras[p] ? lime->streamExtras[p] : nullptr; @@ -828,7 +828,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) static void trx_lms7002m_end(TRXState* s1) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); for (int p = 0; p < lime->deviceCount; ++p) { SDRDevice* portDevice = lime->device[p]; diff --git a/src/ADF4002/ADF4002.cpp b/src/ADF4002/ADF4002.cpp index 8a517a5e1..a4f2fa3fe 100644 --- a/src/ADF4002/ADF4002.cpp +++ b/src/ADF4002/ADF4002.cpp @@ -36,7 +36,7 @@ int ADF4002::UploadConfig() std::vector dataWr; for (int i = 0; i < 12; i += 3) - dataWr.push_back((uint32_t)data[i] << 16 | (uint32_t)data[i + 1] << 8 | data[i + 2]); + dataWr.push_back(static_cast(data[i]) << 16 | static_cast(data[i + 1]) << 8 | data[i + 2]); // ADF4002 needs to be writen 4 values of 24 bits mComms->SPI(dataWr.data(), nullptr, 4); @@ -95,7 +95,7 @@ void ADF4002::MakeData() m_registers[0x00] = 0x00; //R Value LSB itmp = txtRCnt; - btmp = (char)itmp; + btmp = static_cast(itmp); btmp = btmp << 2; m_registers[0x00] |= btmp; //Addr @@ -106,20 +106,20 @@ void ADF4002::MakeData() //======= register addr 0x01 ======= m_registers[0x01] = 0x00; //R Value MSB - btmp = (char)(itmp >> 6); + btmp = static_cast((itmp >> 6)); btmp = btmp << 0; m_registers[0x01] |= btmp; //======= register addr 0x02 ======= m_registers[0x02] = 0x00; //Anti-Backlash - btmp = (char)cmbABW; + btmp = static_cast(cmbABW); if (btmp > 0) btmp++; btmp = btmp << 0; m_registers[0x02] |= btmp; //Lock Detact Precision - btmp = (char)cmbLDP; + btmp = static_cast(cmbLDP); btmp = btmp << 4; m_registers[0x02] |= btmp; @@ -134,7 +134,7 @@ void ADF4002::MakeData() m_registers[0x04] = 0x00; //N Value LSB itmp = txtNCnt; - btmp = (char)itmp; + btmp = static_cast(itmp); btmp = btmp << 0; m_registers[0x04] |= btmp; @@ -142,11 +142,11 @@ void ADF4002::MakeData() m_registers[0x05] = 0x00; //N Value MSB itmp = txtNCnt; - btmp = (char)(itmp >> 8); + btmp = static_cast((itmp >> 8)); btmp = btmp << 0; m_registers[0x05] |= btmp; //CP Gain - btmp = (char)cmbCPG; + btmp = static_cast(cmbCPG); btmp = btmp << 5; m_registers[0x05] |= btmp; @@ -157,55 +157,55 @@ void ADF4002::MakeData() btmp = btmp << 0; m_registers[0x06] |= btmp; //Counter Reset - btmp = (char)rgrCR_f; + btmp = static_cast(rgrCR_f); btmp = btmp << 2; m_registers[0x06] |= btmp; //PD 1 - btmp = (char)rgrPD1_f; + btmp = static_cast(rgrPD1_f); btmp = btmp << 3; m_registers[0x06] |= btmp; //Muxout Control - btmp = (char)cmbMOC_f; + btmp = static_cast(cmbMOC_f); btmp = btmp << 4; m_registers[0x06] |= btmp; //PD Polarity - btmp = (char)rgrPDP_f; + btmp = static_cast(rgrPDP_f); btmp = btmp << 7; m_registers[0x06] |= btmp; //======= register addr 0x07 ======= m_registers[0x07] = 0x00; //CP State - btmp = (char)rgrCPS_f; + btmp = static_cast(rgrCPS_f); btmp = btmp << 0; m_registers[0x07] |= btmp; //Fastlock - btmp = (char)cmbFL_f; + btmp = static_cast(cmbFL_f); if (btmp > 0) btmp++; btmp = btmp << 1; m_registers[0x07] |= btmp; //Timer Counter - btmp = (char)cmbTC_f; + btmp = static_cast(cmbTC_f); btmp = btmp << 3; m_registers[0x07] |= btmp; //Current Setting 1 MSB - btmp = (char)cmbCS1_f; + btmp = static_cast(cmbCS1_f); btmp = btmp << 7; m_registers[0x07] |= btmp; //======= register addr 0x08 ======= m_registers[0x08] = 0x00; //Current Setting 1 LSB - btmp = (char)cmbCS1_f; + btmp = static_cast(cmbCS1_f); btmp = btmp >> 1; m_registers[0x08] |= btmp; //Current Setting 2 - btmp = (char)cmbCS2_f; + btmp = static_cast(cmbCS2_f); btmp = btmp << 2; m_registers[0x08] |= btmp; //PD 2 - btmp = (char)rgrPD2_f; + btmp = static_cast(rgrPD2_f); btmp = btmp << 5; m_registers[0x08] |= btmp; @@ -216,55 +216,55 @@ void ADF4002::MakeData() btmp = btmp << 0; m_registers[0x09] |= btmp; //Counter Reset - btmp = (char)rgrCR_i; + btmp = static_cast(rgrCR_i); btmp = btmp << 2; m_registers[0x09] |= btmp; //PD 1 - btmp = (char)rgrPD1_i; + btmp = static_cast(rgrPD1_i); btmp = btmp << 3; m_registers[0x09] |= btmp; //Muxout Control - btmp = (char)cmbMOC_i; + btmp = static_cast(cmbMOC_i); btmp = btmp << 4; m_registers[0x09] |= btmp; //PD Polarity - btmp = (char)rgrPDP_i; + btmp = static_cast(rgrPDP_i); btmp = btmp << 7; m_registers[0x09] |= btmp; //======= register addr 0x0A ======= m_registers[0x0A] = 0x00; //CP State - btmp = (char)rgrCPS_i; + btmp = static_cast(rgrCPS_i); btmp = btmp << 0; m_registers[0x0A] |= btmp; //Fastlock - btmp = (char)cmbFL_i; + btmp = static_cast(cmbFL_i); if (btmp > 0) btmp++; btmp = btmp << 1; m_registers[0x0A] |= btmp; //Timer Counter - btmp = (char)cmbTC_i; + btmp = static_cast(cmbTC_i); btmp = btmp << 3; m_registers[0x0A] |= btmp; //Current Setting 1 MSB - btmp = (char)cmbCS1_i; + btmp = static_cast(cmbCS1_i); btmp = btmp << 7; m_registers[0x0A] |= btmp; //======= register addr 0x0B ======= m_registers[0x0B] = 0x00; //Current Setting 1 LSB - btmp = (char)cmbCS1_i; + btmp = static_cast(cmbCS1_i); btmp = btmp >> 1; m_registers[0x0B] |= btmp; //Current Setting 2 - btmp = (char)cmbCS2_i; + btmp = static_cast(cmbCS2_i); btmp = btmp << 2; m_registers[0x0B] |= btmp; //PD 2 - btmp = (char)rgrPD2_i; + btmp = static_cast(rgrPD2_i); btmp = btmp << 5; m_registers[0x0B] |= btmp; @@ -311,8 +311,8 @@ void ADF4002::CalculateRN() }; Fcomp = (x + y) / 1000000.0; - int R = (int)((txtFref / Fcomp) + 0.5); - int N = (int)((txtFvco / Fcomp) + 0.5); + int R = std::round(txtFref / Fcomp); + int N = std::round(txtFvco / Fcomp); txtRCnt = R; txtNCnt = N; diff --git a/src/ADF4002/ADF4002_wxgui.cpp b/src/ADF4002/ADF4002_wxgui.cpp index 4dd2078f7..853a60aff 100644 --- a/src/ADF4002/ADF4002_wxgui.cpp +++ b/src/ADF4002/ADF4002_wxgui.cpp @@ -509,8 +509,8 @@ ADF4002_wxgui::ADF4002_wxgui(wxWindow* parent, wxWindowID id, const wxPoint& pos FlexGridSizer1->Fit(this); FlexGridSizer1->SetSizeHints(this); - Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ADF4002_wxgui::OnbtnCalcSendClick); - Connect(ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ADF4002_wxgui::OnbtnUploadClick); + Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&ADF4002_wxgui::OnbtnCalcSendClick)); + Connect(ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&ADF4002_wxgui::OnbtnUploadClick)); //*) } diff --git a/src/CDCM6208/CDCM6208_Dev.cpp b/src/CDCM6208/CDCM6208_Dev.cpp index f67db8c25..d29cdaf38 100644 --- a/src/CDCM6208/CDCM6208_Dev.cpp +++ b/src/CDCM6208/CDCM6208_Dev.cpp @@ -60,25 +60,27 @@ int CDCM_Dev::Reset(double primaryFreq, double secondaryFreq) uint16_t addr; uint16_t val; }; - std::map CDCM_Regs = { { 1, { (uint16_t)(SPI_BASE_ADDR + 1), 0x0000 } }, - { 2, { (uint16_t)(SPI_BASE_ADDR + 2), 0x0018 } }, - { 3, { (uint16_t)(SPI_BASE_ADDR + 3), 0x00F0 } }, - { 4, { (uint16_t)(SPI_BASE_ADDR + 4), 0x20FF } }, - { 6, { (uint16_t)(SPI_BASE_ADDR + 6), 0x0018 } }, - { 8, { (uint16_t)(SPI_BASE_ADDR + 8), 0x0018 } }, - { 9, { (uint16_t)(SPI_BASE_ADDR + 9), 0x0003 } }, - { 10, { (uint16_t)(SPI_BASE_ADDR + 10), 0x0180 } }, - { 11, { (uint16_t)(SPI_BASE_ADDR + 11), 0x0000 } }, - { 12, { (uint16_t)(SPI_BASE_ADDR + 12), 0x0003 } }, - { 13, { (uint16_t)(SPI_BASE_ADDR + 13), 0x0180 } }, - { 14, { (uint16_t)(SPI_BASE_ADDR + 14), 0x0000 } }, - { 15, { (uint16_t)(SPI_BASE_ADDR + 15), 0x0003 } }, - { 16, { (uint16_t)(SPI_BASE_ADDR + 16), 0x0180 } }, - { 17, { (uint16_t)(SPI_BASE_ADDR + 17), 0x0000 } }, - { 18, { (uint16_t)(SPI_BASE_ADDR + 18), 0x0003 } }, - { 19, { (uint16_t)(SPI_BASE_ADDR + 19), 0x0180 } }, - { 20, { (uint16_t)(SPI_BASE_ADDR + 20), 0x0000 } }, - { 23, { (uint16_t)(SPI_BASE_ADDR + 23), 0x010A } } }; + std::map CDCM_Regs = { + { 1, { static_cast(SPI_BASE_ADDR + 1), 0x0000 } }, + { 2, { static_cast(SPI_BASE_ADDR + 2), 0x0018 } }, + { 3, { static_cast(SPI_BASE_ADDR + 3), 0x00F0 } }, + { 4, { static_cast(SPI_BASE_ADDR + 4), 0x20FF } }, + { 6, { static_cast(SPI_BASE_ADDR + 6), 0x0018 } }, + { 8, { static_cast(SPI_BASE_ADDR + 8), 0x0018 } }, + { 9, { static_cast(SPI_BASE_ADDR + 9), 0x0003 } }, + { 10, { static_cast(SPI_BASE_ADDR + 10), 0x0180 } }, + { 11, { static_cast(SPI_BASE_ADDR + 11), 0x0000 } }, + { 12, { static_cast(SPI_BASE_ADDR + 12), 0x0003 } }, + { 13, { static_cast(SPI_BASE_ADDR + 13), 0x0180 } }, + { 14, { static_cast(SPI_BASE_ADDR + 14), 0x0000 } }, + { 15, { static_cast(SPI_BASE_ADDR + 15), 0x0003 } }, + { 16, { static_cast(SPI_BASE_ADDR + 16), 0x0180 } }, + { 17, { static_cast(SPI_BASE_ADDR + 17), 0x0000 } }, + { 18, { static_cast(SPI_BASE_ADDR + 18), 0x0003 } }, + { 19, { static_cast(SPI_BASE_ADDR + 19), 0x0180 } }, + { 20, { static_cast(SPI_BASE_ADDR + 20), 0x0000 } }, + { 23, { static_cast(SPI_BASE_ADDR + 23), 0x010A } }, + }; for (auto reg : CDCM_Regs) if (WriteRegister(reg.second.addr, reg.second.val) != 0) @@ -233,14 +235,14 @@ int CDCM_Dev::SetFrequency(cdcm_output_t output, double frequency, bool upload) } if (Outputs.Y0Y1.used) - Outputs.Y0Y1.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.requested_freq); + Outputs.Y0Y1.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.requested_freq); else - Outputs.Y0Y1.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.output_freq); + Outputs.Y0Y1.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.output_freq); if (Outputs.Y2Y3.used) - Outputs.Y2Y3.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.requested_freq); + Outputs.Y2Y3.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.requested_freq); else - Outputs.Y2Y3.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.output_freq); + Outputs.Y2Y3.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.output_freq); if (Outputs.Y4.used) Outputs.Y4.divider_val = (VCO.output_freq / VCO.prescaler_A) / Outputs.Y4.requested_freq; @@ -303,14 +305,14 @@ int CDCM_Dev::RecalculateFrequencies() } if (Outputs.Y0Y1.used) - Outputs.Y0Y1.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.requested_freq); + Outputs.Y0Y1.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.requested_freq); else - Outputs.Y0Y1.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.output_freq); + Outputs.Y0Y1.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.output_freq); if (Outputs.Y2Y3.used) - Outputs.Y2Y3.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.requested_freq); + Outputs.Y2Y3.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.requested_freq); else - Outputs.Y2Y3.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.output_freq); + Outputs.Y2Y3.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.output_freq); if (Outputs.Y4.used) Outputs.Y4.divider_val = (VCO.output_freq / VCO.prescaler_A) / Outputs.Y4.requested_freq; @@ -458,24 +460,26 @@ int CDCM_Dev::UploadConfiguration() uint16_t val; }; - std::map CDCM_Regs = { { 1, { (uint16_t)(SPI_BASE_ADDR + 1), 0 } }, - { 2, { (uint16_t)(SPI_BASE_ADDR + 2), 0 } }, - { 3, { (uint16_t)(SPI_BASE_ADDR + 3), 0 } }, - { 4, { (uint16_t)(SPI_BASE_ADDR + 4), 0 } }, - { 6, { (uint16_t)(SPI_BASE_ADDR + 6), 0 } }, - { 8, { (uint16_t)(SPI_BASE_ADDR + 8), 0 } }, - { 9, { (uint16_t)(SPI_BASE_ADDR + 9), 0 } }, - { 10, { (uint16_t)(SPI_BASE_ADDR + 10), 0 } }, - { 11, { (uint16_t)(SPI_BASE_ADDR + 11), 0 } }, - { 12, { (uint16_t)(SPI_BASE_ADDR + 12), 0 } }, - { 13, { (uint16_t)(SPI_BASE_ADDR + 13), 0 } }, - { 14, { (uint16_t)(SPI_BASE_ADDR + 14), 0 } }, - { 15, { (uint16_t)(SPI_BASE_ADDR + 15), 0 } }, - { 16, { (uint16_t)(SPI_BASE_ADDR + 16), 0 } }, - { 17, { (uint16_t)(SPI_BASE_ADDR + 17), 0 } }, - { 18, { (uint16_t)(SPI_BASE_ADDR + 18), 0 } }, - { 19, { (uint16_t)(SPI_BASE_ADDR + 19), 0 } }, - { 20, { (uint16_t)(SPI_BASE_ADDR + 20), 0 } } }; + std::map CDCM_Regs = { + { 1, { static_cast(SPI_BASE_ADDR + 1), 0 } }, + { 2, { static_cast(SPI_BASE_ADDR + 2), 0 } }, + { 3, { static_cast(SPI_BASE_ADDR + 3), 0 } }, + { 4, { static_cast(SPI_BASE_ADDR + 4), 0 } }, + { 6, { static_cast(SPI_BASE_ADDR + 6), 0 } }, + { 8, { static_cast(SPI_BASE_ADDR + 8), 0 } }, + { 9, { static_cast(SPI_BASE_ADDR + 9), 0 } }, + { 10, { static_cast(SPI_BASE_ADDR + 10), 0 } }, + { 11, { static_cast(SPI_BASE_ADDR + 11), 0 } }, + { 12, { static_cast(SPI_BASE_ADDR + 12), 0 } }, + { 13, { static_cast(SPI_BASE_ADDR + 13), 0 } }, + { 14, { static_cast(SPI_BASE_ADDR + 14), 0 } }, + { 15, { static_cast(SPI_BASE_ADDR + 15), 0 } }, + { 16, { static_cast(SPI_BASE_ADDR + 16), 0 } }, + { 17, { static_cast(SPI_BASE_ADDR + 17), 0 } }, + { 18, { static_cast(SPI_BASE_ADDR + 18), 0 } }, + { 19, { static_cast(SPI_BASE_ADDR + 19), 0 } }, + { 20, { static_cast(SPI_BASE_ADDR + 20), 0 } }, + }; for (int i = 3; i < 24; i += 3) { @@ -497,12 +501,12 @@ int CDCM_Dev::UploadConfiguration() CDCM_Regs[4].val |= ((VCO.R_div - 1) & 0xF) << 8; CDCM_Regs[4].val |= ((VCO.input_mux - 1) & 1) << 12; - CDCM_Regs[6].val = 0 | ((uint16_t)(Outputs.Y0Y1.divider_val - 1) & 0xFF); + CDCM_Regs[6].val = 0 | (static_cast(Outputs.Y0Y1.divider_val - 1) & 0xFF); - CDCM_Regs[8].val = 0 | ((uint16_t)(Outputs.Y2Y3.divider_val - 1) & 0xFF); + CDCM_Regs[8].val = 0 | (static_cast(Outputs.Y2Y3.divider_val - 1) & 0xFF); CDCM_Regs[9].val &= ~0x1E00; - CDCM_Regs[9].val |= (((int)Outputs.Y4.isFrac) << 9); + CDCM_Regs[9].val |= (static_cast(Outputs.Y4.isFrac)) << 9; CDCM_Regs[9].val |= ((Outputs.Y4.prescaler - 2) & 7) << 10; CDCM_Regs[10].val = 0 | (((Outputs.Y4.integer_part - 1) & 0xFF) << 4); @@ -511,7 +515,7 @@ int CDCM_Dev::UploadConfiguration() CDCM_Regs[11].val = Outputs.Y4.fractional_part & 0xFFFF; CDCM_Regs[12].val &= ~0x1E00; - CDCM_Regs[12].val |= (((int)Outputs.Y5.isFrac) << 9); + CDCM_Regs[12].val |= (static_cast(Outputs.Y5.isFrac)) << 9; CDCM_Regs[12].val |= ((Outputs.Y5.prescaler - 2) & 7) << 10; CDCM_Regs[13].val = 0 | (((Outputs.Y5.integer_part - 1) & 0xFF) << 4); @@ -520,7 +524,7 @@ int CDCM_Dev::UploadConfiguration() CDCM_Regs[14].val = Outputs.Y5.fractional_part & 0xFFFF; CDCM_Regs[15].val &= ~0x1E00; - CDCM_Regs[15].val |= (((int)Outputs.Y6.isFrac) << 9); + CDCM_Regs[15].val |= (static_cast(Outputs.Y6.isFrac)) << 9; CDCM_Regs[15].val |= ((Outputs.Y6.prescaler - 2) & 7) << 10; CDCM_Regs[16].val = 0 | (((Outputs.Y6.integer_part - 1) & 0xFF) << 4); @@ -529,7 +533,7 @@ int CDCM_Dev::UploadConfiguration() CDCM_Regs[17].val = Outputs.Y6.fractional_part & 0xFFFF; CDCM_Regs[18].val &= ~0x1E00; - CDCM_Regs[18].val |= (((int)Outputs.Y7.isFrac) << 9); + CDCM_Regs[18].val |= (static_cast(Outputs.Y7.isFrac)) << 9; CDCM_Regs[18].val |= ((Outputs.Y7.prescaler - 2) & 7) << 10; CDCM_Regs[19].val = 0 | (((Outputs.Y7.integer_part - 1) & 0xFF) << 4); @@ -569,26 +573,28 @@ int CDCM_Dev::DownloadConfiguration() uint16_t val; }; - std::map CDCM_Regs = { { 1, { (uint16_t)(SPI_BASE_ADDR + 1), 0 } }, - { 2, { (uint16_t)(SPI_BASE_ADDR + 2), 0 } }, - { 3, { (uint16_t)(SPI_BASE_ADDR + 3), 0 } }, - { 4, { (uint16_t)(SPI_BASE_ADDR + 4), 0 } }, - { 6, { (uint16_t)(SPI_BASE_ADDR + 6), 0 } }, - { 8, { (uint16_t)(SPI_BASE_ADDR + 8), 0 } }, - { 9, { (uint16_t)(SPI_BASE_ADDR + 9), 0 } }, - { 10, { (uint16_t)(SPI_BASE_ADDR + 10), 0 } }, - { 11, { (uint16_t)(SPI_BASE_ADDR + 11), 0 } }, - { 12, { (uint16_t)(SPI_BASE_ADDR + 12), 0 } }, - { 13, { (uint16_t)(SPI_BASE_ADDR + 13), 0 } }, - { 14, { (uint16_t)(SPI_BASE_ADDR + 14), 0 } }, - { 15, { (uint16_t)(SPI_BASE_ADDR + 15), 0 } }, - { 16, { (uint16_t)(SPI_BASE_ADDR + 16), 0 } }, - { 17, { (uint16_t)(SPI_BASE_ADDR + 17), 0 } }, - { 18, { (uint16_t)(SPI_BASE_ADDR + 18), 0 } }, - { 19, { (uint16_t)(SPI_BASE_ADDR + 19), 0 } }, - { 20, { (uint16_t)(SPI_BASE_ADDR + 20), 0 } }, - { 22, { (uint16_t)(SPI_BASE_ADDR + 22), 0 } }, - { 23, { (uint16_t)(SPI_BASE_ADDR + 23), 0 } } }; + std::map CDCM_Regs = { + { 1, { static_cast(SPI_BASE_ADDR + 1), 0 } }, + { 2, { static_cast(SPI_BASE_ADDR + 2), 0 } }, + { 3, { static_cast(SPI_BASE_ADDR + 3), 0 } }, + { 4, { static_cast(SPI_BASE_ADDR + 4), 0 } }, + { 6, { static_cast(SPI_BASE_ADDR + 6), 0 } }, + { 8, { static_cast(SPI_BASE_ADDR + 8), 0 } }, + { 9, { static_cast(SPI_BASE_ADDR + 9), 0 } }, + { 10, { static_cast(SPI_BASE_ADDR + 10), 0 } }, + { 11, { static_cast(SPI_BASE_ADDR + 11), 0 } }, + { 12, { static_cast(SPI_BASE_ADDR + 12), 0 } }, + { 13, { static_cast(SPI_BASE_ADDR + 13), 0 } }, + { 14, { static_cast(SPI_BASE_ADDR + 14), 0 } }, + { 15, { static_cast(SPI_BASE_ADDR + 15), 0 } }, + { 16, { static_cast(SPI_BASE_ADDR + 16), 0 } }, + { 17, { static_cast(SPI_BASE_ADDR + 17), 0 } }, + { 18, { static_cast(SPI_BASE_ADDR + 18), 0 } }, + { 19, { static_cast(SPI_BASE_ADDR + 19), 0 } }, + { 20, { static_cast(SPI_BASE_ADDR + 20), 0 } }, + { 22, { static_cast(SPI_BASE_ADDR + 22), 0 } }, + { 23, { static_cast(SPI_BASE_ADDR + 23), 0 } }, + }; if (PrepareToReadRegs() != 0) return -1; @@ -620,28 +626,28 @@ int CDCM_Dev::DownloadConfiguration() Outputs.Y0Y1.divider_val = (CDCM_Regs[6].val & 0xFF) + 1; Outputs.Y2Y3.divider_val = (CDCM_Regs[8].val & 0xFF) + 1; - Outputs.Y4.isFrac = (bool)((CDCM_Regs[9].val >> 9) & 1); + Outputs.Y4.isFrac = static_cast((CDCM_Regs[9].val >> 9) & 1); Outputs.Y4.prescaler = ((CDCM_Regs[9].val >> 10) & 7) + 2; Outputs.Y4.integer_part = ((CDCM_Regs[10].val >> 4) & 0xFF) + 1; Outputs.Y4.fractional_part = 0 | ((CDCM_Regs[10].val & 0xF) << 16); Outputs.Y4.fractional_part |= CDCM_Regs[11].val; CalculateFracDiv(&Outputs.Y4); - Outputs.Y5.isFrac = (bool)((CDCM_Regs[12].val >> 9) & 1); + Outputs.Y5.isFrac = static_cast((CDCM_Regs[12].val >> 9) & 1); Outputs.Y5.prescaler = ((CDCM_Regs[12].val >> 10) & 7) + 2; Outputs.Y5.integer_part = ((CDCM_Regs[13].val >> 4) & 0xFF) + 1; Outputs.Y5.fractional_part = 0 | ((CDCM_Regs[13].val & 0xF) << 16); Outputs.Y5.fractional_part |= CDCM_Regs[14].val; CalculateFracDiv(&Outputs.Y5); - Outputs.Y6.isFrac = (bool)((CDCM_Regs[15].val >> 9) & 1); + Outputs.Y6.isFrac = static_cast((CDCM_Regs[15].val >> 9) & 1); Outputs.Y6.prescaler = ((CDCM_Regs[15].val >> 10) & 7) + 2; Outputs.Y6.integer_part = ((CDCM_Regs[16].val >> 4) & 0xFF) + 1; Outputs.Y6.fractional_part = 0 | ((CDCM_Regs[16].val & 0xF) << 16); Outputs.Y6.fractional_part |= CDCM_Regs[17].val; CalculateFracDiv(&Outputs.Y6); - Outputs.Y7.isFrac = (bool)((CDCM_Regs[18].val >> 9) & 1); + Outputs.Y7.isFrac = static_cast((CDCM_Regs[18].val >> 9) & 1); Outputs.Y7.prescaler = ((CDCM_Regs[18].val >> 10) & 7) + 2; Outputs.Y7.integer_part = ((CDCM_Regs[19].val >> 4) & 0xFF) + 1; Outputs.Y7.fractional_part = 0 | ((CDCM_Regs[19].val & 0xF) << 16); @@ -657,7 +663,7 @@ int CDCM_Dev::DownloadConfiguration() return 0; } -/** +/** @brief Finds fractional dividers integer and fractional parts values. @param target The requested fractional divider target. @param[out] Output Output to which fractional divider the value is found. @@ -673,7 +679,7 @@ double CDCM_Dev::SolveFracDiv(double target, CDCM_Output* Output) // 1 0000 0000 1111 1111 1111 1111 1111 // \ int / \ fractional / - double max_fractional_val = (((1 << 28) + ((1 << 20) - 1)) / (double)(1 << 20)) * 3; + double max_fractional_val = (((1 << 28) + ((1 << 20) - 1)) / static_cast(1 << 20)) * 3; double result = target; // Check bounds @@ -693,13 +699,13 @@ double CDCM_Dev::SolveFracDiv(double target, CDCM_Output* Output) div3_result = result / 3; // Cast float into 8.20 fixed point integer - div2_fixed = (int)(div2_result * ((1 << 20) & ((1 << 28) - 1))); + div2_fixed = static_cast(div2_result * ((1 << 20) & ((1 << 28) - 1))); // Recast back - div2_result = (float)div2_fixed / (1 << 20); + div2_result = static_cast(div2_fixed) / (1 << 20); // Cast float into 8.20 fixed point integer - div3_fixed = (int)(div3_result * ((1 << 20) & ((1 << 28) - 1))); + div3_fixed = static_cast(div3_result * ((1 << 20) & ((1 << 28) - 1))); // Recast back - div3_result = (float)div3_fixed / (1 << 20); + div3_result = static_cast(div3_fixed) / (1 << 20); // Find best match double div2_difference = abs(result - (div2_result * 2.0)); double div3_difference = abs(result - (div3_result * 3.0)); @@ -721,7 +727,7 @@ double CDCM_Dev::SolveFracDiv(double target, CDCM_Output* Output) return result; } -/** +/** @brief Finds 8-bit and 10-bit multiplier values. @param Target The requested fractional divider target. @param[out] Mult8bit 8-bit multiplier value. @@ -740,7 +746,7 @@ int CDCM_Dev::SolveN(int Target, int* Mult8bit, int* Mult10bit) // Check if res is integer if (IsInteger(res)) { - *Mult8bit = (int)res; + *Mult8bit = static_cast(res); *Mult10bit = i10; return 0; } @@ -749,7 +755,7 @@ int CDCM_Dev::SolveN(int Target, int* Mult8bit, int* Mult10bit) return -1; } -/** +/** @brief Calculates full divider value based on integer and fractional parts. @param[in] Output CDCM Output. */ @@ -768,7 +774,7 @@ void CDCM_Dev::CalculateFracDiv(CDCM_Output* Output) } } -/** +/** @brief Calculates CDCM output frequencies based on current VCO configuration. */ void CDCM_Dev::UpdateOutputFrequencies() @@ -788,7 +794,7 @@ void CDCM_Dev::UpdateOutputFrequencies() Outputs.Y7.output_freq = (VCO.output_freq / VCO.prescaler_B) / Outputs.Y7.divider_val; } -/** +/** @brief Prepare to read the FPGA registers. @return 0 on success; -1 on failure. */ @@ -813,7 +819,7 @@ int CDCM_Dev::PrepareToReadRegs() return 0; } -/** +/** @brief Calculates numerator and denumenator values from decimal. @param decimal Decimal value. @param[out] num Numerator value. @@ -834,7 +840,7 @@ double CDCM_Dev::DecToFrac(double decimal, int* num, int* den) l_den *= 10; decimal *= 10; } - l_num = (uint64_t)decimal; + l_num = static_cast(decimal); uint64_t gcd = FindGCD(l_num, l_den); l_num /= gcd; @@ -869,13 +875,13 @@ double CDCM_Dev::DecToFrac(double decimal, int* num, int* den) l_num = l_num >> 1; } // Return values - *num = (int)l_num; - *den = (int)l_den; - double result_freq = *num / (double)*den; + *num = static_cast(l_num); + *den = static_cast(l_den); + double result_freq = *num / static_cast(*den); return (fabs(1 - (l_target / result_freq))); } -/** +/** @brief Find all available VCO configurations based on @p lcm value. @param lcm The least common multiple value. @param version VCO version. @@ -912,7 +918,7 @@ std::vector CDCM_Dev::FindValidVCOFreqs(double lcm, int version) return Config_vector; } -/** +/** @brief Euclidean method to find greatest common divisor between two integers. @param a First integer. @param b Second integer. @@ -925,7 +931,7 @@ uint64_t CDCM_Dev::FindGCD(uint64_t a, uint64_t b) return FindGCD(b, a % b); } -/** +/** @brief Finds the index of VCO input vector which has lowest Prescaler A value. @param input Vector of VCO configurations. @return Index of lowest input. @@ -947,7 +953,7 @@ int CDCM_Dev::FindLowestPSAOutput(std::vector input) return index; } -/** +/** @brief Finds the index of VCO input vector which has lowest frequency error. @param input Vector of VCO configurations. @return Index of lowest input. @@ -967,7 +973,7 @@ int CDCM_Dev::GetLowestFreqErr(std::vector input) return index; } -/** +/** @brief Finds best VCO configuration index. @param input Vector of VCO configurations. @param num_errors How many errors there are in all configurations. @@ -997,7 +1003,7 @@ int CDCM_Dev::FindBestVCOConfigIndex(std::vector& input, int num_error } } -/** +/** @brief Finds VCO configuration based on requested output frequencies. @return VCO configuration. */ @@ -1019,7 +1025,7 @@ CDCM_VCO CDCM_Dev::FindVCOConfig() bool do_vco_calc = true; if (Outputs.Y0Y1.used && Outputs.Y2Y3.used) - int_lcm = (l_Y0Y1 * l_Y2Y3) / FindGCD((uint64_t)l_Y0Y1, (uint64_t)l_Y2Y3); + int_lcm = (l_Y0Y1 * l_Y2Y3) / FindGCD(static_cast(l_Y0Y1), static_cast(l_Y2Y3)); else if (Outputs.Y0Y1.used) int_lcm = l_Y0Y1; else if (Outputs.Y2Y3.used) diff --git a/src/CDCM6208/CDCM6208_Dev.h b/src/CDCM6208/CDCM6208_Dev.h index a4078d4ec..7ebe68f84 100644 --- a/src/CDCM6208/CDCM6208_Dev.h +++ b/src/CDCM6208/CDCM6208_Dev.h @@ -3,6 +3,9 @@ #include "limesuite/config.h" #include "FPGA_common.h" +#include +#include + #define CDCM_VCO_MIN_V1 2390 * 1e6 #define CDCM_VCO_MAX_V1 2550 * 1e6 #define CDCM_VCO_MIN_V2 2940 * 1e6 @@ -135,11 +138,11 @@ class LIME_API CDCM_Dev double DecToFrac(double target, int* num, int* den); /** - @brief Checks if the given double is an integer. + @brief Checks if the given double is an integer. @param var The double to check. @return Whether the double is an integer or not. */ - bool IsInteger(double var) { return var == (int64_t)var; } + bool IsInteger(double var) { return var == static_cast(var); } std::vector FindValidVCOFreqs(double lcm, int version); uint64_t FindGCD(uint64_t a, uint64_t b); int GetLowestFreqErr(std::vector input); diff --git a/src/CDCM6208/CDCM6208_panelgui.cpp b/src/CDCM6208/CDCM6208_panelgui.cpp index d8f094be4..e1cc9b9da 100644 --- a/src/CDCM6208/CDCM6208_panelgui.cpp +++ b/src/CDCM6208/CDCM6208_panelgui.cpp @@ -914,18 +914,18 @@ void CDCM6208_panelgui::OnFreqEntry(wxCommandEvent& event) int return_val = -1; CDCM_Outputs Outputs = CDCM->GetOutputs(); - if ((bool)m_Y0Y1_chk->GetValue()) - Outputs.Y0Y1.requested_freq = std::stod((std::string)m_Y0Y1_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y2Y3_chk->GetValue()) - Outputs.Y2Y3.requested_freq = std::stod((std::string)m_Y2Y3_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y4_chk->GetValue()) - Outputs.Y4.requested_freq = std::stod((std::string)m_Y4_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y5_chk->GetValue()) - Outputs.Y5.requested_freq = std::stod((std::string)m_Y5_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y6_chk->GetValue()) - Outputs.Y6.requested_freq = std::stod((std::string)m_Y6_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y7_chk->GetValue()) - Outputs.Y7.requested_freq = std::stod((std::string)m_Y7_FREQ_req->GetValue()) * 1e6; + if (static_cast(m_Y0Y1_chk->GetValue())) + Outputs.Y0Y1.requested_freq = std::stod(std::string{ m_Y0Y1_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y2Y3_chk->GetValue())) + Outputs.Y2Y3.requested_freq = std::stod(std::string{ m_Y2Y3_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y4_chk->GetValue())) + Outputs.Y4.requested_freq = std::stod(std::string{ m_Y4_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y5_chk->GetValue())) + Outputs.Y5.requested_freq = std::stod(std::string{ m_Y5_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y6_chk->GetValue())) + Outputs.Y6.requested_freq = std::stod(std::string{ m_Y6_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y7_chk->GetValue())) + Outputs.Y7.requested_freq = std::stod(std::string{ m_Y7_FREQ_req->GetValue() }) * 1e6; CDCM->SetOutputs(Outputs); return_val = CDCM->RecalculateFrequencies(); @@ -953,12 +953,12 @@ void CDCM6208_panelgui::onFP_chk(wxCommandEvent& event) { CDCM_Outputs Outputs = CDCM->GetOutputs(); - Outputs.Y0Y1.used = (bool)m_Y0Y1_chk->GetValue(); - Outputs.Y2Y3.used = (bool)m_Y2Y3_chk->GetValue(); - Outputs.Y4.used = (bool)m_Y4_chk->GetValue(); - Outputs.Y5.used = (bool)m_Y5_chk->GetValue(); - Outputs.Y6.used = (bool)m_Y6_chk->GetValue(); - Outputs.Y7.used = (bool)m_Y7_chk->GetValue(); + Outputs.Y0Y1.used = static_cast(m_Y0Y1_chk->GetValue()); + Outputs.Y2Y3.used = static_cast(m_Y2Y3_chk->GetValue()); + Outputs.Y4.used = static_cast(m_Y4_chk->GetValue()); + Outputs.Y5.used = static_cast(m_Y5_chk->GetValue()); + Outputs.Y6.used = static_cast(m_Y6_chk->GetValue()); + Outputs.Y7.used = static_cast(m_Y7_chk->GetValue()); CDCM->SetOutputs(Outputs); CDCM->UpdateOutputFrequencies(); @@ -1033,7 +1033,7 @@ void CDCM6208_panelgui::UpdateGUI() m_VCOFREQ->SetForegroundColour(wxColour("#000000")); //Y0Y1 divider - str = std::to_string((int)Outputs.Y0Y1.divider_val); + str = std::to_string(static_cast(Outputs.Y0Y1.divider_val)); m_Y0Y1_DIV->SetValue(str); //Y0Y1 Frequency str = std::to_string(Outputs.Y0Y1.output_freq / 1e6); @@ -1043,7 +1043,7 @@ void CDCM6208_panelgui::UpdateGUI() m_Y0Y1_FREQ_req->SetValue(str); //Y2Y3 divider - str = std::to_string((int)Outputs.Y2Y3.divider_val); + str = std::to_string(static_cast(Outputs.Y2Y3.divider_val)); m_Y2Y3_DIV->SetValue(str); //Y2Y3 Frequency str = std::to_string(Outputs.Y2Y3.output_freq / 1e6); diff --git a/src/DSP/Equalizer.cpp b/src/DSP/Equalizer.cpp index 30595c4d0..0c0c682b0 100644 --- a/src/DSP/Equalizer.cpp +++ b/src/DSP/Equalizer.cpp @@ -146,7 +146,7 @@ void Equalizer::UpdateHannCoeff(uint16_t Filt_N) Filt_N = std::min(Filt_N, MaxFilt_N); for (i = 0; i < Filt_N; ++i) - w[i] = (uint16_t)(32768.0 * 0.25 * (1.0 - cos(2.0 * M_PI * i / (Filt_N - 1)))); + w[i] = static_cast(32768.0 * 0.25 * (1.0 - cos(2.0 * M_PI * i / (Filt_N - 1)))); WriteRegister(SLEEP_CFR, 1); msb = lsb = 0; @@ -179,11 +179,11 @@ void Equalizer::UpdateHannCoeff(uint16_t Filt_N) msb = lsb = 0; i = j = 0; offset = 0; - while (i <= (uint16_t)((Filt_N / 2) - 1)) + while (i <= static_cast((Filt_N / 2) - 1)) { addr = (2 << 15) + (maddressf1 << 6) + (msb << 4) + lsb; if (j >= offset) - data = w[(uint16_t)((Filt_N + 1) / 2 + i)]; + data = w[static_cast((Filt_N + 1) / 2 + i)]; else data = 0; mosi.push_back((1 << 31) | addr << 16 | data); @@ -204,7 +204,7 @@ void Equalizer::UpdateHannCoeff(uint16_t Filt_N) msb = lsb = 0; i = j = 0; - offset = (MaxFilt_N / 2) - ((uint16_t)((Filt_N + 1) / 2)); + offset = (MaxFilt_N / 2) - (static_cast((Filt_N + 1) / 2)); while (i < Filt_N) { addr = (2 << 15) + (maddressf0 << 6) + (msb << 4) + lsb; @@ -296,14 +296,14 @@ void Equalizer::SetFIRCoefficients(const int16_t* coefficients, uint16_t count) mosi.clear(); msb = lsb = i = 0; - while (i <= (uint16_t)((Filt_N)-1)) + while (i <= static_cast((Filt_N)-1)) { addr = (maddressf0 << 6) + (msb << 4) + lsb; - data = (uint16_t)coefficients[i]; + data = static_cast(coefficients[i]); mosi.push_back((1 << 31) | addr << 16 | data); addr = (maddressf1 << 6) + (msb << 4) + lsb; - data = (uint16_t)coefficients[i]; + data = static_cast(coefficients[i]); mosi.push_back((1 << 31) | addr << 16 | data); if (lsb >= NN) // 15 { diff --git a/src/FPGA_common/FPGA_common.cpp b/src/FPGA_common/FPGA_common.cpp index e65cd46dd..f0b6c6a9b 100644 --- a/src/FPGA_common/FPGA_common.cpp +++ b/src/FPGA_common/FPGA_common.cpp @@ -678,7 +678,7 @@ int FPGA::FPGAPacketPayload2Samples(const uint8_t* buffer, int bufLen, bool mimo if (mimo) //uncompressed samples { - complex16_t* ptr = (complex16_t*)buffer; + const complex16_t* ptr = reinterpret_cast(buffer); const int collected = bufLen / sizeof(complex16_t) / 2; for (int i = 0; i < collected; i++) { @@ -728,7 +728,7 @@ int FPGA::FPGAPacketPayload2SamplesFloat(const uint8_t* buffer, int bufLen, bool return collected; } - complex16_t* src = (complex16_t*)buffer; + const complex16_t* src = reinterpret_cast(buffer); if (mimo) //uncompressed samples { const int collected = bufLen / sizeof(complex16_t) / 2; @@ -782,7 +782,7 @@ int FPGA::Samples2FPGAPacketPayloadFloat( return b; } - complex16_t* dest = (complex16_t*)buffer; + complex16_t* dest = reinterpret_cast(buffer); if (mimo) { for (int src = 0; src < samplesCount; ++src) @@ -831,7 +831,7 @@ int FPGA::Samples2FPGAPacketPayload( if (mimo) { - complex16_t* ptr = (complex16_t*)buffer; + complex16_t* ptr = reinterpret_cast(buffer); for (int src = 0; src < samplesCount; ++src) { *ptr++ = samples[0][src]; @@ -1250,7 +1250,7 @@ FPGA::GatewareInfo FPGA::GetGatewareInfo() return info; info.boardID = data[0]; - info.version = (int16_t)data[1]; + info.version = static_cast(data[1]); info.revision = data[2]; info.hardwareVersion = data[3] & 0x7F; return info; diff --git a/src/LMS_Programing/LMS_Programing_wxgui.cpp b/src/LMS_Programing/LMS_Programing_wxgui.cpp index 9c4b83c5a..4e12b66b2 100644 --- a/src/LMS_Programing/LMS_Programing_wxgui.cpp +++ b/src/LMS_Programing/LMS_Programing_wxgui.cpp @@ -82,14 +82,20 @@ LMS_Programing_wxgui::LMS_Programing_wxgui( FlexGridSizer1->Fit(this); FlexGridSizer1->SetSizeHints(this); - Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&LMS_Programing_wxgui::OnbtnOpenClick); + Connect( + ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&LMS_Programing_wxgui::OnbtnOpenClick)); Connect(btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, - (wxObjectEventFunction)&LMS_Programing_wxgui::OnbtnStartProgrammingClick); - Connect(ID_CHOICE2, wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction)&LMS_Programing_wxgui::OncmbDeviceSelect); - Connect(ID_PROGRAMING_FINISHED_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&LMS_Programing_wxgui::OnProgramingFinished); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&LMS_Programing_wxgui::OnProgramingStatusUpdate); + reinterpret_cast(&LMS_Programing_wxgui::OnbtnStartProgrammingClick)); + Connect(ID_CHOICE2, + wxEVT_COMMAND_CHOICE_SELECTED, + reinterpret_cast(&LMS_Programing_wxgui::OncmbDeviceSelect)); + Connect(ID_PROGRAMING_FINISHED_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&LMS_Programing_wxgui::OnProgramingFinished)); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&LMS_Programing_wxgui::OnProgramingStatusUpdate)); } LMS_Programing_wxgui::~LMS_Programing_wxgui() @@ -211,14 +217,16 @@ void LMS_Programing_wxgui::OnbtnStartProgrammingClick(wxCommandEvent& event) Disconnect(btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, - (wxObjectEventFunction)&LMS_Programing_wxgui::OnbtnStartProgrammingClick); + reinterpret_cast(&LMS_Programing_wxgui::OnbtnStartProgrammingClick)); btnOpen->Disable(); btnStartStop->SetLabel(_("Abort")); mAbortProgramming.store(false); //run programming in separate thread, to prevent GUI freeze mWorkerThread = std::thread(&LMS_Programing_wxgui::DoProgramming, this); - Connect(btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&LMS_Programing_wxgui::OnAbortProgramming); + Connect(btnStartStop->GetId(), + wxEVT_COMMAND_BUTTON_CLICKED, + reinterpret_cast(&LMS_Programing_wxgui::OnAbortProgramming)); } /** @brief Change programming modes according to selected device @@ -240,11 +248,12 @@ void LMS_Programing_wxgui::OnProgramingFinished(wxCommandEvent& event) mWorkerThread.join(); wxMessageBox(event.GetString(), _("INFO"), wxICON_INFORMATION | wxOK); btnOpen->Enable(btnOpenEnb); - Disconnect( - btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&LMS_Programing_wxgui::OnAbortProgramming); + Disconnect(btnStartStop->GetId(), + wxEVT_COMMAND_BUTTON_CLICKED, + reinterpret_cast(&LMS_Programing_wxgui::OnAbortProgramming)); Connect(btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, - (wxObjectEventFunction)&LMS_Programing_wxgui::OnbtnStartProgrammingClick); + reinterpret_cast(&LMS_Programing_wxgui::OnbtnStartProgrammingClick)); btnStartStop->SetLabel(_("Program")); } diff --git a/src/Si5351C/Si5351C.cpp b/src/Si5351C/Si5351C.cpp index b9d671862..08fd5ba9b 100644 --- a/src/Si5351C/Si5351C.cpp +++ b/src/Si5351C/Si5351C.cpp @@ -26,8 +26,8 @@ using namespace lime; /// Splits float into fraction integers A + B/C void realToFrac(const float real, int& A, int& B, int& C) { - A = (int)real; - B = (int)((real - A) * 1048576 + 0.5); + A = static_cast(real); + B = std::round((real - A) * 1048576); C = 1048576; int a = B; @@ -750,7 +750,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l //cout << "PLLA stage: " << endl; //cout << "best score: " << bestScore << " best VCO: " << bestVCOA << endl; plls[0].VCO_Hz = bestVCOA; - plls[0].feedbackDivider = (double)bestVCOA / plls[0].inputFreqHz; + plls[0].feedbackDivider = static_cast(bestVCOA) / plls[0].inputFreqHz; for (int i = 0; i < clockCount; ++i) { @@ -766,7 +766,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l else { clocks[i].int_mode = false; - clocks[i].multisynthDivider = (double)bestVCOA / clocks[i].outputFreqHz; + clocks[i].multisynthDivider = static_cast(bestVCOA) / clocks[i].outputFreqHz; } clocks[i].pllSource = 0; } @@ -821,7 +821,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l if (bestVCOB == 0) //just in case if pllb is not used make it the same frequency as plla bestVCOB = bestVCOA; plls[1].VCO_Hz = bestVCOB; - plls[1].feedbackDivider = (double)bestVCOB / plls[0].inputFreqHz; + plls[1].feedbackDivider = static_cast(bestVCOB) / plls[0].inputFreqHz; for (int i = 0; i < clockCount; ++i) { if (clocks[i].outputFreqHz == 0 || !clocks[i].powered) @@ -838,7 +838,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l else { clocks[i].int_mode = false; - clocks[i].multisynthDivider = (double)bestVCOB / clocks[i].outputFreqHz; + clocks[i].multisynthDivider = static_cast(bestVCOB) / clocks[i].outputFreqHz; } clocks[i].pllSource = 1; } @@ -893,8 +893,8 @@ Si5351C::Status Si5351C::ConfigureClocks() { if (CLK[i].outputFreqHz <= 150000000) { - unsigned MSX_P1 = 128 * DivA + floor(128 * ((float)DivB / DivC)) - 512; - unsigned MSX_P2 = 128 * DivB - DivC * floor(128 * DivB / DivC); + unsigned MSX_P1 = 128 * DivA + std::floor(128 * (static_cast(DivB) / DivC)) - 512; + unsigned MSX_P2 = 128 * DivB - DivC * std::floor(128 * DivB / DivC); unsigned MSX_P3 = DivC; m_newConfiguration[addr] = MSX_P3 >> 8; @@ -984,8 +984,8 @@ Si5351C::Status Si5351C::ConfigureClocks() DivB, DivC); - MSNx_P1 = 128 * DivA + floor(128 * ((float)DivB / DivC)) - 512; - MSNx_P2 = 128 * DivB - DivC * floor(128 * DivB / DivC); + MSNx_P1 = 128 * DivA + std::floor(128 * (static_cast(DivB) / DivC)) - 512; + MSNx_P2 = 128 * DivB - DivC * std::floor(128 * DivB / DivC); MSNx_P3 = DivC; m_newConfiguration[addr + 4] = MSNx_P1; @@ -1016,8 +1016,7 @@ void Si5351C::SetClock(unsigned char id, unsigned long fOut_Hz, bool enabled, bo { if (fOut_Hz < 8000 || fOut_Hz > 160000000) { - lime::error( - "Si5351C - CLK%d output frequency must be between 8kHz and 160MHz. fOut_MHz = %g", (int)id, fOut_Hz / 1000000.0); + lime::error("Si5351C - CLK%d output frequency must be between 8kHz and 160MHz. fOut_MHz = %g", id, fOut_Hz / 1000000.0); return; } CLK[id].powered = enabled; diff --git a/src/Si5351C/Si5351C_wxgui.cpp b/src/Si5351C/Si5351C_wxgui.cpp index fc05e4a18..ce242dfc5 100644 --- a/src/Si5351C/Si5351C_wxgui.cpp +++ b/src/Si5351C/Si5351C_wxgui.cpp @@ -293,11 +293,17 @@ Si5351C_wxgui::Si5351C_wxgui( FlexGridSizer1->Fit(this); FlexGridSizer1->SetSizeHints(this); - Connect(ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnLoadFileClick); - Connect(ID_BUTTON4, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnResetToDefaultsClick); - Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnReadStatusClick); - Connect(ID_BUTTON5, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnClearStatusClick); - Connect(ID_BUTTON3, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnConfigureClockClick); + Connect(ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&Si5351C_wxgui::OnbtnLoadFileClick)); + Connect(ID_BUTTON4, + wxEVT_COMMAND_BUTTON_CLICKED, + reinterpret_cast(&Si5351C_wxgui::OnbtnResetToDefaultsClick)); + Connect( + ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&Si5351C_wxgui::OnbtnReadStatusClick)); + Connect( + ID_BUTTON5, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&Si5351C_wxgui::OnbtnClearStatusClick)); + Connect(ID_BUTTON3, + wxEVT_COMMAND_BUTTON_CLICKED, + reinterpret_cast(&Si5351C_wxgui::OnbtnConfigureClockClick)); } void Si5351C_wxgui::Initialize(SDRDevice* pModule) diff --git a/src/boards/MMX8/MM_X8Entry.cpp b/src/boards/MMX8/MM_X8Entry.cpp index e6359a1c7..c732c3dd0 100644 --- a/src/boards/MMX8/MM_X8Entry.cpp +++ b/src/boards/MMX8/MM_X8Entry.cpp @@ -127,7 +127,7 @@ class LMS64C_FPGA_Over_PCIe_MMX8 : public lime::IComms const char* data, size_t length, int prog_mode, int target, ProgressCallback callback = nullptr) override { return LMS64CProtocol::ProgramWrite( - pipe, data, length, prog_mode, (LMS64CProtocol::ProgramWriteTarget)target, callback, subdeviceIndex); + pipe, data, length, prog_mode, static_cast(target), callback, subdeviceIndex); } int MemoryWrite(uint32_t address, const void* data, uint32_t dataLength) diff --git a/src/boards_wxgui/pnlX3.cpp b/src/boards_wxgui/pnlX3.cpp index 55c0650ea..8ff4d3315 100644 --- a/src/boards_wxgui/pnlX3.cpp +++ b/src/boards_wxgui/pnlX3.cpp @@ -193,7 +193,8 @@ pnlX3::pnlX3(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& btnLMS1Settings = new wxButton(this, wxNewId(), _T("Configure")); mainSizer->Add(btnLMS1Settings, 1, wxALIGN_LEFT | wxEXPAND, 5); - Connect(btnLMS1Settings->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&pnlX3::OnLMS1Configure); + Connect( + btnLMS1Settings->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&pnlX3::OnLMS1Configure)); // end B.J. auto lms1Sizer = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, wxT("LMS1")), wxVERTICAL); @@ -313,7 +314,8 @@ pnlX3::pnlX3(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& btnLMS2Settings = new wxButton(this, wxNewId(), _T("Configure")); mainSizer2->Add(btnLMS2Settings, 1, wxALIGN_LEFT | wxEXPAND, 5); - Connect(btnLMS2Settings->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&pnlX3::OnLMS2Configure); + Connect( + btnLMS2Settings->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&pnlX3::OnLMS2Configure)); // end B.J. auto lms2Sizer = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, wxT("LMS2")), wxVERTICAL); @@ -573,8 +575,8 @@ void pnlX3::OnLMS1Configure(wxCommandEvent& event) int m_bLMS1ChA, m_bLMS1ChB = 0; Register chkLms1Tx1, cmbLms1Tx1Path, cmbLms1Rx1Path, chkLms1Tx2, cmbLms1Tx2Path, cmbLms1Rx2Path; - m_bLMS1ChA = (int)cbLMS1ChA->GetValue(); - m_bLMS1ChB = (int)cbLMS1ChB->GetValue(); + m_bLMS1ChA = static_cast(cbLMS1ChA->GetValue()); + m_bLMS1ChB = static_cast(cbLMS1ChB->GetValue()); // LMS#1 channel A chkLms1Tx1 = Register(0x00D2, 5, 5, 0); // positive logic @@ -682,8 +684,8 @@ void pnlX3::OnLMS2Configure(wxCommandEvent& event) Register cmbLms2Trx1T, cmbLms2Trx1, cmbLms2Rx1In, cmbLms2Rx1C, cmbLms3Rx1, chkLms2Tx1, chkLms2Lna1; Register cmbLms2Trx2T, cmbLms2Trx2, cmbLms2Rx2In, cmbLms2Rx2C, chkLms2Tx2, chkLms2Lna2; - m_bLMS2ChA = (int)cbLMS2ChA->GetValue(); - m_bLMS2ChB = (int)cbLMS2ChB->GetValue(); + m_bLMS2ChA = static_cast(cbLMS2ChA->GetValue()); + m_bLMS2ChB = static_cast(cbLMS2ChB->GetValue()); // RF2 (log. 0), RF1 (log. 1) // LMS#2 channel A diff --git a/src/cli/limeTRX.cpp b/src/cli/limeTRX.cpp index 53746cfae..7f1d51926 100644 --- a/src/cli/limeTRX.cpp +++ b/src/cli/limeTRX.cpp @@ -559,7 +559,7 @@ int main(int argc, char** argv) inputFile.seekg(0, std::ios_base::beg); cerr << "File size : " << cnt << " bytes." << endl; txData.resize(cnt / sizeof(complex16_t)); - inputFile.read((char*)txData.data(), cnt); + inputFile.read(reinterpret_cast(txData.data()), cnt); inputFile.close(); } @@ -665,7 +665,7 @@ int main(int argc, char** argv) totalSamplesReceived += samplesRead; if (rxFilename) { - rxFile.write((char*)rxSamples[0], samplesRead * sizeof(lime::complex16_t)); + rxFile.write(reinterpret_cast(rxSamples[0]), samplesRead * sizeof(lime::complex16_t)); } t2 = std::chrono::high_resolution_clock::now(); @@ -682,7 +682,8 @@ int main(int argc, char** argv) m_fftCalcIn[i].r = rxSamples[0][i].i / 32768.0; m_fftCalcIn[i].i = rxSamples[0][i].q / 32768.0; } - kiss_fft(m_fftCalcPlan, (kiss_fft_cpx*)&m_fftCalcIn, (kiss_fft_cpx*)&m_fftCalcOut); + kiss_fft( + m_fftCalcPlan, reinterpret_cast(&m_fftCalcIn), reinterpret_cast(&m_fftCalcOut)); for (unsigned int i = 0; i < fftSize; ++i) { float amplitude = diff --git a/src/comms/PCIe/LitePCIe.cpp b/src/comms/PCIe/LitePCIe.cpp index bb3372e1c..404cd278d 100644 --- a/src/comms/PCIe/LitePCIe.cpp +++ b/src/comms/PCIe/LitePCIe.cpp @@ -74,8 +74,12 @@ int LitePCIe::Open(const std::string& deviceFilename, uint32_t flags) const std::string msg = mFilePath + ": DMA writer request denied"; throw std::runtime_error(msg); } - uint8_t* buf = (uint8_t*)mmap( - NULL, info.dma_rx_buf_size * info.dma_rx_buf_count, PROT_READ, MAP_SHARED, mFileDescriptor, info.dma_rx_buf_offset); + uint8_t* buf = static_cast(mmap(NULL, + info.dma_rx_buf_size * info.dma_rx_buf_count, + PROT_READ, + MAP_SHARED, + mFileDescriptor, + info.dma_rx_buf_offset)); if (buf == MAP_FAILED || buf == nullptr) { const std::string msg = mFilePath + ": failed to MMAP Rx DMA buffer"; @@ -94,12 +98,12 @@ int LitePCIe::Open(const std::string& deviceFilename, uint32_t flags) const std::string msg = mFilePath + ": DMA reader request denied"; throw std::runtime_error(msg); } - uint8_t* buf = (uint8_t*)mmap(NULL, + uint8_t* buf = static_cast(mmap(NULL, info.dma_tx_buf_size * info.dma_tx_buf_count, PROT_WRITE, MAP_SHARED, mFileDescriptor, - info.dma_tx_buf_offset); + info.dma_tx_buf_offset)); if (buf == MAP_FAILED || buf == nullptr) { const std::string msg = mFilePath + ": failed to MMAP Tx DMA buffer"; diff --git a/src/comms/PCIe/PCIeCommon.cpp b/src/comms/PCIe/PCIeCommon.cpp index e2caee401..c1cf1a8b2 100644 --- a/src/comms/PCIe/PCIeCommon.cpp +++ b/src/comms/PCIe/PCIeCommon.cpp @@ -58,7 +58,8 @@ int LMS64C_FPGA_Over_PCIe::CustomParameterRead(std::vector& p int LMS64C_FPGA_Over_PCIe::ProgramWrite(const char* data, size_t length, int prog_mode, int target, ProgressCallback callback) { - return LMS64CProtocol::ProgramWrite(pipe, data, length, prog_mode, (LMS64CProtocol::ProgramWriteTarget)target, callback); + return LMS64CProtocol::ProgramWrite( + pipe, data, length, prog_mode, static_cast(target), callback); } int LMS64C_FPGA_Over_PCIe::MemoryWrite(uint32_t address, const void* data, uint32_t dataLength) diff --git a/src/comms/PCIe/TRXLooper_PCIE.cpp b/src/comms/PCIe/TRXLooper_PCIE.cpp index 9e50cfec7..ac916c26b 100644 --- a/src/comms/PCIe/TRXLooper_PCIE.cpp +++ b/src/comms/PCIe/TRXLooper_PCIE.cpp @@ -52,8 +52,8 @@ class AvgRmsCounter { if (counter == 0) return; - avg = avgAccumulator / (double)counter; - rms = sqrt(rmsAccumulator / (double)counter); + avg = avgAccumulator / static_cast(counter); + rms = sqrt(rmsAccumulator / static_cast(counter)); avgAccumulator = 0; rmsAccumulator = 0; counter = 0; @@ -85,13 +85,7 @@ static inline int64_t ts_to_us(int64_t fs, int64_t ts) int n, r; n = (ts / fs); r = (ts % fs); - return (int64_t)n * 1000000 + (((int64_t)r * 1000000) / fs); -} - -template inline static T clamp(T value, T low, T high) -{ - assert(low <= high); - return value < low ? low : (value > high ? high : value); + return static_cast(n) * 1000000 + ((static_cast(r) * 1000000) / fs); } TRXLooper_PCIE::TRXLooper_PCIE( @@ -179,7 +173,7 @@ int TRXLooper_PCIE::TxSetup() if (mConfig.extraConfig && mConfig.extraConfig->txMaxPacketsInBatch != 0) mTx.packetsToBatch = mConfig.extraConfig->txMaxPacketsInBatch; - mTx.packetsToBatch = clamp((int)mTx.packetsToBatch, 1, (int)(dma.bufferSize / packetSize)); + mTx.packetsToBatch = std::clamp(mTx.packetsToBatch, 1, dma.bufferSize / packetSize); std::vector dmaBuffers(dma.bufferCount); for (uint32_t i = 0; i < dmaBuffers.size(); ++i) @@ -211,7 +205,7 @@ int TRXLooper_PCIE::TxSetup() return 0; } -/** +/** @brief A class for managing the transmission buffer for the PCIe transfer. @tparam T The samples packet input type. */ @@ -250,7 +244,7 @@ template class TxBufferManager header = reinterpret_cast(mData); header->Clear(); payloadSize = 0; - payloadPtr = (uint8_t*)header + sizeof(StreamHeader); + payloadPtr = reinterpret_cast(header) + sizeof(StreamHeader); } inline bool hasSpace() const @@ -269,7 +263,7 @@ template class TxBufferManager { header = reinterpret_cast(mData + bytesUsed); header->Clear(); - payloadPtr = (uint8_t*)header + sizeof(StreamHeader); + payloadPtr = reinterpret_cast(header) + sizeof(StreamHeader); payloadSize = 0; } @@ -301,7 +295,7 @@ template class TxBufferManager if (bytesUsed >= mCapacity - sizeof(StreamHeader)) sendBuffer = true; // not enough space for more packets, need to flush - if ((uint64_t)payloadPtr & 0xF) + if (reinterpret_cast(payloadPtr) & 0xF) sendBuffer = true; // next packets payload memory is not suitably aligned for vectorized filling if (sendBuffer) @@ -356,8 +350,8 @@ void FPGATxState(FPGA* fpga) fpga->ReadRegisters(addrs, words, 4); pendingTxTS |= words[0]; pendingTxTS |= words[1] << 16; - pendingTxTS |= (uint64_t)words[2] << 32; - pendingTxTS |= (uint64_t)words[3] << 48; + pendingTxTS |= static_cast(words[2]) << 32; + pendingTxTS |= static_cast(words[3]) << 48; if (i < 4) printf("Buf%i: %08lX\n", i, pendingTxTS); else @@ -684,7 +678,7 @@ int TRXLooper_PCIE::RxSetup() if (mConfig.extraConfig && mConfig.extraConfig->rxSamplesInPacket != 0) requestSamplesInPkt = mConfig.extraConfig->rxSamplesInPacket; - int samplesInPkt = clamp(requestSamplesInPkt, 64, maxSamplesInPkt); + int samplesInPkt = std::clamp(requestSamplesInPkt, 64, maxSamplesInPkt); int payloadSize = requestSamplesInPkt * sampleSize * chCount; // iqSamplesCount must be N*16, or N*8 depending on device BUS width @@ -705,7 +699,7 @@ int TRXLooper_PCIE::RxSetup() if (mConfig.extraConfig && mConfig.extraConfig->rxPacketsInBatch != 0) mRx.packetsToBatch = mConfig.extraConfig->rxPacketsInBatch; - mRx.packetsToBatch = clamp((int)mRx.packetsToBatch, 1, (int)(dma.bufferSize / packetSize)); + mRx.packetsToBatch = std::clamp(mRx.packetsToBatch, 1, dma.bufferSize / packetSize); int irqPeriod = 16; float bufferTimeDuration = 0; @@ -714,7 +708,7 @@ int TRXLooper_PCIE::RxSetup() bufferTimeDuration = float(samplesInPkt * mRx.packetsToBatch) / mConfig.hintSampleRate; irqPeriod = 80e-6 / bufferTimeDuration; } - irqPeriod = clamp(irqPeriod, 1, 16); + irqPeriod = std::clamp(irqPeriod, 1, 16); irqPeriod = 4; if (mCallback_logMessage) diff --git a/src/comms/USB/LMS64C_FPGA_Over_USB.cpp b/src/comms/USB/LMS64C_FPGA_Over_USB.cpp index a274089d0..b20e5e7f8 100644 --- a/src/comms/USB/LMS64C_FPGA_Over_USB.cpp +++ b/src/comms/USB/LMS64C_FPGA_Over_USB.cpp @@ -50,5 +50,6 @@ int LMS64C_FPGA_Over_USB::CustomParameterRead(std::vector& pa int LMS64C_FPGA_Over_USB::ProgramWrite(const char* data, size_t length, int prog_mode, int target, ProgressCallback callback) { - return LMS64CProtocol::ProgramWrite(*pipe, data, length, prog_mode, (LMS64CProtocol::ProgramWriteTarget)target, callback); + return LMS64CProtocol::ProgramWrite( + *pipe, data, length, prog_mode, static_cast(target), callback); } diff --git a/src/examples/basicRX.cpp b/src/examples/basicRX.cpp index eb059f017..fca84867d 100644 --- a/src/examples/basicRX.cpp +++ b/src/examples/basicRX.cpp @@ -145,7 +145,7 @@ int main(int argc, char** argv) m_fftCalcIn[i].r = rxSamples[0][i].i; m_fftCalcIn[i].i = rxSamples[0][i].q; } - kiss_fft(m_fftCalcPlan, (kiss_fft_cpx*)&m_fftCalcIn, (kiss_fft_cpx*)&m_fftCalcOut); + kiss_fft(m_fftCalcPlan, reinterpret_cast(&m_fftCalcIn), reinterpret_cast(&m_fftCalcOut)); for (unsigned int i = 1; i < fftSize; ++i) { float output = diff --git a/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp b/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp index 4c68caed4..390358e47 100644 --- a/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp +++ b/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp @@ -562,7 +562,7 @@ void fftviewer_frFFTviewer::StreamingLoop( { for (unsigned s = 0; s < fftSize; ++s) { - const float div = (float)fftCounter * fftSize * fftSize; + const float div = static_cast(fftCounter) * fftSize * fftSize; localDataResults.fftBins[ch][s] /= div; } } diff --git a/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp b/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp index d54f19596..1889e32f9 100644 --- a/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp @@ -558,8 +558,9 @@ void lms7002_pnlMCU_BD_view::OnbtnStartProgrammingClick(wxCommandEvent& event) progressPooler->Start(200); Connect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnProgrammingfinished), NULL, this); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); obj_ptr = this; mThreadWorking = true; mWorkerThread = std::thread( @@ -631,9 +632,9 @@ void lms7002_pnlMCU_BD_view::OnbtnLoadTestFileClick(wxCommandEvent& event) //fscanf(inFile, "%d %d %d", &test_code, &address, &value); scanStatus = fscanf(inFile, "%d ", &address); scanStatus = fscanf(inFile, "%d\n", &value); - TestResultArray_code[m_iTestResultFileLine] = (unsigned char)(test_code); - TestResultArray_address[m_iTestResultFileLine] = (unsigned char)(address); - TestResultArray_value[m_iTestResultFileLine] = (unsigned char)(value); + TestResultArray_code[m_iTestResultFileLine] = static_cast(test_code); + TestResultArray_address[m_iTestResultFileLine] = static_cast(address); + TestResultArray_value[m_iTestResultFileLine] = static_cast(value); m_iTestResultFileLine++; scanStatus = fscanf(inFile, "%d", &test_code); @@ -819,7 +820,7 @@ int lms7002_pnlMCU_BD_view::ReadOneByte(unsigned char* data) LMS_ReadLMSReg(lmsControl, 0x0005, &tempi); ; // REG5 read // return the read byte - (*data) = (unsigned char)(tempi); + (*data) = static_cast(tempi); } else (*data) = 0; @@ -875,16 +876,16 @@ int lms7002_pnlMCU_BD_view::Three_byte_command(unsigned char data1, *rdata2 = 0x00; *rdata3 = 0x00; - LMS_WriteLMSReg(lmsControl, 0x8004, (unsigned short)data1); + LMS_WriteLMSReg(lmsControl, 0x8004, static_cast(data1)); retval = WaitUntilWritten(); if (retval == -1) return -1; - LMS_WriteLMSReg(lmsControl, 0x8004, (unsigned short)data2); //REG4 write + LMS_WriteLMSReg(lmsControl, 0x8004, static_cast(data2)); //REG4 write retval = WaitUntilWritten(); if (retval == -1) return -1; - LMS_WriteLMSReg(lmsControl, 0x8004, (unsigned short)data3); //REG4 write + LMS_WriteLMSReg(lmsControl, 0x8004, static_cast(data3)); //REG4 write retval = WaitUntilWritten(); if (retval == -1) return -1; @@ -944,9 +945,9 @@ void lms7002_pnlMCU_BD_view::OnbtnRunTestClick(wxCommandEvent& event) { scanStatus = fscanf(inFile, "%d ", &address); scanStatus = fscanf(inFile, "%d\n", &value); - TestResultArray_code[m_iTestResultFileLine] = (unsigned char)(test_code); - TestResultArray_address[m_iTestResultFileLine] = (unsigned char)(address); - TestResultArray_value[m_iTestResultFileLine] = (unsigned char)(value); + TestResultArray_code[m_iTestResultFileLine] = static_cast(test_code); + TestResultArray_address[m_iTestResultFileLine] = static_cast(address); + TestResultArray_value[m_iTestResultFileLine] = static_cast(value); m_iTestResultFileLine++; scanStatus = fscanf(inFile, "%d", &test_code); @@ -984,7 +985,8 @@ void lms7002_pnlMCU_BD_view::OnbtnRunTestClick(wxCommandEvent& event) { if (TestResultArray_code[i] == m_iTestNo) { - retval = Three_byte_command(0x78, (unsigned char)(TestResultArray_address[i]), 0x00, &tempc1, &tempc2, &tempc3); + retval = + Three_byte_command(0x78, static_cast(TestResultArray_address[i]), 0x00, &tempc1, &tempc2, &tempc3); if ((retval == -1) || (tempc3 != TestResultArray_value[i])) m_iError = 1; else @@ -1353,8 +1355,9 @@ void lms7002_pnlMCU_BD_view::OnViewSFRsClick(wxCommandEvent& event) progressBar->SetValue(0); progressPooler->Start(200); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Connect(ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnReadSFRfinished), NULL, this); mThreadWorking = true; @@ -1385,7 +1388,7 @@ int lms7002_pnlMCU_BD_view::Read_IRAM() for (i = 0; i <= 255; i++) { // code 0x78 is for reading the IRAM locations - retval = Three_byte_command(0x78, ((unsigned char)(i)), 0x00, &tempc1, &tempc2, &tempc3); + retval = Three_byte_command(0x78, static_cast(i), 0x00, &tempc1, &tempc2, &tempc3); if (retval == 0) m_IRAM[i] = tempc3; else @@ -1412,8 +1415,9 @@ void lms7002_pnlMCU_BD_view::OnViewIRAMClick(wxCommandEvent& event) progressBar->SetValue(0); progressPooler->Start(200); Connect(ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnReadIRAMfinished), NULL, this); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); mThreadWorking = true; mWorkerThread = std::thread( @@ -1443,7 +1447,7 @@ int lms7002_pnlMCU_BD_view::Erase_IRAM() { m_IRAM[i] = 0x00; // code 0x7C is for writing the IRAM locations - retval = Three_byte_command(0x7C, ((unsigned char)(i)), 0x00, &tempc1, &tempc2, &tempc3); + retval = Three_byte_command(0x7C, static_cast(i), 0x00, &tempc1, &tempc2, &tempc3); if (retval == -1) { i = 256; @@ -1467,8 +1471,9 @@ void lms7002_pnlMCU_BD_view::OnEraseIRAMClick(wxCommandEvent& event) Disable(); progressBar->SetValue(0); progressPooler->Start(200); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Connect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnEraseIRAMfinished), NULL, this); @@ -1560,7 +1565,9 @@ void lms7002_pnlMCU_BD_view::OnReadIRAMfinished(wxThreadEvent& event) mWorkerThread.join(); mThreadWorking = false; progressPooler->Stop(); - Disconnect(ID_PROGRAMING_STATUS_EVENT, wxEVT_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Disconnect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Disconnect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnReadIRAMfinished), NULL, this); progressBar->SetValue(100); @@ -1581,7 +1588,9 @@ void lms7002_pnlMCU_BD_view::OnEraseIRAMfinished(wxThreadEvent& event) mWorkerThread.join(); mThreadWorking = false; progressPooler->Stop(); - Disconnect(ID_PROGRAMING_STATUS_EVENT, wxEVT_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Disconnect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Disconnect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnEraseIRAMfinished), NULL, this); progressBar->SetValue(100); @@ -1596,7 +1605,9 @@ void lms7002_pnlMCU_BD_view::OnReadSFRfinished(wxThreadEvent& event) mWorkerThread.join(); mThreadWorking = false; progressPooler->Stop(); - Disconnect(ID_PROGRAMING_STATUS_EVENT, wxEVT_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Disconnect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Disconnect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnReadSFRfinished), NULL, this); progressBar->SetValue(100); @@ -1617,7 +1628,9 @@ void lms7002_pnlMCU_BD_view::OnProgrammingfinished(wxThreadEvent& event) mWorkerThread.join(); mThreadWorking = false; progressPooler->Stop(); - Disconnect(ID_PROGRAMING_STATUS_EVENT, wxEVT_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Disconnect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Disconnect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnProgrammingfinished), NULL, this); progressBar->SetValue(100); diff --git a/src/lms7002_wxgui/lms7002_pnlR3.cpp b/src/lms7002_wxgui/lms7002_pnlR3.cpp index 2962188c1..907ff217c 100644 --- a/src/lms7002_wxgui/lms7002_pnlR3.cpp +++ b/src/lms7002_wxgui/lms7002_pnlR3.cpp @@ -526,11 +526,13 @@ void lms7002_pnlR3_view::MCU_RunProcedure(uint8_t id) const uint16_t x0002reg = temp & 0xFF; const uint16_t interupt6 = 0x0008; const uint16_t addrs[5] = { 0x0006, 0x0, 0x0002, 0x0002, 0x0002 }; - const uint16_t values[5] = { (uint16_t)(id != 0), - (uint16_t)(id), - (uint16_t)(x0002reg & ~interupt6), - (uint16_t)(x0002reg | interupt6), - (uint16_t)(x0002reg & ~interupt6) }; + const uint16_t values[5] = { + static_cast(id != 0), + static_cast(id), + static_cast(x0002reg & ~interupt6), + static_cast(x0002reg | interupt6), + static_cast(x0002reg & ~interupt6), + }; for (int i = 0; i < 5; ++i) lmsControl->SPI_write(addrs[i], values[i]); } diff --git a/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp b/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp index be60b8036..ec73d064e 100644 --- a/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp @@ -1744,25 +1744,25 @@ void lms7002_pnlTXTSP_view::UpdateGUI() cmbHBI_OVR_TXTSP->SetSelection(value2index(hbi, hbi_ovr_txtsp_IndexValuePairs)); int16_t value; - LMS_ReadParam(lmsControl, LMS7param(TSGFCW_TXTSP), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(TSGFCW_TXTSP), reinterpret_cast(&value)); rgrTSGFCW_TXTSP->SetSelection(value2index(value, tsgfcw_txtsp_IndexValuePairs)); - LMS_ReadParam(lmsControl, LMS7param(IQCORR_TXTSP), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(IQCORR_TXTSP), reinterpret_cast(&value)); int bitsToShift = (15 - LMS7param(IQCORR_TXTSP).msb - LMS7param(IQCORR_TXTSP).lsb); value = value << bitsToShift; value = value >> bitsToShift; cmbIQCORR_TXTSP->SetValue(value); - LMS_ReadParam(lmsControl, LMS7param(SEL_TX), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(SEL_TX), reinterpret_cast(&value)); assert(rgrNCOselections.size() == 16); rgrNCOselections[value & 0xF]->SetValue(true); UpdateNCOinputs(); - LMS_ReadParam(lmsControl, LMS7param(DCCORRI_TXTSP), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(DCCORRI_TXTSP), reinterpret_cast(&value)); int8_t dccorr = value; cmbDCCORRI_TXTSP->SetValue(dccorr); - LMS_ReadParam(lmsControl, LMS7param(DCCORRQ_TXTSP), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(DCCORRQ_TXTSP), reinterpret_cast(&value)); dccorr = value; cmbDCCORRQ_TXTSP->SetValue(dccorr); @@ -1786,10 +1786,10 @@ void lms7002_pnlTXTSP_view::UpdateGUI() //LMS_GetSampleRate(lmsControl, LMS_CH_TX, ch , &sr, nullptr); txtRATEVAL->SetLabel(wxString::Format("%3.3f MHz", sr / 1e6)); //check if B channel is enabled - LMS_ReadParam(lmsControl, LMS7param(MAC), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(MAC), reinterpret_cast(&value)); if (value >= 2) { - LMS_ReadParam(lmsControl, LMS7param(MIMO_SISO), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(MIMO_SISO), reinterpret_cast(&value)); if (value != 0) wxMessageBox(_("MIMO channel B is disabled"), _("Warning")); } diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index db7b86590..5a35f409f 100644 --- a/src/lms7002m/LMS7002M.cpp +++ b/src/lms7002m/LMS7002M.cpp @@ -13,7 +13,14 @@ #include #include "limesuite/IComms.h" #include "limesuite/commonTypes.h" +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif #include "cpp-feather-ini-parser/INI.h" +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif #include #include #include @@ -1182,7 +1189,7 @@ int LMS7002M::SetTBBIAMP_dB(const float_type gain, const Channel channel) return 0; } - int g_iamp = (float_type)opt_gain_tbb[ind] * pow(10.0, gain / 20.0) + 0.4; + int g_iamp = static_cast(opt_gain_tbb[ind]) * pow(10.0, gain / 20.0) + 0.4; Modify_SPI_Reg_bits(LMS7param(CG_IAMP_TBB), std::clamp(g_iamp, 1, 63), true); return 0; @@ -1201,7 +1208,7 @@ float_type LMS7002M::GetTBBIAMP_dB(const Channel channel) return 0.0; Modify_SPI_Reg_bits(LMS7param(CG_IAMP_TBB), g_current, true); //restore } - return 20.0 * log10((float_type)g_current / (float_type)opt_gain_tbb[ind]); + return 20.0 * log10(static_cast(g_current) / static_cast(opt_gain_tbb[ind])); } int LMS7002M::SetPathRFE(PathRFE path) @@ -1385,18 +1392,18 @@ int LMS7002M::SetFrequencyCGEN(const float_type freq_Hz, const bool retainNCOfre if (dFvco <= gCGEN_VCO_frequencies[0] || dFvco >= gCGEN_VCO_frequencies[1]) return ReportError(ERANGE, "SetFrequencyCGEN(%g MHz) - cannot deliver requested frequency", freq_Hz / 1e6); //Integer division - uint16_t gINT = (uint16_t)(dFvco / GetReferenceClk_SX(TRXDir::Rx) - 1); + uint16_t gINT = static_cast(dFvco / GetReferenceClk_SX(TRXDir::Rx) - 1); //Fractional division - dFrac = dFvco / GetReferenceClk_SX(TRXDir::Rx) - (uint32_t)(dFvco / GetReferenceClk_SX(TRXDir::Rx)); - uint32_t gFRAC = (uint32_t)(dFrac * 1048576); + dFrac = dFvco / GetReferenceClk_SX(TRXDir::Rx) - static_cast(dFvco / GetReferenceClk_SX(TRXDir::Rx)); + uint32_t gFRAC = static_cast(dFrac * 1048576); Modify_SPI_Reg_bits(LMS7param(INT_SDM_CGEN), gINT); //INT_SDM_CGEN Modify_SPI_Reg_bits(0x0087, 15, 0, gFRAC & 0xFFFF); //INT_SDM_CGEN[15:0] Modify_SPI_Reg_bits(0x0088, 3, 0, gFRAC >> 16); //INT_SDM_CGEN[19:16] Modify_SPI_Reg_bits(LMS7param(DIV_OUTCH_CGEN), iHdiv); //DIV_OUTCH_CGEN - lime::debug("INT %d, FRAC %d, DIV_OUTCH_CGEN %d", gINT, gFRAC, (uint16_t)iHdiv); + lime::debug("INT %d, FRAC %d, DIV_OUTCH_CGEN %d", gINT, gFRAC, iHdiv); lime::debug("VCO %.2f MHz, RefClk %.2f MHz", dFvco / 1e6, GetReferenceClk_SX(TRXDir::Rx) / 1e6); if (output) @@ -1548,7 +1555,7 @@ int LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT { Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, 0); this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); if (cmphl == 3) //VCO too high { this->SetActiveChannel(ch); //restore previously used channel @@ -1557,7 +1564,7 @@ int LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT } Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, 255); this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); if (cmphl == 0) //VCO too low { this->SetActiveChannel(ch); //restore previously used channel @@ -1582,8 +1589,8 @@ int LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT cswSearch[t].high |= 1 << i; //CSW_VCO=1 Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, cswSearch[t].high); this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); - lime::debug("csw=%d\tcmphl=%d", cswSearch[t].high, (int16_t)cmphl); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); + lime::debug("csw=%d\tcmphl=%d", cswSearch[t].high, cmphl); if (cmphl & 0x01) // reduce CSW cswSearch[t].high &= ~(1 << i); //CSW_VCO=0 if (cmphl == 2 && cswSearch[t].high < cswSearch[t].low) @@ -1600,7 +1607,7 @@ int LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, cswSearch[t].low); this_thread::sleep_for(settlingTime); const uint8_t tempCMPvalue = Get_SPI_Reg_bits(addrCMP, 13, 12, true); - lime::debug("csw=%d\tcmphl=%d", cswSearch[t].low, (int16_t)tempCMPvalue); + lime::debug("csw=%d\tcmphl=%d", cswSearch[t].low, tempCMPvalue); if (tempCMPvalue != 2) { ++cswSearch[t].low; @@ -1646,7 +1653,7 @@ int LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT finalCSW = cswLow; Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, cswLow); this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); if (cmphl != 2) { finalCSW = cswHigh; @@ -1659,7 +1666,7 @@ int LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, finalCSW); } this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); this->SetActiveChannel(ch); //restore previously used channel if (cmphl == 2) { @@ -1800,10 +1807,9 @@ int LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* output) const float_type refClk_Hz = GetReferenceClk_SX(dir); assert(refClk_Hz > 0); - integerPart = (uint16_t)(VCOfreq / (refClk_Hz * (1 + (VCOfreq > m_dThrF))) - 4); - fractionalPart = (uint32_t)((VCOfreq / (refClk_Hz * (1 + (VCOfreq > m_dThrF))) - - (uint32_t)(VCOfreq / (refClk_Hz * (1 + (VCOfreq > m_dThrF))))) * - 1048576); + double divider = refClk_Hz * (1 + (VCOfreq > m_dThrF)); + integerPart = static_cast(VCOfreq / divider - 4); + fractionalPart = static_cast((VCOfreq / divider - static_cast(VCOfreq / divider)) * 1048576); Channel ch = this->GetActiveChannel(); this->SetActiveChannel(dir == TRXDir::Tx ? Channel::ChSXT : Channel::ChSXR); @@ -1819,7 +1825,7 @@ int LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* output) freq_Hz / 1e6, integerPart, fractionalPart, - (int16_t)div_loch, + div_loch, (VCOfreq > m_dThrF)); lime::debug("Expected VCO %.2f MHz, RefClk %.2f MHz", VCOfreq / 1e6, refClk_Hz / 1e6); @@ -1846,7 +1852,7 @@ int LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* output) Modify_SPI_Reg_bits(LMS7param(SEL_VCO), sel_vco); Modify_SPI_Reg_bits(LMS7param(CSW_VCO).address, LMS7param(CSW_VCO).msb, LMS7param(CSW_VCO).lsb, csw_value); this_thread::sleep_for(chrono::microseconds(50)); // probably no need for this as the interface is already very slow.. - auto cmphl = (uint8_t)Get_SPI_Reg_bits(LMS7param(VCO_CMPHO).address, 13, 12, true); + auto cmphl = static_cast(Get_SPI_Reg_bits(LMS7param(VCO_CMPHO).address, 13, 12, true)); if (cmphl == 2) { lime::info("Fast Tune success; vco=%d value=%d", tuning_cache_sel_vco[freq_Hz], tuning_cache_csw_value[freq_Hz]); @@ -1951,7 +1957,7 @@ int LMS7002M::SetFrequencySXWithSpurCancelation(TRXDir dir, float_type freq_Hz, float newFreq(0); if (needCancelation) { - newFreq = (int)(freq_Hz / refClk + 0.5) * refClk; + newFreq = std::round(freq_Hz / refClk) * refClk; TuneRxFilter(BW - BWOffset + 2 * abs(freq_Hz - newFreq)); status = SetFrequencySX(dir, newFreq); } @@ -2015,9 +2021,9 @@ float_type LMS7002M::GetFrequencySX(TRXDir dir) uint32_t gFRAC = ((gINT & 0xF) * 65536) | Get_SPI_Reg_bits(0x011D, 15, 0); const float_type refClk_Hz = GetReferenceClk_SX(dir); - dMul = (float_type)refClk_Hz / (1 << (Get_SPI_Reg_bits(LMS7param(DIV_LOCH)) + 1)); + dMul = refClk_Hz / (1 << (Get_SPI_Reg_bits(LMS7param(DIV_LOCH)) + 1)); //Calculate real frequency according to the calculated parameters - dMul = dMul * ((gINT >> 4) + 4 + (float_type)gFRAC / 1048576.0) * (Get_SPI_Reg_bits(LMS7param(EN_DIV2_DIVPROG)) + 1); + dMul = dMul * ((gINT >> 4) + 4 + gFRAC / 1048576.0) * (Get_SPI_Reg_bits(LMS7param(EN_DIV2_DIVPROG)) + 1); return dMul; } @@ -2071,7 +2077,7 @@ float_type LMS7002M::GetNCOFrequency(TRXDir dir, uint8_t index, bool fromChip) int LMS7002M::SetNCOPhaseOffsetForMode0(TRXDir dir, float_type angle_deg) { uint16_t addr = dir == TRXDir::Tx ? 0x0241 : 0x0441; - uint16_t pho = (uint16_t)(65536 * (angle_deg / 360)); + uint16_t pho = static_cast(65536 * (angle_deg / 360)); SPI_write(addr, pho); return 0; } @@ -2087,7 +2093,7 @@ int LMS7002M::SetNCOPhaseOffset(TRXDir dir, uint8_t index, float_type angle_deg) if (index > 15) return ReportError(ERANGE, "SetNCOPhaseOffset(index = %d) - index out of range [0, 15]", int(index)); uint16_t addr = dir == TRXDir::Tx ? 0x0244 : 0x0444; - uint16_t pho = (uint16_t)(65536 * (angle_deg / 360)); + uint16_t pho = static_cast(65536 * (angle_deg / 360)); SPI_write(addr + index, pho); return 0; } @@ -2161,7 +2167,7 @@ int LMS7002M::SetGFIRCoefficients(TRXDir dir, uint8_t GFIR_index, const int16_t* vector addresses; for (index = 0; index < coefCount; ++index) addresses.push_back(startAddr + index + 24 * (index / 40)); - SPI_write_batch(&addresses[0], (uint16_t*)coef, coefCount, true); + SPI_write_batch(&addresses[0], reinterpret_cast(coef), coefCount, true); return 0; } @@ -2185,7 +2191,7 @@ int LMS7002M::WriteGFIRCoefficients(TRXDir dir, uint8_t gfirIndex, const float_t int16_t words[120]; // actual used coefficients count is multiple of 'bankCount' // if coefCount is not multiple, extra '0' coefficients will be written - const uint8_t bankLength = ceil((float)coefCount / bankCount); + const uint8_t bankLength = std::ceil(static_cast(coefCount) / bankCount); const int16_t actualCoefCount = bankLength * bankCount; assert(actualCoefCount <= maxCoefCount); @@ -2204,7 +2210,7 @@ int LMS7002M::WriteGFIRCoefficients(TRXDir dir, uint8_t gfirIndex, const float_t gfirL_param.address += gfirIndex + (dir == TRXDir::Tx ? 0 : 0x0200); Modify_SPI_Reg_bits(gfirL_param, bankLength - 1); - return SPI_write_batch(addrs, (const uint16_t*)words, actualCoefCount, true); + return SPI_write_batch(addrs, reinterpret_cast(words), actualCoefCount, true); } /** @brief Returns currently loaded FIR coefficients @@ -2428,7 +2434,7 @@ int LMS7002M::SPI_read_batch(const uint16_t* spiAddr, uint16_t* spiData, uint16_ std::vector dataRd(cnt); for (size_t i = 0; i < cnt; ++i) { - dataWr[i] = (uint32_t)(spiAddr[i]); + dataWr[i] = spiAddr[i]; } controlPort->SPI(dataWr.data(), dataRd.data(), cnt); @@ -2922,7 +2928,7 @@ int LMS7002M::SetInterfaceFrequency(float_type cgen_freq_Hz, const uint8_t inter } else { - uint8_t divider = (uint8_t)pow(2.0, decimation + siso); + uint8_t divider = static_cast(std::pow(2.0, decimation + siso)); if (divider > 1) Modify_SPI_Reg_bits(LMS7param(RXTSPCLKA_DIV), (divider / 2) - 1); else @@ -2948,7 +2954,7 @@ int LMS7002M::SetInterfaceFrequency(float_type cgen_freq_Hz, const uint8_t inter } else { - uint8_t divider = (uint8_t)pow(2.0, interpolation + siso); + uint8_t divider = static_cast(std::pow(2.0, interpolation + siso)); if (divider > 1) Modify_SPI_Reg_bits(LMS7param(TXTSPCLKA_DIV), (divider / 2) - 1); else diff --git a/src/lms7002m/LMS7002M_RxTxCalibrations.cpp b/src/lms7002m/LMS7002M_RxTxCalibrations.cpp index 5111b1cd7..df9a257a1 100644 --- a/src/lms7002m/LMS7002M_RxTxCalibrations.cpp +++ b/src/lms7002m/LMS7002M_RxTxCalibrations.cpp @@ -204,7 +204,7 @@ int LMS7002M::CalibrateTx(float_type bandwidth_Hz, bool useExtLoopback) return ReportError(EINVAL, "Tx Calibration: Device not connected"); auto beginTime = std::chrono::high_resolution_clock::now(); int status; - uint8_t ch = (uint8_t)Get_SPI_Reg_bits(LMS7_MAC); + uint8_t ch = static_cast(Get_SPI_Reg_bits(LMS7_MAC)); if (ch == 0 || ch == 3) return ReportError(EINVAL, "Tx Calibration: Incorrect channel selection MAC %i", ch); @@ -304,11 +304,11 @@ int LMS7002M::CalibrateRx(float_type bandwidth_Hz, bool useExtLoopback) #endif int status; - uint8_t ch = (uint8_t)Get_SPI_Reg_bits(LMS7_MAC); + uint8_t ch = static_cast(Get_SPI_Reg_bits(LMS7_MAC)); if (ch == 0 || ch == 3) return ReportError(EINVAL, "Rx Calibration: Incorrect channel selection MAC %i", ch); uint8_t channel = ch == 1 ? 0 : 1; - uint8_t lna = (uint8_t)Get_SPI_Reg_bits(LMS7_SEL_PATH_RFE); + uint8_t lna = static_cast(Get_SPI_Reg_bits(LMS7_SEL_PATH_RFE)); double rxFreq = GetFrequencySX(TRXDir::Rx); const char* lnaName; diff --git a/src/lms7002m/MCU_BD.cpp b/src/lms7002m/MCU_BD.cpp index e30c83e3a..41121d428 100644 --- a/src/lms7002m/MCU_BD.cpp +++ b/src/lms7002m/MCU_BD.cpp @@ -176,7 +176,7 @@ int MCU_BD::ReadOneByte(unsigned char* data) { // Time out has not occured tempi = mSPI_read(0x0005); // REG5 read // return the read byte - (*data) = (unsigned char)(tempi); + (*data) = static_cast(tempi); } else (*data) = 0; @@ -224,17 +224,17 @@ int MCU_BD::Three_byte_command(unsigned char data1, *rdata2 = 0x00; *rdata3 = 0x00; - mSPI_write(0x8004, (unsigned short)(data1)); //REG4 write + mSPI_write(0x8004, static_cast(data1)); //REG4 write retval = WaitUntilWritten(); if (retval == -1) return -1; - mSPI_write(0x8004, (unsigned short)(data2)); //REG4 write + mSPI_write(0x8004, static_cast(data2)); //REG4 write retval = WaitUntilWritten(); if (retval == -1) return -1; - mSPI_write(0x8004, (unsigned short)(data3)); //REG4 write + mSPI_write(0x8004, static_cast(data3)); //REG4 write retval = WaitUntilWritten(); if (retval == -1) return -1; @@ -282,7 +282,7 @@ int MCU_BD::Read_IRAM() for (i = 0; i <= 255; i++) { // code 0x78 is for reading the IRAM locations - retval = Three_byte_command(0x78, ((unsigned char)(i)), 0x00, &tempc1, &tempc2, &tempc3); + retval = Three_byte_command(0x78, static_cast(i), 0x00, &tempc1, &tempc2, &tempc3); if (retval == 0) m_IRAM[i] = tempc3; else @@ -319,7 +319,7 @@ int MCU_BD::Erase_IRAM() { m_IRAM[i] = 0x00; // code 0x7C is for writing the IRAM locations - retval = Three_byte_command(0x7C, ((unsigned char)(i)), 0x00, &tempc1, &tempc2, &tempc3); + retval = Three_byte_command(0x7C, static_cast(i), 0x00, &tempc1, &tempc2, &tempc3); if (retval == -1) { i = 256; @@ -1152,7 +1152,7 @@ void MCU_BD::SetParameter(MCU_Parameter param, float value) { uint8_t inputRegs[3]; value /= 1e6; - inputRegs[0] = (uint8_t)value; //frequency integer part + inputRegs[0] = static_cast(value); //frequency integer part uint16_t fracPart = value * 1000.0 - inputRegs[0] * 1000.0; inputRegs[1] = (fracPart >> 8) & 0xFF; @@ -1171,7 +1171,7 @@ void MCU_BD::SetParameter(MCU_Parameter param, float value) RunProcedure(3); if (param == MCU_Parameter::MCU_EXT_LOOPBACK_PAIR) { - uint8_t intVal = (int)value; + uint8_t intVal = static_cast(value); mSPI_write(0, intVal); mSPI_write(0x0002, x0002reg | interupt7); mSPI_write(0x0002, x0002reg & ~interupt7); diff --git a/src/lms7002m/MCU_File.cpp b/src/lms7002m/MCU_File.cpp index 7390424b7..41269ce66 100644 --- a/src/lms7002m/MCU_File.cpp +++ b/src/lms7002m/MCU_File.cpp @@ -163,7 +163,7 @@ void MCU_File::ReadHex(unsigned long limit) { throw "Hex line data corrupt!\n"; } - checkSum += (unsigned char)tmp; + checkSum += static_cast(tmp); } if (checkSum != 0) { @@ -206,7 +206,7 @@ void MCU_File::ReadHex(unsigned long limit) } continue; } - m_chunks.back().m_bytes.push_back((unsigned char)tmp); + m_chunks.back().m_bytes.push_back(static_cast(tmp)); } } break; @@ -271,7 +271,7 @@ void MCU_File::ReadHex(unsigned long limit) throw "Address field must be zero in extended linear address record!\n"; } sscanf(&szLine[9], "%4lx", &startAddress); - addressBase = ((unsigned long)startAddress) << 16; + addressBase = startAddress << 16; linear = true; break; @@ -323,7 +323,7 @@ void MCU_File::ReadHex(unsigned long limit) { throw "Hex line data corrupt!\n"; } - checkSum += (unsigned char)tmp; + checkSum += static_cast(tmp); } if (checkSum != 255) { @@ -340,7 +340,7 @@ void MCU_File::ReadHex(unsigned long limit) for (i = 0; uint8_t(i + 3) < count; ++i) { sscanf(&szLine[8 + i * 2], "%2lx", &tmp); - header[i] = (char)tmp; + header[i] = static_cast(tmp); } header[i] = 0; if (i > 0) @@ -390,7 +390,7 @@ void MCU_File::ReadHex(unsigned long limit) } continue; } - m_chunks.back().m_bytes.push_back((unsigned char)tmp); + m_chunks.back().m_bytes.push_back(static_cast(tmp)); } } break; @@ -503,4 +503,4 @@ bool MCU_File::BitString(const unsigned long address, const unsigned char bits, mask <<= 1; } return true; -} \ No newline at end of file +} diff --git a/src/lms7suiteAppFrame.cpp b/src/lms7suiteAppFrame.cpp index cb3dd3d56..fac0cab47 100644 --- a/src/lms7suiteAppFrame.cpp +++ b/src/lms7suiteAppFrame.cpp @@ -343,7 +343,7 @@ void LMS7SuiteAppFrame::OnLogDataTransfer(bool Tx, const uint8_t* data, const ui repeatedZeros = repeatedZeros - (repeatedZeros & 0x1); for (size_t i = 0; i < length - repeatedZeros; ++i) //casting to short to print as numbers - ss << " " << std::setw(2) << (unsigned short)data[i]; + ss << " " << std::setw(2) << static_cast(data[i]); if (repeatedZeros > 2) ss << " (00 x " << std::dec << repeatedZeros << " times)"; cout << ss.str() << endl; diff --git a/src/mcu_program/common_src/lms7002m_calibrations.c b/src/mcu_program/common_src/lms7002m_calibrations.c index 8a0934567..5b7052d41 100644 --- a/src/mcu_program/common_src/lms7002m_calibrations.c +++ b/src/mcu_program/common_src/lms7002m_calibrations.c @@ -2,36 +2,32 @@ #include "LMS7002M_parameters_compact.h" #include "spi.h" #include "lms7002m_controls.h" -#include +#include #include "mcu_defines.h" -#ifndef __cplusplus - #include "lms7002_regx51.h" //MCU timer sfr -#endif - #define ENABLE_EXTERNAL_LOOPBACK 1 -#ifdef __cplusplus - #include +#include //#define VERBOSE 1 //#define DRAW_GNU_PLOTS - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include - #ifdef DRAW_GNU_PLOTS - #define PUSH_GMEASUREMENT_VALUES(value, rssi) gMeasurements.push_back({ value, rssi }) +#ifdef DRAW_GNU_PLOTS + #define PUSH_GMEASUREMENT_VALUES(value, rssi) gMeasurements.push_back({ value, rssi }) GNUPlotPipe saturationPlot; GNUPlotPipe IQImbalancePlot; GNUPlotPipe txDCPlot; - #else - #define PUSH_GMEASUREMENT_VALUES(value, rssi) - #endif - #include +#else + #define PUSH_GMEASUREMENT_VALUES(value, rssi) +#endif +#include typedef std::vector> MeasurementsVector; MeasurementsVector gMeasurements; @@ -61,7 +57,7 @@ float ChipRSSI_2_dBFS(uint32_t rssi) uint32_t maxRSSI = 0x15FF4; if (rssi == 0) rssi = 1; - return 20 * log10((float)(rssi) / maxRSSI); + return 20 * log10(static_cast(rssi) / maxRSSI); } int16_t toSigned(int16_t val, uint8_t msblsb) @@ -70,10 +66,6 @@ int16_t toSigned(int16_t val, uint8_t msblsb) val >>= 15 - ((msblsb >> 4) & 0xF); return val; } -#else - #define VERBOSE 0 - #define PUSH_GMEASUREMENT_VALUES(value, rssi) -#endif // __cplusplus float bandwidthRF = 5e6; //Calibration bandwidth uint16_t RSSIDelayCounter = 1; // MCU timer delay between RSSI measurements @@ -86,15 +78,6 @@ uint16_t RSSIDelayCounter = 1; // MCU timer delay between RSSI measurements // [1:0] SEL_PATH_RFE, when calibrating Tx uint8_t extLoopbackPair = 0; -int16_t clamp(int16_t value, int16_t minBound, int16_t maxBound) -{ - if (value < minBound) - return minBound; - if (value > maxBound) - return maxBound; - return value; -} - static void FlipRisingEdge(const uint16_t addr, const uint8_t bits) { Modify_SPI_Reg_bits(addr, bits, 0); @@ -127,7 +110,7 @@ void UpdateRSSIDelay() decimation = 1; //bypass { float waitTime = sampleCount / ((GetReferenceClk_TSP_MHz(false) / 2) / decimation); - RSSIDelayCounter = (0xFFFF) - (uint16_t)(waitTime * RefClk / 12); + RSSIDelayCounter = (0xFFFF) - static_cast(waitTime * RefClk / 12); } } @@ -250,7 +233,7 @@ int CheckSaturationTxRx(bool extLoopback) Modify_SPI_Reg_bits(CMIX_BYP_RXTSP, 0); SetNCOFrequency(LMS7002M_Rx, calibrationSXOffset_Hz - offsetNCO + (bandwidthRF / calibUserBwDivider) * 2, 0); - g_pga = (uint8_t)Get_SPI_Reg_bits(G_PGA_RBB); + g_pga = static_cast(Get_SPI_Reg_bits(G_PGA_RBB)); #if ENABLE_EXTERNAL_LOOPBACK if (extLoopback) { @@ -259,7 +242,7 @@ int CheckSaturationTxRx(bool extLoopback) } else #endif - g_rfe = (uint8_t)Get_SPI_Reg_bits(G_RXLOOPB_RFE); + g_rfe = static_cast(Get_SPI_Reg_bits(G_RXLOOPB_RFE)); rssi = GetRSSI(); PUSH_GMEASUREMENT_VALUES(index, ChipRSSI_2_dBFS(rssi)); @@ -298,7 +281,7 @@ int CheckSaturationTxRx(bool extLoopback) break; Modify_SPI_Reg_bits(G_PGA_RBB, g_pga); rssi = GetRSSI(); - if ((float)rssi / rssi_prev < 1.05) // pga should give ~1dB change + if (static_cast(rssi) / rssi_prev < 1.05) // pga should give ~1dB change break; rssi_prev = rssi; PUSH_GMEASUREMENT_VALUES(++index, ChipRSSI_2_dBFS(rssi)); @@ -455,12 +438,12 @@ void AdjustAutoDC(const uint16_t address, bool tx) minValue = initVal = ReadAnalogDC(address); minRSSI = rssi = GetRSSI(); - WriteAnalogDC(address, clamp(initVal + 1, -range, range)); + WriteAnalogDC(address, std::clamp(initVal + 1, -range, range)); valChange = GetRSSI() < rssi ? 1 : -1; for (i = 8; i; --i) { - initVal = clamp(initVal + valChange, -range, range); + initVal = std::clamp(initVal + valChange, -range, range); WriteAnalogDC(address, initVal); rssi = GetRSSI(); if (rssi < minRSSI) @@ -580,10 +563,10 @@ void CalibrateTxDCAuto() qparams.result = 0; //ReadAnalogDC(qparams.param.address); for (i = 0; i < 3; ++i) { - iparams.minValue = clamp(iparams.result - offset[i], -1024, 1023); - iparams.maxValue = clamp(iparams.result + offset[i], -1024, 1023); - qparams.minValue = clamp(qparams.result - offset[i], -1024, 1023); - qparams.maxValue = clamp(qparams.result + offset[i], -1024, 1023); + iparams.minValue = std::clamp(iparams.result - offset[i], -1024, 1023); + iparams.maxValue = std::clamp(iparams.result + offset[i], -1024, 1023); + qparams.minValue = std::clamp(qparams.result - offset[i], -1024, 1023); + qparams.maxValue = std::clamp(qparams.result + offset[i], -1024, 1023); TxDcBinarySearch(&iparams); #ifdef DRAW_GNU_PLOTS @@ -728,10 +711,8 @@ void CalibrateIQImbalance(bool tx) uint8_t SetupCGEN() { - uint8_t cgenMultiplier; - uint8_t gfir3n; - cgenMultiplier = clamp((GetFrequencyCGEN() / 46.08e6) + 0.5, 2, 13); - gfir3n = 4 * cgenMultiplier; + uint8_t cgenMultiplier = std::clamp(std::round(GetFrequencyCGEN() / 46.08e6), 2, 13); + uint8_t gfir3n = 4 * cgenMultiplier; if (Get_SPI_Reg_bits(EN_ADCCLKH_CLKGN) == 1) gfir3n /= pow2(Get_SPI_Reg_bits(CLKH_OV_CLKL_CGEN)); @@ -930,7 +911,7 @@ uint8_t CalibrateTxSetup(bool extLoopback) LoadDC_REG_TX_IQ(); SetNCOFrequency(LMS7002M_Tx, bandwidthRF / calibUserBwDivider, 0); { - const uint8_t sel_band1_2_trf = (uint8_t)Get_SPI_Reg_bits(0x0103, MSB_LSB(11, 10)); + const uint8_t sel_band1_2_trf = static_cast(Get_SPI_Reg_bits(0x0103, MSB_LSB(11, 10))); #if ENABLE_EXTERNAL_LOOPBACK if (extLoopback) { @@ -1014,7 +995,7 @@ uint8_t CalibrateTx(bool extLoopback) CalibrateTxDCAuto(); SetNCOFrequency(LMS7002M_Rx, calibrationSXOffset_Hz - offsetNCO, 0); CalibrateIQImbalance(LMS7002M_Tx); -TxCalibrationEnd : { +TxCalibrationEnd: { //analog dc is not overwritten by chip state restore uint16_t gcorri = Get_SPI_Reg_bits(GCORRI_TXTSP); uint16_t gcorrq = Get_SPI_Reg_bits(GCORRQ_TXTSP); @@ -1320,7 +1301,7 @@ uint8_t CheckSaturationRx(const float_type bandwidth_Hz, bool extLoopback) { ROM const uint16_t target_rssi = 0x07000; //0x0B000 = -3 dBFS uint16_t rssi; - uint8_t cg_iamp = (uint8_t)Get_SPI_Reg_bits(CG_IAMP_TBB); + uint8_t cg_iamp = static_cast(Get_SPI_Reg_bits(CG_IAMP_TBB)); #ifdef DRAW_GNU_PLOTS int index = 0; GNUPlotPipe& gp = saturationPlot; @@ -1486,7 +1467,7 @@ uint8_t CalibrateRx(bool extLoopback, bool dcOnly) goto RxCalibrationEndStage; if (!extLoopback) { - if ((uint8_t)Get_SPI_Reg_bits(SEL_PATH_RFE) == 2) + if (Get_SPI_Reg_bits(SEL_PATH_RFE) == 2) { Modify_SPI_Reg_bits(PD_RLOOPB_2_RFE, 0); Modify_SPI_Reg_bits(EN_INSHSW_LB2_RFE, 0); @@ -1514,7 +1495,7 @@ uint8_t CalibrateRx(bool extLoopback, bool dcOnly) Modify_SPI_Reg_bits(CMIX_BYP_RXTSP, 0); SetNCOFrequency(LMS7002M_Rx, bandwidthRF / calibUserBwDivider + offsetNCO, 0); CalibrateIQImbalance(LMS7002M_Rx); -RxCalibrationEndStage : { +RxCalibrationEndStage: { uint16_t gcorri = Get_SPI_Reg_bits(GCORRI_RXTSP); uint16_t gcorrq = Get_SPI_Reg_bits(GCORRQ_RXTSP); uint16_t phaseOffset = Get_SPI_Reg_bits(IQCORR_RXTSP); diff --git a/src/mcu_program/common_src/lms7002m_controls.c b/src/mcu_program/common_src/lms7002m_controls.c index fae3ceac1..8e77b3eaf 100644 --- a/src/mcu_program/common_src/lms7002m_controls.c +++ b/src/mcu_program/common_src/lms7002m_controls.c @@ -561,7 +561,7 @@ float_type GetFrequencyCGEN() { const float_type dMul = (RefClk / 2.0) / (Get_SPI_Reg_bits(DIV_OUTCH_CGEN) + 1); //DIV_OUTCH_CGEN const uint16_t gINT = Get_SPI_Reg_bits(0x0088, MSB_LSB(13, 0)); //read whole register to reduce SPI transfers - const uint32_t gFRAC = ((uint32_t)(gINT & 0xF) << 16) | Get_SPI_Reg_bits(0x0087, MSB_LSB(15, 0)); + const uint32_t gFRAC = (static_cast(gINT & 0xF) << 16) | Get_SPI_Reg_bits(0x0087, MSB_LSB(15, 0)); return dMul * (((gINT >> 4) + 1 + gFRAC / 1048576.0)); } @@ -582,8 +582,8 @@ uint8_t SetFrequencyCGEN(float_type freq) Modify_SPI_Reg_bits(INT_SDM_CGEN, intpart - 1); //INT_SDM_CGEN //Fractional division { - const float_type dFrac = intpart - (uint32_t)(dFvco / RefClk); - const uint32_t gFRAC = (uint32_t)(dFrac * 1048576); + const float_type dFrac = intpart - static_cast(dFvco / RefClk); + const uint32_t gFRAC = static_cast(dFrac * 1048576); Modify_SPI_Reg_bits(0x0087, MSB_LSB(15, 0), gFRAC & 0xFFFF); //INT_SDM_CGEN[15:0] Modify_SPI_Reg_bits(0x0088, MSB_LSB(3, 0), gFRAC >> 16); //INT_SDM_CGEN[19:16] } @@ -609,7 +609,7 @@ float_type GetReferenceClk_TSP_MHz(bool tx) void SetNCOFrequency(const bool tx, const float freq, uint8_t index) { const uint16_t addr = (tx ? 0x0242 : 0x0442) + index * 2; - const uint32_t fcw = (uint32_t)((freq / GetReferenceClk_TSP_MHz(tx)) * 4294967296.0); + const uint32_t fcw = static_cast((freq / GetReferenceClk_TSP_MHz(tx)) * 4294967296.0); SPI_write(addr, (fcw >> 16)); //NCO frequency control word register MSB part. SPI_write(addr + 1, fcw); //NCO frequency control word register LSB part. } @@ -620,7 +620,7 @@ float_type GetFrequencySX(const bool Tx) Modify_SPI_Reg_bits(MAC, Tx ? 2 : 1); // Rx mac = 1, Tx mac = 2 { const uint16_t gINT = Get_SPI_Reg_bits(0x011E, MSB_LSB(13, 0)); // read whole register to reduce SPI transfers - const uint32_t gFRAC = ((uint32_t)(gINT & 0xF) << 16) | SPI_read(0x011D); + const uint32_t gFRAC = (static_cast(gINT & 0xF) << 16) | SPI_read(0x011D); const uint8_t enDiv2 = Get_SPI_Reg_bits(EN_DIV2_DIVPROG) + 1; const uint8_t divLoch = Get_SPI_Reg_bits(DIV_LOCH) + 1; SPI_write(0x0020, ch); @@ -655,9 +655,9 @@ uint8_t SetFrequencySX(const bool tx, const float_type freq_Hz) const uint8_t enDiv2 = (VCOfreq > 5500e6) ? 1 : 0; Modify_SPI_Reg_bits(EN_DIV2_DIVPROG, enDiv2); //EN_DIV2_DIVPROG temp = VCOfreq / (RefClk * (1 + enDiv2)); - fractionalPart = (uint32_t)((temp - (uint32_t)(temp)) * 1048576); + fractionalPart = static_cast((temp - static_cast(temp)) * 1048576); - Modify_SPI_Reg_bits(INT_SDM, (uint16_t)(temp - 4)); //INT_SDM + Modify_SPI_Reg_bits(INT_SDM, static_cast(temp - 4)); //INT_SDM Modify_SPI_Reg_bits(0x011E, MSB_LSB(3, 0), (fractionalPart >> 16)); //FRAC_SDM[19:16] SPI_write(0x011D, fractionalPart & 0xFFFF); //FRAC_SDM[15:0] } @@ -709,7 +709,7 @@ static uint8_t ReadCMP(const bool SX) while (!TF0) ; // wait for timer overflow #endif - return (uint8_t)Get_SPI_Reg_bits(SX ? 0x0123 : 0x008C, MSB_LSB(13, 12)); + return static_cast(Get_SPI_Reg_bits(SX ? 0x0123 : 0x008C, MSB_LSB(13, 12))); } uint8_t TuneVCO(bool SX) // 0-cgen, 1-SXR, 2-SXT diff --git a/src/mcu_program/common_src/lms7002m_filters.c b/src/mcu_program/common_src/lms7002m_filters.c index e655d951a..9a5843285 100644 --- a/src/mcu_program/common_src/lms7002m_filters.c +++ b/src/mcu_program/common_src/lms7002m_filters.c @@ -3,8 +3,9 @@ #include "lms7002m_filters.h" #include "LMS7002M_parameters_compact.h" #include "spi.h" -#include +#include #include "mcu_defines.h" +#include enum { SEARCH_SUCCESS = 0, SEARCH_NEED_TO_DECREASE, SEARCH_NEED_TO_INCREASE }; @@ -20,14 +21,14 @@ static ROM const float_type TxLPF_RF_LimitHigh = 130e6; static uint8_t ConfigCGEN_ForLPF_IF(float IF_Hz) { - uint8_t cgenMultiplier = clamp(IF_Hz * 20 / 46.08e6 + 0.5, 2, 13); + uint8_t cgenMultiplier = std::clamp(std::round(IF_Hz * 20 / 46.08e6), 2, 13); return SetFrequencyCGEN(46.08e6 * cgenMultiplier + 10e6); } static uint8_t RxFilterSearch(const uint16_t addr, const uint8_t msblsb, const uint16_t rssi_3dB, const uint16_t stepLimit) { const bool doDecrement = GetRSSI() < rssi_3dB; - int16_t value = Get_SPI_Reg_bits(addr, msblsb); + uint16_t value = Get_SPI_Reg_bits(addr, msblsb); const uint16_t maxValue = pow2((msblsb >> 4) - (msblsb & 0xF) + 1) - 1; uint16_t stepSize = 1; while (1) @@ -37,7 +38,7 @@ static uint8_t RxFilterSearch(const uint16_t addr, const uint8_t msblsb, const u value -= stepSize; else value += stepSize; - value = clamp(value, 0, maxValue); + value = std::clamp(value, 0, maxValue); Modify_SPI_Reg_bits(addr, msblsb, value); if (doDecrement != (GetRSSI() < rssi_3dB)) break; @@ -51,7 +52,7 @@ static uint8_t RxFilterSearch(const uint16_t addr, const uint8_t msblsb, const u value += stepSize; else value -= stepSize; - value = clamp(value, 0, maxValue); + value = std::clamp(value, 0, maxValue); Modify_SPI_Reg_bits(addr, msblsb, value); } return 0; @@ -302,19 +303,19 @@ uint8_t TuneRxFilterSetup(const float_type rx_lpf_IF) int8_t ccomp_tia_rfe; if (g_tia_rfe > 1) { - cfb_tia_rfe = (int16_t)(1680e6 / rx_lpf_IF - 10); + cfb_tia_rfe = static_cast(1680e6 / rx_lpf_IF - 10); ccomp_tia_rfe = cfb_tia_rfe / 100; } else if (g_tia_rfe == 1) { - cfb_tia_rfe = (int16_t)(5400e6 / rx_lpf_IF - 15); + cfb_tia_rfe = static_cast(5400e6 / rx_lpf_IF - 15); ccomp_tia_rfe = cfb_tia_rfe / 100 + 1; } else return MCU_RX_INVALID_TIA; - SPI_write(0x0112, (clamp(ccomp_tia_rfe, 0, 15) << 8) | clamp(cfb_tia_rfe, 0, 4095)); + SPI_write(0x0112, (std::clamp(ccomp_tia_rfe, 0, 15) << 8) | std::clamp(cfb_tia_rfe, 0, 4095)); - Modify_SPI_Reg_bits(RCOMP_TIA_RFE, clamp(15 - cfb_tia_rfe / 100, 0, 15)); + Modify_SPI_Reg_bits(RCOMP_TIA_RFE, std::clamp(15 - cfb_tia_rfe / 100, 0, 15)); } { const int8_t rcc_ctl_pga_rbb = (430 * pow(0.65, g_pga_rbb / 10) - 110.35) / 20.45 + 16; @@ -327,7 +328,7 @@ uint8_t TuneRxFilterSetup(const float_type rx_lpf_IF) Modify_SPI_Reg_bits(INPUT_CTL_PGA_RBB, 0); { const float freqIF = rx_lpf_IF * 1.3; - int16_t c_ctl_lpfl_rbb = clamp(2160e6 / freqIF - 103, 0, 2047); + int16_t c_ctl_lpfl_rbb = std::clamp(2160e6 / freqIF - 103, 0, 2047); uint8_t rcc_ctl_lpfl_rbb = 5; if (freqIF < 15e6) @@ -349,8 +350,8 @@ uint8_t TuneRxFilterSetup(const float_type rx_lpf_IF) Modify_SPI_Reg_bits(INPUT_CTL_PGA_RBB, 1); { const float lpfIF_adjusted = rx_lpf_IF * 1.3; - uint8_t c_ctl_lpfh_rbb = clamp(6000e6 / lpfIF_adjusted - 50, 0, 255); - uint8_t rcc_ctl_lpfh_rbb = clamp(lpfIF_adjusted / 10e6 - 3, 0, 7); + uint8_t c_ctl_lpfh_rbb = std::clamp(6000e6 / lpfIF_adjusted - 50, 0, 255); + uint8_t rcc_ctl_lpfh_rbb = std::clamp(lpfIF_adjusted / 10e6 - 3, 0, 7); Modify_SPI_Reg_bits(0x0116, MSB_LSB(10, 0), (rcc_ctl_lpfh_rbb << 8) | c_ctl_lpfh_rbb); } } @@ -466,24 +467,24 @@ uint8_t TuneRxFilter(const float_type rx_lpf_freq_RF) uint16_t cfb_tia_rfe; uint8_t g_tia_rfe = Get_SPI_Reg_bits(G_TIA_RFE); if (g_tia_rfe == 3 || g_tia_rfe == 2) - cfb_tia_rfe = (int)(1680e6 / (rx_lpf_IF * 0.72) - 10); + cfb_tia_rfe = static_cast(1680e6 / (rx_lpf_IF * 0.72) - 10); else if (g_tia_rfe == 1) - cfb_tia_rfe = (int)(5400e6 / (rx_lpf_IF * 0.72) - 15); + cfb_tia_rfe = static_cast(5400e6 / (rx_lpf_IF * 0.72) - 15); else { status = MCU_RX_INVALID_TIA; goto RxFilterSearchEndStage; } - cfb_tia_rfe = clamp(cfb_tia_rfe, 0, 4095); + cfb_tia_rfe = std::clamp(cfb_tia_rfe, 0, 4095); Modify_SPI_Reg_bits(CFB_TIA_RFE, cfb_tia_rfe); { uint8_t ccomp_tia_rfe = cfb_tia_rfe / 100; if (g_tia_rfe == 1) ccomp_tia_rfe += 1; - Modify_SPI_Reg_bits(CCOMP_TIA_RFE, clamp(ccomp_tia_rfe, 0, 15)); + Modify_SPI_Reg_bits(CCOMP_TIA_RFE, std::clamp(ccomp_tia_rfe, 0, 15)); } - Modify_SPI_Reg_bits(RCOMP_TIA_RFE, clamp(15 - cfb_tia_rfe / 100, 0, 15)); + Modify_SPI_Reg_bits(RCOMP_TIA_RFE, std::clamp(15 - cfb_tia_rfe / 100, 0, 15)); } } else //if(rx_lpf_IF > 54e6) @@ -500,7 +501,7 @@ uint8_t TuneRxFilter(const float_type rx_lpf_freq_RF) goto RxFilterSearchEndStage; } //END TIA -RxFilterSearchEndStage : { +RxFilterSearchEndStage: { //Restore settings uint16_t ccomp_cfb_tia_rfe = SPI_read(0x0112); uint16_t rcc_c_ctl_lpfl_rbb = SPI_read(0x0117); @@ -717,14 +718,14 @@ uint8_t TuneTxFilterSetup(const float_type tx_lpf_IF) const float_type freq = (16.0 / 20.0) * tx_lpf_IF / 1e6; int16_t rcal_lpflad_tbb = pow(freq, 4) * 1.29858903647958e-16 + pow(freq, 3) * (-0.000110746929967704) + pow(freq, 2) * 0.00277593485991029 + freq * 21.0384293169607 + (-48.4092606238297); - Modify_SPI_Reg_bits(RCAL_LPFLAD_TBB, clamp(rcal_lpflad_tbb, 0, 255)); + Modify_SPI_Reg_bits(RCAL_LPFLAD_TBB, std::clamp(rcal_lpflad_tbb, 0, 255)); } else { const float_type freq = tx_lpf_IF / 1e6; int16_t rcal_lpfh_tbb = pow(freq, 4) * 1.10383261611112e-06 + pow(freq, 3) * (-0.000210800032517545) + pow(freq, 2) * 0.0190494874803309 + freq * 1.43317445923528 + (-47.6950779298333); - Modify_SPI_Reg_bits(RCAL_LPFH_TBB, clamp(rcal_lpfh_tbb, 0, 255)); + Modify_SPI_Reg_bits(RCAL_LPFH_TBB, std::clamp(rcal_lpfh_tbb, 0, 255)); } //CGEN @@ -799,13 +800,13 @@ static uint8_t SearchTxFilterCCAL_RCAL(uint16_t addr, uint8_t msblsb) uint8_t R = Get_SPI_Reg_bits(addr, msblsb); if (R == 0 || R == 255) return MCU_NO_ERROR; // reached filter bandwidth limit - Modify_SPI_Reg_bits(addr, msblsb, clamp(R + rcal_step, 0, 255)); + Modify_SPI_Reg_bits(addr, msblsb, std::clamp(R + rcal_step, 0, 255)); Modify_SPI_Reg_bits(CCAL_LPFLAD_TBB, 16); } else if (needToChangeCCAL) { uint8_t ccal_lpflad_tbb = Get_SPI_Reg_bits(CCAL_LPFLAD_TBB); - ccal_lpflad_tbb = clamp(++ccal_lpflad_tbb, 0, 31); + ccal_lpflad_tbb = std::clamp(ccal_lpflad_tbb + 1, 0, 31); Modify_SPI_Reg_bits(CCAL_LPFLAD_TBB, ccal_lpflad_tbb); } --iterationsLeft; @@ -845,7 +846,7 @@ uint8_t TuneTxFilter(const float_type tx_lpf_freq_RF) Modify_SPI_Reg_bits(C_CTL_PGA_RBB, 2); status = SearchTxFilterCCAL_RCAL(RCAL_LPFH_TBB); } -TxFilterSearchEndStage : { +TxFilterSearchEndStage: { uint16_t ccal_lpflad_tbb = Get_SPI_Reg_bits(CCAL_LPFLAD_TBB); uint16_t rcal_lpfh_lpflad_tbb = SPI_read(0x0109); diff --git a/src/oglGraph/GLFont.cpp b/src/oglGraph/GLFont.cpp index 4c6e25b40..a3572a8e6 100644 --- a/src/oglGraph/GLFont.cpp +++ b/src/oglGraph/GLFont.cpp @@ -67,25 +67,25 @@ bool GLFont::load(const char* file) in.read(reserved, 16); unsigned char fontSize = 0; - in.read((char*)&fontSize, 1); + in.read(reinterpret_cast(&fontSize), sizeof(fontSize)); m_fontSize = fontSize; unsigned short glyphCount = 0; - in.read((char*)&glyphCount, 2); + in.read(reinterpret_cast(&glyphCount), sizeof(glyphCount)); for (int i = 0; i < m_glyphCount; ++i) m_glyphs[i].reset(); GLGlyph tempGlyph; for (unsigned int i = 0; i < glyphCount; ++i) { - in.read((char*)&tempGlyph.id, sizeof(unsigned short)); - in.read((char*)&tempGlyph.width, sizeof(unsigned short)); - in.read((char*)&tempGlyph.height, sizeof(unsigned short)); - in.read((char*)&tempGlyph.u, sizeof(unsigned short)); - in.read((char*)&tempGlyph.v, sizeof(unsigned short)); - in.read((char*)&tempGlyph.offset_x, sizeof(short)); - in.read((char*)&tempGlyph.offset_y, sizeof(short)); - in.read((char*)&tempGlyph.advance_x, sizeof(short)); + in.read(reinterpret_cast(&tempGlyph.id), sizeof(tempGlyph.id)); + in.read(reinterpret_cast(&tempGlyph.width), sizeof(tempGlyph.width)); + in.read(reinterpret_cast(&tempGlyph.height), sizeof(tempGlyph.height)); + in.read(reinterpret_cast(&tempGlyph.u), sizeof(tempGlyph.u)); + in.read(reinterpret_cast(&tempGlyph.v), sizeof(tempGlyph.v)); + in.read(reinterpret_cast(&tempGlyph.offset_x), sizeof(tempGlyph.offset_x)); + in.read(reinterpret_cast(&tempGlyph.offset_y), sizeof(tempGlyph.offset_y)); + in.read(reinterpret_cast(&tempGlyph.advance_x), sizeof(tempGlyph.advance_x)); tempGlyph.advance_x = tempGlyph.advance_x >> 6; m_glyphs[tempGlyph.id] = tempGlyph; } @@ -94,14 +94,15 @@ bool GLFont::load(const char* file) unsigned short texHeight = 0; char bpp = 0; - in.read((char*)&texWidth, sizeof(unsigned short)); + in.read(reinterpret_cast(&texWidth), sizeof(texWidth)); m_texwidth = texWidth; - in.read((char*)&texHeight, sizeof(unsigned short)); + in.read(reinterpret_cast(&texHeight), sizeof(texHeight)); m_texheight = texHeight; - in.read(&bpp, sizeof(char)); + in.read(&bpp, sizeof(bpp)); - unsigned char* bitmap = new unsigned char[texWidth * texHeight]; - in.read((char*)bitmap, texWidth * texHeight); + const int bitmapSize = texWidth * texHeight; + unsigned char* bitmap = new unsigned char[bitmapSize]; + in.read(reinterpret_cast(bitmap), bitmapSize); in.close(); glEnable(GL_TEXTURE_2D); @@ -118,7 +119,14 @@ bool GLFont::load(const char* file) glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, texWidth, texHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap); glBindTexture(GL_TEXTURE_2D, 0); +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif if (!m_vboID && GLEW_VERSION_1_5) +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif { glGenBuffers(1, &m_vboID); glBindBuffer(GL_ARRAY_BUFFER, m_vboID); @@ -157,25 +165,25 @@ bool GLFont::loadFromArray(const char* array, unsigned int size) in.read(reserved, 16); unsigned char fontSize = 0; - in.read((char*)&fontSize, 1); + in.read(reinterpret_cast(&fontSize), sizeof(fontSize)); m_fontSize = fontSize; unsigned short glyphCount = 0; - in.read((char*)&glyphCount, 2); + in.read(reinterpret_cast(&glyphCount), sizeof(glyphCount)); for (int i = 0; i < m_glyphCount; ++i) m_glyphs[i].reset(); GLGlyph tempGlyph; for (unsigned int i = 0; i < glyphCount; ++i) { - in.read((char*)&tempGlyph.id, sizeof(unsigned short)); - in.read((char*)&tempGlyph.width, sizeof(unsigned short)); - in.read((char*)&tempGlyph.height, sizeof(unsigned short)); - in.read((char*)&tempGlyph.u, sizeof(unsigned short)); - in.read((char*)&tempGlyph.v, sizeof(unsigned short)); - in.read((char*)&tempGlyph.offset_x, sizeof(short)); - in.read((char*)&tempGlyph.offset_y, sizeof(short)); - in.read((char*)&tempGlyph.advance_x, sizeof(short)); + in.read(reinterpret_cast(&tempGlyph.id), sizeof(tempGlyph.id)); + in.read(reinterpret_cast(&tempGlyph.width), sizeof(tempGlyph.width)); + in.read(reinterpret_cast(&tempGlyph.height), sizeof(tempGlyph.height)); + in.read(reinterpret_cast(&tempGlyph.u), sizeof(tempGlyph.u)); + in.read(reinterpret_cast(&tempGlyph.v), sizeof(tempGlyph.v)); + in.read(reinterpret_cast(&tempGlyph.offset_x), sizeof(tempGlyph.offset_x)); + in.read(reinterpret_cast(&tempGlyph.offset_y), sizeof(tempGlyph.offset_y)); + in.read(reinterpret_cast(&tempGlyph.advance_x), sizeof(tempGlyph.advance_x)); tempGlyph.advance_x = tempGlyph.advance_x >> 6; m_glyphs[tempGlyph.id] = tempGlyph; } @@ -184,14 +192,15 @@ bool GLFont::loadFromArray(const char* array, unsigned int size) unsigned short texHeight = 0; char bpp = 0; - in.read((char*)&texWidth, sizeof(unsigned short)); + in.read(reinterpret_cast(&texWidth), sizeof(texWidth)); m_texwidth = texWidth; - in.read((char*)&texHeight, sizeof(unsigned short)); + in.read(reinterpret_cast(&texHeight), sizeof(texHeight)); m_texheight = texHeight; - in.read(&bpp, sizeof(char)); + in.read(&bpp, sizeof(bpp)); - unsigned char* bitmap = new unsigned char[texWidth * texHeight]; - in.read((char*)bitmap, texWidth * texHeight); + const int bitmapSize = texWidth * texHeight; + unsigned char* bitmap = new unsigned char[bitmapSize]; + in.read(reinterpret_cast(bitmap), bitmapSize); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); @@ -207,7 +216,14 @@ bool GLFont::loadFromArray(const char* array, unsigned int size) glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, texWidth, texHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap); glBindTexture(GL_TEXTURE_2D, 0); +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif if (!m_vboID && GLEW_VERSION_1_5) +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif { glGenBuffers(1, &m_vboID); glBindBuffer(GL_ARRAY_BUFFER, m_vboID); @@ -244,17 +260,26 @@ void GLFont::render_textWorldSpace(const char* text, float x, float y, float fon GLGlyph* g = NULL; glBindTexture(GL_TEXTURE_2D, m_texID); +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif if (GLEW_VERSION_1_5) +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif + { glBindBuffer(GL_ARRAY_BUFFER, m_vboID); + } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), (char*)0); - glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), (char*)0 + 2 * sizeof(float)); + glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), static_cast(0)); + glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), static_cast(0) + 2 * sizeof(float)); const char* p; for (p = text; *p; ++p) { - g = &m_glyphs[(unsigned char)*p]; - if ((char)*p == '\n') + g = &m_glyphs[static_cast(*p)]; + if (*p == '\n') { x = startx; y = y - lineHeight() * scale; @@ -335,17 +360,26 @@ void GLFont::render_textScreenSpace(const char* text, float x, float y, float fo GLGlyph* g = NULL; glBindTexture(GL_TEXTURE_2D, m_texID); +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif if (GLEW_VERSION_1_5) +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif + { glBindBuffer(GL_ARRAY_BUFFER, m_vboID); + } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), (char*)0); - glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), (char*)0 + 2 * sizeof(float)); + glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), 0); + glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), static_cast(0) + 2 * sizeof(float)); const char* p; for (p = text; *p; ++p) { - g = &m_glyphs[(unsigned char)*p]; - if ((char)*p == '\n') + g = &m_glyphs[static_cast(*p)]; + if (*p == '\n') { x = startx; y = y + lineHeight() * scale; @@ -414,17 +448,17 @@ unsigned int GLFont::lineHeight() const } /** - @brief Gets the width of a given character. + @brief Gets the width of a given character. @param c The character to get the width of. @return The width of @p c . */ unsigned int GLFont::char_width(const char c) const { - return m_glyphs[(unsigned char)c].advance_x; + return m_glyphs[static_cast(c)].advance_x; } /** - @brief Gets the width of a given string. + @brief Gets the width of a given string. @param str The string to get the width of. @return The width of @p str . */ @@ -432,7 +466,7 @@ unsigned int GLFont::string_width(const char* str) const { unsigned int width = 0; for (unsigned int i = 0; i < strlen(str); ++i) - width += m_glyphs[(unsigned char)str[i]].advance_x; + width += m_glyphs[static_cast(str[i])].advance_x; return width; } @@ -454,10 +488,10 @@ void GLFont::getTextSize(const char* str, int& width, int& height, float fontSiz for (int i = 0; i < len; ++i) { if (i > len - 1) - width += m_glyphs[(unsigned char)str[i]].width; + width += m_glyphs[static_cast(str[i])].width; else - width += m_glyphs[(unsigned char)str[i]].advance_x; - glyphH = m_glyphs[(unsigned char)str[i]].height; + width += m_glyphs[static_cast(str[i])].advance_x; + glyphH = m_glyphs[static_cast(str[i])].height; if (glyphH > height) height = glyphH; } diff --git a/src/oglGraph/OpenGLGraph.cpp b/src/oglGraph/OpenGLGraph.cpp index 345e120f0..af9a38d17 100644 --- a/src/oglGraph/OpenGLGraph.cpp +++ b/src/oglGraph/OpenGLGraph.cpp @@ -173,7 +173,7 @@ bool OpenGLGraph::Initialize(int width, int height) } char userOGLversion[255]; - strcpy(userOGLversion, (const char*)glGetString(GL_VERSION)); + strcpy(userOGLversion, reinterpret_cast(glGetString(GL_VERSION))); oglOk = glewIsSupported("GL_VERSION_2_0"); @@ -207,7 +207,7 @@ bool OpenGLGraph::Initialize(int width, int height) initialized = true; m_font = new GLFont(); - m_font->loadFromArray((const char*)standardStaticFont, sizeof(standardStaticFont)); + m_font->loadFromArray(reinterpret_cast(standardStaticFont), sizeof(standardStaticFont)); return true; } @@ -595,7 +595,7 @@ void OpenGLGraph::CalculateGrid() while (interval / divisor > 10 * xlines) divisor *= 10; settings.gridXspacing = divisor * mult[int(0.5f + interval / xlines / divisor)]; - settings.gridXstart = (int)(settings.visibleArea.x1 / settings.gridXspacing) * settings.gridXspacing; + settings.gridXstart = static_cast(settings.visibleArea.x1 / settings.gridXspacing) * settings.gridXspacing; } else settings.gridXspacing = interval; @@ -615,7 +615,7 @@ void OpenGLGraph::CalculateGrid() while (interval / divisor > 10 * ylines) divisor *= 10; settings.gridYspacing = divisor * mult[int(0.5f + interval / ylines / divisor)]; - settings.gridYstart = (int)(settings.visibleArea.y1 / settings.gridYspacing) * settings.gridYspacing; + settings.gridYstart = static_cast(settings.visibleArea.y1 / settings.gridYspacing) * settings.gridYspacing; } else settings.gridYspacing = interval; @@ -683,7 +683,15 @@ void OpenGLGraph::Draw() //draw series data switchToDataView(); + +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif if (settings.useVBO && GLEW_VERSION_1_5) +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif { for (unsigned int i = 0; i < series.size(); i++) { @@ -1030,8 +1038,8 @@ void OpenGLGraph::OnMouseMove(int X, int Y) m_MouseCoord.y2 = Y; spanx = settings.visibleArea.x2 - settings.visibleArea.x1; spany = settings.visibleArea.y2 - settings.visibleArea.y1; - sx = 1 + ((float)(m_MouseCoord.x1 - m_MouseCoord.x2)) / settings.dataViewWidth; - sy = 1 + ((float)(m_MouseCoord.y1 - m_MouseCoord.y2)) / settings.dataViewHeight; + sx = 1 + static_cast(m_MouseCoord.x1 - m_MouseCoord.x2) / settings.dataViewWidth; + sy = 1 + static_cast(m_MouseCoord.y1 - m_MouseCoord.y2) / settings.dataViewHeight; Zoom(settings.visibleArea.x1 + spanx / 2, settings.visibleArea.y1 + spany / 2, m_lastSpanX * sx, m_lastSpanY * sy); break; default: @@ -1673,7 +1681,7 @@ bool OpenGLGraph::SearchPeak() void OpenGLGraph::SetMarker(int id, float xValue, bool enabled, bool show) { - if (id >= 0 && id < (int)markers.size()) + if (id >= 0 && id < static_cast(markers.size())) { ChangeMarker(id, xValue); markers[id].used = enabled; @@ -1683,7 +1691,7 @@ void OpenGLGraph::SetMarker(int id, float xValue, bool enabled, bool show) void OpenGLGraph::GetMarker(int id, float& xValue, float& yValue, bool& enabled, bool& show) { - if (id >= 0 && id < (int)markers.size()) + if (id >= 0 && id < static_cast(markers.size())) { xValue = markers[id].posX; yValue = markers[id].posY; diff --git a/src/oglGraph/OpenGLGraph.h b/src/oglGraph/OpenGLGraph.h index 24aa2dfe0..b8ecdb452 100644 --- a/src/oglGraph/OpenGLGraph.h +++ b/src/oglGraph/OpenGLGraph.h @@ -86,10 +86,10 @@ struct GLG_color { unsigned int getColor4b() { unsigned int color = 0; - color |= (unsigned int)(255 * red) << 24; - color |= (unsigned int)(255 * green) << 16; - color |= (unsigned int)(255 * blue) << 8; - color |= (unsigned int)(255 * alpha); + color |= static_cast(255 * red) << 24; + color |= static_cast(255 * green) << 16; + color |= static_cast(255 * blue) << 8; + color |= static_cast(255 * alpha); return color; } diff --git a/src/oglGraph/StaticFontHeader.h b/src/oglGraph/StaticFontHeader.h index 74eb20237..e6be3c55a 100644 --- a/src/oglGraph/StaticFontHeader.h +++ b/src/oglGraph/StaticFontHeader.h @@ -1,7 +1,8 @@ #ifndef STATIC_FONT_HEADER_H #define STATIC_FONT_HEADER_H +// clang-format off const unsigned char standardStaticFont[] = {79,112,101,110,71,76,32,70,111,110,116,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,96,0,32,0,0,0,0,0,5,0,25,0,0,0,0,0,192,1,33,0,1,0,8,0,4,0,48,0,3,0,8,0,192,1,34,0,3,0,3,0,0,0,60,0,2,0,9,0,192,1,35,0,7,0,8,0,37,0,0,0,0,0,8,0,192,1,36,0,5,0,9,0,23,0,0,0,1,0,8,0,192,1,37,0,7,0,8,0,29,0,54,0,0,0,8,0,192,1,38,0,6,0,8,0,52,0,18,0,1,0,8,0,192,1,39,0,1,0,3,0,4,0,60,0,3,0,9,0,192,1,40,0,3,0,11,0,6,0,12,0,2,0,9,0,192,1,41,0,3,0,11,0,6,0,0,0,2,0,9,0,192,1,42,0,5,0,5,0,65,0,41,0,1,0,6,0,192,1,43,0,5,0,5,0,65,0,35,0,1,0,6,0,192,1,44,0,2,0,4,0,125,0,0,0,1,0,2,0,192,1,45,0,5,0,1,0,10,0,62,0,1,0,4,0,192,1,46,0,1,0,2,0,4,0,57,0,2,0,2,0,192,1,47,0,5,0,10,0,10,0,11,0,1,0,9,0,192,1,48,0,5,0,8,0,59,0,27,0,1,0,8,0,192,1,49,0,5,0,8,0,59,0,18,0,1,0,8,0,192,1,50,0,5,0,8,0,59,0,9,0,1,0,8,0,192,1,51,0,5,0,8,0,59,0,0,0,1,0,8,0,192,1,52,0,6,0,8,0,52,0,9,0,1,0,8,0,192,1,53,0,5,0,8,0,52,0,54,0,1,0,8,0,192,1,54,0,5,0,8,0,52,0,45,0,1,0,8,0,192,1,55,0,5,0,8,0,52,0,36,0,1,0,8,0,192,1,56,0,5,0,8,0,52,0,27,0,1,0,8,0,192,1,57,0,5,0,8,0,23,0,55,0,1,0,8,0,192,1,58,0,1,0,6,0,123,0,0,0,3,0,6,0,192,1,59,0,2,0,8,0,6,0,53,0,1,0,6,0,192,1,60,0,6,0,5,0,78,0,7,0,0,0,6,0,192,1,61,0,6,0,3,0,16,0,60,0,1,0,5,0,192,1,62,0,6,0,5,0,71,0,7,0,1,0,6,0,192,1,63,0,5,0,8,0,23,0,46,0,1,0,8,0,192,1,64,0,7,0,8,0,29,0,45,0,0,0,8,0,192,1,65,0,6,0,8,0,52,0,0,0,1,0,8,0,192,1,66,0,6,0,8,0,45,0,54,0,1,0,8,0,192,1,67,0,6,0,8,0,45,0,45,0,1,0,8,0,192,1,68,0,6,0,8,0,45,0,36,0,1,0,8,0,192,1,69,0,5,0,8,0,23,0,37,0,1,0,8,0,192,1,70,0,5,0,8,0,23,0,28,0,1,0,8,0,192,1,71,0,6,0,8,0,45,0,27,0,1,0,8,0,192,1,72,0,6,0,8,0,45,0,18,0,1,0,8,0,192,1,73,0,3,0,8,0,6,0,44,0,2,0,8,0,192,1,74,0,4,0,8,0,59,0,45,0,1,0,8,0,192,1,75,0,6,0,8,0,45,0,9,0,1,0,8,0,192,1,76,0,5,0,8,0,23,0,19,0,1,0,8,0,192,1,77,0,7,0,8,0,29,0,36,0,0,0,8,0,192,1,78,0,6,0,8,0,45,0,0,0,1,0,8,0,192,1,79,0,6,0,8,0,37,0,54,0,1,0,8,0,192,1,80,0,5,0,8,0,23,0,10,0,1,0,8,0,192,1,81,0,6,0,9,0,16,0,0,0,1,0,8,0,192,1,82,0,6,0,8,0,37,0,45,0,1,0,8,0,192,1,83,0,6,0,8,0,37,0,36,0,1,0,8,0,192,1,84,0,7,0,8,0,29,0,27,0,0,0,8,0,192,1,85,0,6,0,8,0,37,0,27,0,1,0,8,0,192,1,86,0,7,0,8,0,29,0,18,0,0,0,8,0,192,1,87,0,7,0,8,0,29,0,9,0,0,0,8,0,192,1,88,0,6,0,8,0,37,0,18,0,1,0,8,0,192,1,89,0,7,0,8,0,29,0,0,0,0,0,8,0,192,1,90,0,6,0,8,0,37,0,9,0,1,0,8,0,192,1,91,0,3,0,11,0,0,0,48,0,2,0,9,0,192,1,92,0,5,0,10,0,10,0,0,0,1,0,9,0,192,1,93,0,3,0,11,0,0,0,36,0,2,0,9,0,192,1,94,0,5,0,6,0,65,0,28,0,1,0,9,0,192,1,95,0,7,0,1,0,85,0,10,0,0,0,0,0,192,1,96,0,2,0,2,0,59,0,61,0,2,0,9,0,192,1,97,0,5,0,6,0,65,0,21,0,1,0,6,0,192,1,98,0,5,0,9,0,16,0,50,0,1,0,9,0,192,1,99,0,5,0,6,0,65,0,14,0,1,0,6,0,192,1,100,0,5,0,9,0,16,0,40,0,1,0,9,0,192,1,101,0,5,0,6,0,65,0,7,0,1,0,6,0,192,1,102,0,5,0,9,0,16,0,30,0,1,0,9,0,192,1,103,0,5,0,9,0,16,0,20,0,1,0,6,0,192,1,104,0,5,0,9,0,16,0,10,0,1,0,9,0,192,1,105,0,2,0,9,0,6,0,34,0,2,0,9,0,192,1,106,0,4,0,11,0,0,0,24,0,1,0,9,0,192,1,107,0,5,0,9,0,10,0,52,0,1,0,9,0,192,1,108,0,2,0,9,0,6,0,24,0,2,0,9,0,192,1,109,0,7,0,6,0,73,0,0,0,0,0,6,0,192,1,110,0,5,0,6,0,117,0,0,0,1,0,6,0,192,1,111,0,5,0,6,0,111,0,0,0,1,0,6,0,192,1,112,0,5,0,9,0,10,0,42,0,1,0,6,0,192,1,113,0,5,0,9,0,10,0,32,0,1,0,6,0,192,1,114,0,5,0,6,0,105,0,0,0,1,0,6,0,192,1,115,0,5,0,6,0,99,0,0,0,1,0,6,0,192,1,116,0,4,0,8,0,59,0,36,0,2,0,8,0,192,1,117,0,5,0,6,0,93,0,0,0,1,0,6,0,192,1,118,0,5,0,6,0,87,0,0,0,1,0,6,0,192,1,119,0,7,0,6,0,65,0,0,0,0,0,6,0,192,1,120,0,5,0,6,0,81,0,0,0,1,0,6,0,192,1,121,0,5,0,9,0,10,0,22,0,1,0,6,0,192,1,122,0,5,0,6,0,59,0,54,0,1,0,6,0,192,1,123,0,5,0,11,0,0,0,12,0,1,0,9,0,192,1,124,0,1,0,11,0,4,0,36,0,3,0,9,0,192,1,125,0,5,0,11,0,0,0,0,0,1,0,9,0,192,1,126,0,7,0,2,0,85,0,7,0,0,0,5,0,192,1,127,0,0,0,0,0,5,0,24,0,0,0,0,0,192,1,128,0,64,0,8,255,255,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,0,255,255,0,255,0,0,0,0,255,0,0,255,255,255,0,0,0,255,0,0,0,255,0,0,255,0,0,255,0,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,255,255,255,255,0,255,255,255,255,0,0,255,0,0,0,0,0,0,255,255,255,0,0,255,0,0,0,255,0,255,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,255,0,255,0,255,255,255,255,0,0,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,0,255,255,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,255,255,0,255,255,0,0,255,0,0,255,0,0,255,0,0,255,0,255,0,0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,255,0,255,0,0,0,0,255,0,0,0,0,255,255,255,255,255,255,0,0,255,0,0,255,0,255,0,255,0,0,0,0,255,0,0,0,0,0,255,0,255,0,255,0,255,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,255,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,255,0,0,0,255,0,0,255,0,255,0,0,255,255,255,255,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,255,0,0,255,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,255,255,255,0,0,0,0,255,0,255,0,0,0,0,0,255,0,255,0,0,0,255,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,255,255,0,0,255,0,0,255,0,0,255,0,255,0,0,255,0,0,255,0,0,255,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,255,0,0,0,0,0,255,255,0,0,255,0,255,0,0,0,255,0,255,0,0,0,255,0,255,0,0,0,0,0,0,0,255,255,0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,255,0,0,0,0,255,0,0,0,255,0,0,0,255,255,255,255,255,255,0,255,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,255,0,255,0,0,0,0,0,255,0,255,255,255,0,255,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,255,255,255,0,255,0,255,255,0,0,0,255,255,255,0,0,255,255,255,255,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,0,255,0,255,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,255,0,0,255,255,0,0,0,255,0,0,0,255,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,255,0,0,0,255,255,255,255,0,255,0,0,0,0,0,255,0,0,0,0,255,0,255,0,0,255,255,0,0,0,255,0,0,0,255,255,0,0,0,0,255,255,255,0,0,0,255,255,255,0,0,255,255,0,0,0,0,0,0,0,0,0,255,255,0,255,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,255,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,255,255,0,0,0,0,0,255,255,0,0,0,0,255,255,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,255,255,255,255,255,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,255,255,255,255,255,0,255,0,0,0,0,0,0,0,0,0,255,255,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,255,255,255,255,0,0,0,255,255,0,0,0,0,0,255,255,0,0,0,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,255,255,0,255,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,255,255,255,255,255,255,0,0,255,0,0,0,0,255,0,0,0,255,0,255,255,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,255,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,255,0,255,0,255,0,0,0,255,0,0,0,0,0,255,255,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,255,255,255,255,0,0,255,0,255,0,255,0,255,0,0,0,0,255,0,0,0,0,255,0,255,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,0,0,255,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,255,255,255,0,0,0,255,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,255,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,0,0,255,0,255,255,255,255,255,255,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,0,255,255,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,255,255,255,0,255,0,255,255,255,255,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,255,255,255,0,0,0,255,0,0,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,255,255,0,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,255,0,0,0,255,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,255,0,0,255,255,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,255,255,0,0,0,0,255,255,255,255,255,255,0,0,255,255,0,0,255,0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,255,255,255,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,255,0,0,0,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,0,255,255,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,255,255,255,255,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,255,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,255,255,255,0,0,0,0,0,255,255,255,0,0,0,255,255,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,255,255,255,255,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,255,255,255,0,255,0,0,0,255,0,0,255,0,255,0,255,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,255,255,255,0,0,0,255,0,255,0,255,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,255,255,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,255,255,255,255,255,255,0,255,0,0,0,0,255,0,0,0,0,255,255,255,0,0,0,255,255,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,255,255,255,0,255,255,255,255,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,255,255,255,255,0,0,0,255,255,255,255,0,0,0,0,255,0,0,0,0,0,0,255,255,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,255,255,255,255,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,255,255,255,0,0,255,0,0,0,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,255,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,255,0,0,255,0,0,0,0,255,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,255,255,255,255,0,0,255,255,255,255,0,0,255,0,0,0,0,0,255,0,255,0,255,0,255,0,0,255,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,255,255,255,0,0,255,0,255,0,255,0,255,0,255,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,255,255,255,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,255,0,0,0,255,255,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,255,0,0,0,255,255,0,0,255,255,255,255,0,0,0,255,255,255,255,0,0,0,255,255,255,255,255,0,0,255,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,255,255,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,255,255,255,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,255,0,0,0,0,255,0,0,0,0,255,255,255,0,0,0,255,255,255,0,0,0,255,255,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,255,255,255,0,0,255,0,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,255,0,255,0,255,0,255,255,255,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,255,0,255,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,255,255,255,255,0,0,255,255,255,255,0,0,0,0,0,0,255,0,0,255,0,0,255,255,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,255,255,255,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,255,255,0,0,0,255,255,255,255,0,0,0,0,0,0,255,255,255,0,0,0,0,255,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,255,255,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,255,255,0,0,0,0,255,255,255,255,255,0,0,0,255,255,255,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,255,0,255,0,0,0,255,255,255,255,0,0,0,0,255,255,0,0,0,0,0,255,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,255,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,255,255,255,255,0,0,255,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,255,255,255,255,0,0,255,255,255,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,255,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,0,0,255,0,0,255,0,0,0,0,0,255,255,255,255,255,255,0,255,0,0,0,255,0,255,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,255,0,0,0,0,255,255,255,255,0,0,0,255,255,255,255,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,0,0,0,0,0,255,255,255,255,255,0,255,255,255,255,255,255,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255}; +// clang-format on #endif // STATIC_FONT_HEADER_H - diff --git a/src/oglGraph/dlgMarkers.cpp b/src/oglGraph/dlgMarkers.cpp index 80334048b..be76e9417 100644 --- a/src/oglGraph/dlgMarkers.cpp +++ b/src/oglGraph/dlgMarkers.cpp @@ -35,7 +35,7 @@ dlgMarkers::dlgMarkers(wxWindow* parent, wxWindowID id, const wxPoint& pos, cons void dlgMarkers::BuildContent(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size) { - parent_graph = (OpenGLGraph*)parent; + parent_graph = static_cast(parent); //(*Initialize(dlgMarkers) Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER, _T("id")); SetClientSize(wxDefaultSize); @@ -56,7 +56,7 @@ void dlgMarkers::BuildContent(wxWindow* parent, wxWindowID id, const wxPoint& po FlexGridSizer1->Fit(this); FlexGridSizer1->SetSizeHints(this); - Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&dlgMarkers::OnbtnCloseClick); + Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&dlgMarkers::OnbtnCloseClick)); //*) } @@ -95,8 +95,8 @@ void dlgMarkers::AddMarker(int id) marker_valuesA.push_back(0); marker_valuesB.push_back(0); FlexGridSizer3->Add(StaticText4, 1, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5); - Connect(markerId, wxEVT_CHECKBOX, (wxObjectEventFunction)&dlgMarkers::OnMarkerChange); - Connect(markerId, wxEVT_COMMAND_TEXT_UPDATED, (wxObjectEventFunction)&dlgMarkers::OnMarkerChange); + Connect(markerId, wxEVT_CHECKBOX, reinterpret_cast(&dlgMarkers::OnMarkerChange)); + Connect(markerId, wxEVT_COMMAND_TEXT_UPDATED, reinterpret_cast(&dlgMarkers::OnMarkerChange)); pnl->SetSizer(FlexGridSizer3); sizerMarkerList->Add(pnl, 1, wxALIGN_LEFT | wxALIGN_TOP, 5); pnl->Layout(); diff --git a/src/protocols/BufferInterleaving.cpp b/src/protocols/BufferInterleaving.cpp index 27d9e98fc..aed3b1b23 100644 --- a/src/protocols/BufferInterleaving.cpp +++ b/src/protocols/BufferInterleaving.cpp @@ -40,7 +40,7 @@ template int ParseRxPayload(const ui if (mimo) //uncompressed samples { - complex16_t* ptr = (complex16_t*)buffer; + const complex16_t* ptr = reinterpret_cast(buffer); const int collected = bufLen / sizeof(complex16_t) / 2; for (int i = 0; i < collected; i++) { @@ -66,10 +66,11 @@ int Deinterleave(const DataConversion& fmt, const uint8_t* buffer, uint32_t leng { samplesProduced = length / sizeof(complex16_t); if (!mimo) - complex16_to_complex32f(dest[0], (const complex16_t*)buffer, length / sizeof(complex16_t)); + complex16_to_complex32f(dest[0], reinterpret_cast(buffer), length / sizeof(complex16_t)); else { - complex16_to_complex32f_unzip(dest[0], dest[1], (const complex16_t*)buffer, length / sizeof(complex16_t)); + complex16_to_complex32f_unzip( + dest[0], dest[1], reinterpret_cast(buffer), length / sizeof(complex16_t)); samplesProduced /= 2; } } @@ -97,10 +98,10 @@ int Interleave(TRXLooper::SamplesPacketType* input, uint32_t count, const DataCo { bytesProduced = count * sizeof(complex16_t); if (!mimo) - complex32f_to_complex16((complex16_t*)buffer, src[0], count); + complex32f_to_complex16(reinterpret_cast(buffer), src[0], count); else { - complex32f_to_complex16_zip((complex16_t*)buffer, src[0], src[1], count); + complex32f_to_complex16_zip(reinterpret_cast(buffer), src[0], src[1], count); bytesProduced *= 2; } } diff --git a/src/protocols/LMS64CProtocol.cpp b/src/protocols/LMS64CProtocol.cpp index 92a1ee0d0..f5f2f9d25 100644 --- a/src/protocols/LMS64CProtocol.cpp +++ b/src/protocols/LMS64CProtocol.cpp @@ -696,9 +696,9 @@ int MemoryWrite(ISerialPort& port, uint32_t address, const void* data, size_t da progView.SetData(src, chunkSize); src += chunkSize; - if (port.Write((uint8_t*)&packet, sizeof(packet), timeout_ms) != sizeof(packet)) + if (port.Write(reinterpret_cast(&packet), sizeof(packet), timeout_ms) != sizeof(packet)) return -1; - if (port.Read((uint8_t*)&inPacket, sizeof(inPacket), timeout_ms) != sizeof(inPacket)) + if (port.Read(reinterpret_cast(&inPacket), sizeof(inPacket), timeout_ms) != sizeof(inPacket)) return -1; if (inPacket.status != STATUS_COMPLETED_CMD) @@ -735,9 +735,9 @@ int MemoryRead(ISerialPort& port, uint32_t address, void* data, size_t dataLen, writeView.SetAddress(address + bytesGot); writeView.SetChunkSize(std::min(dataLen - bytesGot, chunkSize)); - if (port.Write((uint8_t*)&packet, sizeof(packet), timeout_ms) != sizeof(packet)) + if (port.Write(reinterpret_cast(&packet), sizeof(packet), timeout_ms) != sizeof(packet)) return -1; - if (port.Read((uint8_t*)&inPacket, sizeof(inPacket), timeout_ms) != sizeof(inPacket)) + if (port.Read(reinterpret_cast(&inPacket), sizeof(inPacket), timeout_ms) != sizeof(inPacket)) return -1; if (inPacket.status != STATUS_COMPLETED_CMD) diff --git a/src/utilities/rfTest.cpp b/src/utilities/rfTest.cpp index 3ab0c6d1a..008517f46 100644 --- a/src/utilities/rfTest.cpp +++ b/src/utilities/rfTest.cpp @@ -96,7 +96,7 @@ bool OnStreamStatusChange(bool isTx, const SDRDevice::StreamStats* s, void* user // s->isTx, don't care now if it's comming from Rx or Tx bool streamIssues = s->late | s->loss | s->overrun; if (userData) - *(bool*)userData = streamIssues; // report that there were issues with stream + *static_cast(userData) = streamIssues; // report that there were issues with stream return false; } @@ -148,11 +148,11 @@ bool FullStreamTxRx(SDRDevice& dev, bool MIMO) const int samplesInPkt = 256; //(stream.linkFormat == SDRDevice::StreamConfig::I12 ? 1360 : 1020)/channelCount; const float rxBufferTime = 0.002; // max buffer size in time (seconds) - const uint32_t samplesToBuffer = (int)(rxBufferTime * sampleRate / samplesInPkt) * samplesInPkt; + const uint32_t samplesToBuffer = static_cast(rxBufferTime * sampleRate / samplesInPkt) * samplesInPkt; assert(samplesToBuffer > 0); const float txTimeOffset = 0.005; // tx packets delay in time (seconds), will be rounded to even packets count - const int64_t txDeltaTS = (int)(txTimeOffset * sampleRate / samplesInPkt) * samplesInPkt; + const int64_t txDeltaTS = static_cast(txTimeOffset * sampleRate / samplesInPkt) * samplesInPkt; printf("TxDeltaTS +%li, (+%.3fms) %li packets\n", txDeltaTS, 1000.0 * txDeltaTS / sampleRate, txDeltaTS / samplesInPkt); // const int alignment = 4096; @@ -335,15 +335,15 @@ bool TxTiming(SDRDevice& dev, bool MIMO, float tsDelay_ms) const int samplesInPkt = (stream.linkFormat == SDRDevice::StreamConfig::DataFormat::I12 ? 1360 : 1020) / stream.rxCount; const float rxBufferTime = 0.005; // max buffer size in time (seconds) - const uint32_t samplesToBuffer = (int)(rxBufferTime * sampleRate / samplesInPkt) * samplesInPkt; + const uint32_t samplesToBuffer = static_cast(rxBufferTime * sampleRate / samplesInPkt) * samplesInPkt; assert(samplesToBuffer > 0); const float txTimeOffset = 0.001 * tsDelay_ms; // tx packets delay in time (seconds) - const int64_t txDeltaTS = (int)(txTimeOffset * sampleRate); + const int64_t txDeltaTS = static_cast(txTimeOffset * sampleRate); printf("\nusing TxOffsetTS +%li (%+.3fms) (%+.3f packets)\n", txDeltaTS, 1000.0 * txDeltaTS / sampleRate, - (float)txDeltaTS / samplesInPkt); + static_cast(txDeltaTS) / samplesInPkt); std::vector> rxSamples(2); // allocate two channels for simplicity for (uint i = 0; i < rxSamples.size(); ++i) From 6a1ca0909c709441e4223e92d08684bb85d7c47e Mon Sep 17 00:00:00 2001 From: Dominykas Date: Wed, 31 Jan 2024 11:27:22 +0200 Subject: [PATCH 04/13] Change the file extensions to match the way they are actually built --- src/CMakeLists.txt | 12 +++--------- ...002m_calibrations.c => lms7002m_calibrations.cpp} | 0 .../{lms7002m_controls.c => lms7002m_controls.cpp} | 0 .../{lms7002m_filters.c => lms7002m_filters.cpp} | 0 4 files changed, 3 insertions(+), 9 deletions(-) rename src/mcu_program/common_src/{lms7002m_calibrations.c => lms7002m_calibrations.cpp} (100%) rename src/mcu_program/common_src/{lms7002m_controls.c => lms7002m_controls.cpp} (100%) rename src/mcu_program/common_src/{lms7002m_filters.c => lms7002m_filters.cpp} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8cd98537..8eef44afe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,19 +57,13 @@ set(LIME_SUITE_SOURCES memory/MemoryPool.cpp mcu_program/spi.cpp - mcu_program/common_src/lms7002m_calibrations.c - mcu_program/common_src/lms7002m_controls.c - mcu_program/common_src/lms7002m_filters.c + mcu_program/common_src/lms7002m_calibrations.cpp + mcu_program/common_src/lms7002m_controls.cpp + mcu_program/common_src/lms7002m_filters.cpp API/LMS_APIWrapper.cpp ) -SET_SOURCE_FILES_PROPERTIES( - mcu_program/common_src/lms7002m_calibrations.c - mcu_program/common_src/lms7002m_controls.c - mcu_program/common_src/lms7002m_filters.c - PROPERTIES LANGUAGE CXX) - set(LIME_SUITE_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include diff --git a/src/mcu_program/common_src/lms7002m_calibrations.c b/src/mcu_program/common_src/lms7002m_calibrations.cpp similarity index 100% rename from src/mcu_program/common_src/lms7002m_calibrations.c rename to src/mcu_program/common_src/lms7002m_calibrations.cpp diff --git a/src/mcu_program/common_src/lms7002m_controls.c b/src/mcu_program/common_src/lms7002m_controls.cpp similarity index 100% rename from src/mcu_program/common_src/lms7002m_controls.c rename to src/mcu_program/common_src/lms7002m_controls.cpp diff --git a/src/mcu_program/common_src/lms7002m_filters.c b/src/mcu_program/common_src/lms7002m_filters.cpp similarity index 100% rename from src/mcu_program/common_src/lms7002m_filters.c rename to src/mcu_program/common_src/lms7002m_filters.cpp From 16cc771342fc5ce7b6998d6485ce0d878a725371 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Mon, 19 Feb 2024 13:56:09 +0200 Subject: [PATCH 05/13] Fix warnings in LMS7002M code --- src/lms7002m/LMS7002M.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index 53a5f25a3..08c924476 100644 --- a/src/lms7002m/LMS7002M.cpp +++ b/src/lms7002m/LMS7002M.cpp @@ -19,17 +19,18 @@ #include #include -#include "cpp-feather-ini-parser/INI.h" -#include "limesuite/IComms.h" -#include "limesuite/commonTypes.h" #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" #endif +#include "cpp-feather-ini-parser/INI.h" #include "lms_gfir.h" #ifdef __GNUC__ #pragma GCC diagnostic pop #endif + +#include "limesuite/commonTypes.h" +#include "limesuite/IComms.h" #include "LMS7002M_RegistersMap.h" #include "Logger.h" #include "mcu_programs.h" @@ -1765,9 +1766,9 @@ OpStatus LMS7002M::Modify_SPI_Reg_mask(const uint16_t* addr, const uint16_t* mas data.push_back(reg_data); ++start; } + status = SPI_write_batch(&addresses[0], &data[0], addresses.size()); if (status != OpStatus::SUCCESS) return status; - status = SPI_write_batch(&addresses[0], &data[0], addresses.size()); return status; } From 8b5a647513f97c77107d34f47351d50ae9602295 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Mon, 19 Feb 2024 13:58:37 +0200 Subject: [PATCH 06/13] Fix goto target clang-format --- src/mcu_program/common_src/lms7002m_calibrations.cpp | 4 ++-- src/mcu_program/common_src/lms7002m_filters.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mcu_program/common_src/lms7002m_calibrations.cpp b/src/mcu_program/common_src/lms7002m_calibrations.cpp index 5b7052d41..ad797e142 100644 --- a/src/mcu_program/common_src/lms7002m_calibrations.cpp +++ b/src/mcu_program/common_src/lms7002m_calibrations.cpp @@ -995,7 +995,7 @@ uint8_t CalibrateTx(bool extLoopback) CalibrateTxDCAuto(); SetNCOFrequency(LMS7002M_Rx, calibrationSXOffset_Hz - offsetNCO, 0); CalibrateIQImbalance(LMS7002M_Tx); -TxCalibrationEnd: { +TxCalibrationEnd : { //analog dc is not overwritten by chip state restore uint16_t gcorri = Get_SPI_Reg_bits(GCORRI_TXTSP); uint16_t gcorrq = Get_SPI_Reg_bits(GCORRQ_TXTSP); @@ -1495,7 +1495,7 @@ uint8_t CalibrateRx(bool extLoopback, bool dcOnly) Modify_SPI_Reg_bits(CMIX_BYP_RXTSP, 0); SetNCOFrequency(LMS7002M_Rx, bandwidthRF / calibUserBwDivider + offsetNCO, 0); CalibrateIQImbalance(LMS7002M_Rx); -RxCalibrationEndStage: { +RxCalibrationEndStage : { uint16_t gcorri = Get_SPI_Reg_bits(GCORRI_RXTSP); uint16_t gcorrq = Get_SPI_Reg_bits(GCORRQ_RXTSP); uint16_t phaseOffset = Get_SPI_Reg_bits(IQCORR_RXTSP); diff --git a/src/mcu_program/common_src/lms7002m_filters.cpp b/src/mcu_program/common_src/lms7002m_filters.cpp index 9a5843285..74cf002fa 100644 --- a/src/mcu_program/common_src/lms7002m_filters.cpp +++ b/src/mcu_program/common_src/lms7002m_filters.cpp @@ -501,7 +501,7 @@ uint8_t TuneRxFilter(const float_type rx_lpf_freq_RF) goto RxFilterSearchEndStage; } //END TIA -RxFilterSearchEndStage: { +RxFilterSearchEndStage : { //Restore settings uint16_t ccomp_cfb_tia_rfe = SPI_read(0x0112); uint16_t rcc_c_ctl_lpfl_rbb = SPI_read(0x0117); @@ -846,7 +846,7 @@ uint8_t TuneTxFilter(const float_type tx_lpf_freq_RF) Modify_SPI_Reg_bits(C_CTL_PGA_RBB, 2); status = SearchTxFilterCCAL_RCAL(RCAL_LPFH_TBB); } -TxFilterSearchEndStage: { +TxFilterSearchEndStage : { uint16_t ccal_lpflad_tbb = Get_SPI_Reg_bits(CCAL_LPFLAD_TBB); uint16_t rcal_lpfh_lpflad_tbb = SPI_read(0x0109); From 2af52a4a00e6e2b0ea60a85c226b467ef25899ca Mon Sep 17 00:00:00 2001 From: Dominykas Date: Thu, 22 Feb 2024 11:09:02 +0200 Subject: [PATCH 07/13] Clean up unnecessary casts --- amarisoft-plugin/trx_limesuite.cpp | 4 ++-- src/comms/PCIe/TRXLooper_PCIE.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/amarisoft-plugin/trx_limesuite.cpp b/amarisoft-plugin/trx_limesuite.cpp index dd334cdf6..abc66d48a 100644 --- a/amarisoft-plugin/trx_limesuite.cpp +++ b/amarisoft-plugin/trx_limesuite.cpp @@ -149,10 +149,10 @@ static_assert(sizeof(txGainTable) / sizeof(TxGainRow) == 51, "missing tx gains r static inline int64_t ts_to_time(int64_t fs, int64_t ts) { - int n, r; + int64_t n, r; n = (ts / fs); r = (ts % fs); - return static_cast(n) * 1000000 + ((static_cast(r) * 1000000) / fs); + return n * 1000000 + (r * 1000000 / fs); } struct PortChPair { diff --git a/src/comms/PCIe/TRXLooper_PCIE.cpp b/src/comms/PCIe/TRXLooper_PCIE.cpp index 0c0b81b7d..8f49be80b 100644 --- a/src/comms/PCIe/TRXLooper_PCIE.cpp +++ b/src/comms/PCIe/TRXLooper_PCIE.cpp @@ -82,10 +82,10 @@ class AvgRmsCounter static inline int64_t ts_to_us(int64_t fs, int64_t ts) { - int n, r; + int64_t n, r; n = (ts / fs); r = (ts % fs); - return static_cast(n) * 1000000 + ((static_cast(r) * 1000000) / fs); + return n * 1000000 + (r * 1000000 / fs); } TRXLooper_PCIE::TRXLooper_PCIE( From ea84d358347db37fca221177f3d08771750de8d5 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Thu, 22 Feb 2024 11:40:05 +0200 Subject: [PATCH 08/13] Removing functional-style casts, as they function exactly the same as C-style casts --- SoapyLMS7/Settings.cpp | 2 +- src/CDCM6208/CDCM6208_Dev.cpp | 2 +- src/DSP/Equalizer.cpp | 2 +- src/FPGA_common/FPGA_common.cpp | 28 ++++---- src/FPGAcontrols_wxgui/FPGAcontrols_wxgui.cpp | 4 +- src/Si5351C/Si5351C.cpp | 8 +-- src/boards/LimeSDR/LimeSDR.cpp | 12 ++-- src/boards/LimeSDR_Mini/FPGA_Mini.cpp | 10 +-- src/boards/LimeSDR_X3/LimeSDR_X3.cpp | 4 +- src/comms/PCIe/TRXLooper_PCIE.cpp | 6 +- src/lms7002m/LMS7002M.cpp | 66 +++++++++++-------- src/lms7002m/LMS7002M_RxTxCalibrations.cpp | 10 +-- src/lms7002m/MCU_File.cpp | 6 +- src/lms7suiteAppFrame.cpp | 2 +- src/oglGraph/OpenGLGraph.cpp | 4 +- src/protocols/LMS64CProtocol.cpp | 6 +- src/utilities/rfTest.cpp | 2 +- 17 files changed, 96 insertions(+), 78 deletions(-) diff --git a/SoapyLMS7/Settings.cpp b/SoapyLMS7/Settings.cpp index 425eba4fa..1e009898b 100644 --- a/SoapyLMS7/Settings.cpp +++ b/SoapyLMS7/Settings.cpp @@ -500,7 +500,7 @@ void SoapyLMS7::setSampleRate(const int direction, const size_t channel, const d throw std::runtime_error("SoapyLMS7::setSampleRate() failed with message " + std::string{ e.what() }); } - sampleRate[bool(direction)] = rate; + sampleRate[static_cast(direction)] = rate; return; } diff --git a/src/CDCM6208/CDCM6208_Dev.cpp b/src/CDCM6208/CDCM6208_Dev.cpp index d29cdaf38..2943adf73 100644 --- a/src/CDCM6208/CDCM6208_Dev.cpp +++ b/src/CDCM6208/CDCM6208_Dev.cpp @@ -740,7 +740,7 @@ int CDCM_Dev::SolveN(int Target, int* Mult8bit, int* Mult10bit) double res; for (int i10 = 1; i10 <= 1024; i10++) { - res = double(Target) / i10; + res = static_cast(Target) / i10; if (res < (1 << 8)) // Check max value { // Check if res is integer diff --git a/src/DSP/Equalizer.cpp b/src/DSP/Equalizer.cpp index 8098acacd..db5eca52b 100644 --- a/src/DSP/Equalizer.cpp +++ b/src/DSP/Equalizer.cpp @@ -102,7 +102,7 @@ void Equalizer::Configure(const Equalizer::Config& state) const Config::CFR& cfr = state.cfr[ch]; const Config::FIR& fir = state.fir[ch]; - const bool useOversample = std::min(cfr.interpolation, uint8_t(2)) != 1; + const bool useOversample = std::min(cfr.interpolation, 2) != 1; WriteRegister(TX_HB_BYP, !useOversample); WriteRegister(TX_HB_DEL, useOversample); diff --git a/src/FPGA_common/FPGA_common.cpp b/src/FPGA_common/FPGA_common.cpp index bffdf1d43..ce5813d9c 100644 --- a/src/FPGA_common/FPGA_common.cpp +++ b/src/FPGA_common/FPGA_common.cpp @@ -942,7 +942,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, double txPha const uint32_t addr = 0x002A; uint32_t val; - val = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFD; //msbit 1=SPI write + val = (1 << 31) | (0x0020u << 16) | 0xFFFD; //msbit 1=SPI write WriteLMS7002MSPI(&val, 1); ReadLMS7002MSPI(&addr, &val, 1); bool bypassTx = (val & 0xF0) == 0x00; @@ -1023,7 +1023,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde dataWr[0] = 0x0020; ReadLMS7002MSPI(dataWr.data(), ®20, 1); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFD; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFD; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); ReadLMS7002MSPI(spiAddr.data(), dataRdA.data(), bakRegCnt); @@ -1036,7 +1036,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde bypassRx = (val & 0x0F) == 0x0D; } - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFE; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFE; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); for (int i = 0; i < bakRegCnt; ++i) @@ -1044,7 +1044,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde dataRdB.push_back(spiAddr[i]); ReadLMS7002MSPI(dataRdB.data(), dataRdB.data(), dataRdB.size()); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFF; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFF; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); { @@ -1056,7 +1056,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde //Load test config const int setRegCnt = spiData.size(); for (int i = 0; i < setRegCnt; ++i) - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | spiData[i]; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), setRegCnt); } @@ -1107,7 +1107,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde //Load test config const int setRegCnt = spiData.size(); for (int i = 0; i < setRegCnt; ++i) - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | spiData[i]; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), setRegCnt); } @@ -1146,23 +1146,23 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde } //Restore registers - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFD; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFD; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); for (int i = 0; i < bakRegCnt; ++i) - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | dataRdA[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | dataRdA[i]; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), bakRegCnt); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFE; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFE; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); int k = 0; for (int i = 0; i < bakRegCnt; ++i) if (spiAddr[i] >= 0x100) { - dataWr[k] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | dataRdB[k]; //msbit 1=SPI write + dataWr[k] = (1 << 31) | (spiAddr[i] << 16) | dataRdB[k]; //msbit 1=SPI write k++; } WriteLMS7002MSPI(dataWr.data(), k); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | reg20; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | reg20; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); WriteRegister(0x000A, reg_000A); return status; @@ -1255,9 +1255,9 @@ FPGA::GatewareInfo FPGA::GetGatewareInfo() void FPGA::GatewareToDescriptor(const FPGA::GatewareInfo& gw, SDRDevice::Descriptor& desc) { desc.gatewareTargetBoard = GetDeviceName(eLMS_DEV(gw.boardID)); - desc.gatewareVersion = std::to_string(int(gw.version)); - desc.gatewareRevision = std::to_string(int(gw.revision)); - desc.hardwareVersion = std::to_string(int(gw.hardwareVersion)); + desc.gatewareVersion = std::to_string(gw.version); + desc.gatewareRevision = std::to_string(gw.revision); + desc.hardwareVersion = std::to_string(gw.hardwareVersion); } } //namespace lime diff --git a/src/FPGAcontrols_wxgui/FPGAcontrols_wxgui.cpp b/src/FPGAcontrols_wxgui/FPGAcontrols_wxgui.cpp index 1ea439172..ef3993eaa 100644 --- a/src/FPGAcontrols_wxgui/FPGAcontrols_wxgui.cpp +++ b/src/FPGAcontrols_wxgui/FPGAcontrols_wxgui.cpp @@ -320,7 +320,9 @@ int FPGAcontrols_wxgui::UploadFile(std::vector isamples, std::vector fifoSize / 2 ? fifoSize / 2 : buffer.size(); - lms_stream_t tx_stream = { 0, true, uint32_t(cmbDevice->GetSelection() * 2), fifoSize, 0.5, lms_stream_t::LMS_FMT_I16 }; + lms_stream_t tx_stream = { + 0, true, static_cast(cmbDevice->GetSelection() * 2), fifoSize, 0.5, lms_stream_t::LMS_FMT_I16 + }; if (LMS_SetupStream(lmsControl, &tx_stream) != 0) { evt = new wxCommandEvent(UPDATE_STATUS); diff --git a/src/Si5351C/Si5351C.cpp b/src/Si5351C/Si5351C.cpp index e68c3ea8c..7fa913d77 100644 --- a/src/Si5351C/Si5351C.cpp +++ b/src/Si5351C/Si5351C.cpp @@ -534,12 +534,12 @@ Si5351C::Status Si5351C::UploadConfiguration() std::vector outBuffer; //Disable outputs outBuffer.push_back(3); - outBuffer.push_back(uint8_t(0xFF)); + outBuffer.push_back(0xFF); //Power down all output drivers for (int i = 0; i < 8; ++i) { outBuffer.push_back(16 + i); - outBuffer.push_back(uint8_t(0x84)); + outBuffer.push_back(0x84); } //write new configuration for (int i = 15; i <= 92; ++i) @@ -553,8 +553,8 @@ Si5351C::Status Si5351C::UploadConfiguration() outBuffer.push_back(m_newConfiguration[i]); } //apply soft reset - outBuffer.push_back(uint8_t(177)); - outBuffer.push_back(uint8_t(0xAC)); + outBuffer.push_back(0XB1); + outBuffer.push_back(0xAC); //Enabe desired outputs outBuffer.push_back(3); outBuffer.push_back(m_newConfiguration[3]); diff --git a/src/boards/LimeSDR/LimeSDR.cpp b/src/boards/LimeSDR/LimeSDR.cpp index 8affef4e6..768c71a82 100644 --- a/src/boards/LimeSDR/LimeSDR.cpp +++ b/src/boards/LimeSDR/LimeSDR.cpp @@ -393,9 +393,9 @@ SDRDevice::Descriptor LimeSDR::GetDeviceInfo(void) deviceDescriptor.name = GetDeviceName(static_cast(info.deviceId)); deviceDescriptor.expansionName = GetExpansionBoardName(static_cast(info.expansionBoardId)); - deviceDescriptor.firmwareVersion = std::to_string(int(info.firmware)); - deviceDescriptor.hardwareVersion = std::to_string(int(info.hardware)); - deviceDescriptor.protocolVersion = std::to_string(int(info.protocol)); + deviceDescriptor.firmwareVersion = std::to_string(info.firmware); + deviceDescriptor.hardwareVersion = std::to_string(info.hardware); + deviceDescriptor.protocolVersion = std::to_string(info.protocol); deviceDescriptor.serialNumber = info.boardSerialNumber; const uint32_t addrs[] = { 0x0000, 0x0001, 0x0002, 0x0003 }; @@ -407,9 +407,9 @@ SDRDevice::Descriptor LimeSDR::GetDeviceInfo(void) auto hwVersion = data[3] & 0x7F; //pkt.inBuffer[15]&0x7F; deviceDescriptor.gatewareTargetBoard = GetDeviceName(boardID); - deviceDescriptor.gatewareVersion = std::to_string(int(gatewareVersion)); - deviceDescriptor.gatewareRevision = std::to_string(int(gatewareRevision)); - deviceDescriptor.hardwareVersion = std::to_string(int(hwVersion)); + deviceDescriptor.gatewareVersion = std::to_string(gatewareVersion); + deviceDescriptor.gatewareRevision = std::to_string(gatewareRevision); + deviceDescriptor.hardwareVersion = std::to_string(hwVersion); return deviceDescriptor; } diff --git a/src/boards/LimeSDR_Mini/FPGA_Mini.cpp b/src/boards/LimeSDR_Mini/FPGA_Mini.cpp index 1b13be3cb..0bbd54dcd 100644 --- a/src/boards/LimeSDR_Mini/FPGA_Mini.cpp +++ b/src/boards/LimeSDR_Mini/FPGA_Mini.cpp @@ -90,7 +90,7 @@ OpStatus FPGA_Mini::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int cha //backup registers dataWr[0] = 0x0020; lms7002mPort->SPI(dataWr.data(), ®20, 1); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFD; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFD; //msbit 1=SPI write lms7002mPort->SPI(dataWr.data(), nullptr, 1); lms7002mPort->SPI(spiAddr.data(), dataRd.data(), bakRegCnt); @@ -102,7 +102,7 @@ OpStatus FPGA_Mini::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int cha for (int i = 0; i < setRegCnt; ++i) { - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | spiData[i]; //msbit 1=SPI write } lms7002mPort->SPI(dataWr.data(), nullptr, setRegCnt); @@ -137,7 +137,7 @@ OpStatus FPGA_Mini::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int cha for (int i = 0; i < setRegCnt; ++i) { - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | spiData[i]; //msbit 1=SPI write } lms7002mPort->SPI(dataWr.data(), nullptr, setRegCnt); @@ -172,12 +172,12 @@ OpStatus FPGA_Mini::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int cha //Restore registers for (int i = 0; i < bakRegCnt; ++i) { - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | dataRd[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | dataRd[i]; //msbit 1=SPI write } lms7002mPort->SPI(dataWr.data(), nullptr, bakRegCnt); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | reg20; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | reg20; //msbit 1=SPI write lms7002mPort->SPI(dataWr.data(), nullptr, 1); WriteRegister(0x000A, 0); diff --git a/src/boards/LimeSDR_X3/LimeSDR_X3.cpp b/src/boards/LimeSDR_X3/LimeSDR_X3.cpp index 26f6f2b16..3963c910e 100644 --- a/src/boards/LimeSDR_X3/LimeSDR_X3.cpp +++ b/src/boards/LimeSDR_X3/LimeSDR_X3.cpp @@ -741,7 +741,7 @@ void LimeSDR_X3::SetLMSPath(const TRXDir dir, const SDRDevice::ChannelConfig::Di } else { - path = (dir == TRXDir::Rx) ? uint8_t(ePathLMS2_Rx::NONE) : uint8_t(ePathLMS2_Tx::NONE); + path = (dir == TRXDir::Rx) ? static_cast(ePathLMS2_Rx::NONE) : static_cast(ePathLMS2_Tx::NONE); } LMS2SetPath(dir, ch, path); @@ -1211,7 +1211,7 @@ void LimeSDR_X3::LMS2_SetSampleRate(double f_Hz, uint8_t oversample) double txClock = f_Hz; // Oversample is available only to Tx for LMS#2 - oversample = std::min(oversample, uint8_t(2)); + oversample = std::min(oversample, 2); if (oversample == 2 || oversample == 0) // 0 is "auto", use max oversample txClock *= 2; diff --git a/src/comms/PCIe/TRXLooper_PCIE.cpp b/src/comms/PCIe/TRXLooper_PCIE.cpp index 8f49be80b..db9dfad4a 100644 --- a/src/comms/PCIe/TRXLooper_PCIE.cpp +++ b/src/comms/PCIe/TRXLooper_PCIE.cpp @@ -204,7 +204,7 @@ int TRXLooper_PCIE::TxSetup() mTxArgs.packetsToBatch = mTx.packetsToBatch; mTxArgs.samplesInPacket = samplesInPkt; - float bufferTimeDuration = float(samplesInPkt * mTx.packetsToBatch) / mConfig.hintSampleRate; + float bufferTimeDuration = samplesInPkt * mTx.packetsToBatch / mConfig.hintSampleRate; if (mCallback_logMessage) { char msg[256]; @@ -733,7 +733,7 @@ int TRXLooper_PCIE::RxSetup() float bufferTimeDuration = 0; if (mConfig.hintSampleRate > 0) { - bufferTimeDuration = float(samplesInPkt * mRx.packetsToBatch) / mConfig.hintSampleRate; + bufferTimeDuration = samplesInPkt * mRx.packetsToBatch / mConfig.hintSampleRate; irqPeriod = 80e-6 / bufferTimeDuration; } irqPeriod = std::clamp(irqPeriod, 1, 16); @@ -835,7 +835,7 @@ void TRXLooper_PCIE::ReceivePacketsLoop() dma = mRxArgs.port->GetRxDMAState(); if (dma.hwIndex != lastHwIndex) { - const int bytesTransferred = uint16_t(dma.hwIndex - lastHwIndex) * readSize; + const int bytesTransferred = (dma.hwIndex - lastHwIndex) * readSize; Bps += bytesTransferred; stats.bytesTransferred += bytesTransferred; lastHwIndex = dma.hwIndex; diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index 945bdf937..1a11ddea0 100644 --- a/src/lms7002m/LMS7002M.cpp +++ b/src/lms7002m/LMS7002M.cpp @@ -500,14 +500,16 @@ OpStatus LMS7002M::LoadConfigLegacyFile(const std::string& filename) typedef INI ini_t; ini_t parser(filename, true); if (parser.select("FILE INFO") == false) - return ReportError(OpStatus::INVALID_VALUE, "LoadConfigLegacyFile(%s) - invalid format, missing FILE INFO section", filename.c_str()); + return ReportError( + OpStatus::INVALID_VALUE, "LoadConfigLegacyFile(%s) - invalid format, missing FILE INFO section", filename.c_str()); std::string type = ""; type = parser.get("type", "undefined"); if (type.find("LMS7002 configuration") == std::string::npos) { - return ReportError(OpStatus::INVALID_VALUE, "LoadConfigLegacyFile(%s) - invalid format, missing LMS7002 configuration", filename.c_str()); + return ReportError( + OpStatus::INVALID_VALUE, "LoadConfigLegacyFile(%s) - invalid format, missing LMS7002 configuration", filename.c_str()); } int fileVersion = 0; @@ -696,7 +698,8 @@ OpStatus LMS7002M::LoadConfig(const std::string& filename, bool tuneDynamicValue if (type.find("lms7002m_minimal_config") == std::string::npos) { - return ReportError(OpStatus::INVALID_VALUE, "LoadConfig(%s) - invalid format, missing lms7002m_minimal_config", filename.c_str()); + return ReportError( + OpStatus::INVALID_VALUE, "LoadConfig(%s) - invalid format, missing lms7002m_minimal_config", filename.c_str()); } int fileVersion = 0; @@ -797,7 +800,10 @@ OpStatus LMS7002M::ResetLogicregisters() { const uint16_t x0020_value = SPI_read(0x0020); //reset logic registers const uint16_t addr[] = { 0x0020, 0x0020 }; - const uint16_t values[] = { uint16_t(x0020_value & 0x553F), uint16_t(x0020_value | 0xFFC0) }; + const uint16_t values[] = { + static_cast(x0020_value & 0x553F), + static_cast(x0020_value | 0xFFC0), + }; //const uint16_t values[] = {x0020_value & 0x55FF, x0020_value | 0xFF00}; // LRST_TX_B, LRST_TX_A, LRST_RX_B, LRST_RX_A return SPI_write_batch(addr, values, 2); @@ -1736,7 +1742,8 @@ OpStatus LMS7002M::Modify_SPI_Reg_bits(const LMS7Parameter& param, const uint16_ @param value new bits value, the value is shifted left by lsb bits @param fromChip read initial value directly from chip */ -OpStatus LMS7002M::Modify_SPI_Reg_bits(const uint16_t address, const uint8_t msb, const uint8_t lsb, const uint16_t value, bool fromChip) +OpStatus LMS7002M::Modify_SPI_Reg_bits( + const uint16_t address, const uint8_t msb, const uint8_t lsb, const uint16_t value, bool fromChip) { uint16_t spiDataReg = SPI_read(address, fromChip); //read current SPI reg data uint16_t spiMask = (~(~0u << (msb - lsb + 1))) << (lsb); // creates bit mask @@ -1751,7 +1758,8 @@ OpStatus LMS7002M::Modify_SPI_Reg_bits(const uint16_t address, const uint8_t msb @param start starting index of given arrays @param stop end index of given arrays */ -OpStatus LMS7002M::Modify_SPI_Reg_mask(const uint16_t* addr, const uint16_t* masks, const uint16_t* values, uint8_t start, uint8_t stop) +OpStatus LMS7002M::Modify_SPI_Reg_mask( + const uint16_t* addr, const uint16_t* masks, const uint16_t* values, uint8_t start, uint8_t stop) { OpStatus status = OpStatus::SUCCESS; uint16_t reg_data; @@ -1906,7 +1914,10 @@ OpStatus LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* ou { tuneScore[sel_vco] = -128 + Get_SPI_Reg_bits(LMS7param(CSW_VCO), true); canDeliverFrequency = true; - lime::debug("%s : csw=%d %s", vcoNames[sel_vco], tuneScore[sel_vco] + 128, (status == OpStatus::SUCCESS ? "tune ok" : "tune fail")); + lime::debug("%s : csw=%d %s", + vcoNames[sel_vco], + tuneScore[sel_vco] + 128, + (status == OpStatus::SUCCESS ? "tune ok" : "tune fail")); } else { @@ -1959,7 +1970,8 @@ OpStatus LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* ou this->SetActiveChannel(ch); //restore used channel if (canDeliverFrequency == false) - return ReportError(OpStatus::ERROR, "SetFrequencySX%s(%g MHz) - cannot deliver frequency", dir == TRXDir::Tx ? "T" : "R", freq_Hz / 1e6); + return ReportError( + OpStatus::ERROR, "SetFrequencySX%s(%g MHz) - cannot deliver frequency", dir == TRXDir::Tx ? "T" : "R", freq_Hz / 1e6); return OpStatus::SUCCESS; } @@ -2063,16 +2075,16 @@ float_type LMS7002M::GetFrequencySX(TRXDir dir) OpStatus LMS7002M::SetNCOFrequency(TRXDir dir, uint8_t index, float_type freq_Hz) { if (index > 15) - return ReportError(OpStatus::INVALID_VALUE, "SetNCOFrequency(index = %d) - index out of range [0, 15]", int(index)); + return ReportError(OpStatus::INVALID_VALUE, "SetNCOFrequency(index = %d) - index out of range [0, 15]", index); float_type refClk_Hz = GetReferenceClk_TSP(dir); if (freq_Hz < 0 || freq_Hz / refClk_Hz > 0.5) return ReportError(OpStatus::OUT_OF_RANGE, "SetNCOFrequency(index = %d) - Frequency(%g MHz) out of range [0-%g) MHz", - int(index), + index, freq_Hz / 1e6, refClk_Hz / 2e6); uint16_t addr = dir == TRXDir::Tx ? 0x0240 : 0x0440; - uint32_t fcw = uint32_t((freq_Hz / refClk_Hz) * 4294967296); + uint32_t fcw = static_cast((freq_Hz / refClk_Hz) * 4294967296); SPI_write(addr + 2 + index * 2, (fcw >> 16)); //NCO frequency control word register MSB part. SPI_write(addr + 3 + index * 2, fcw); //NCO frequency control word register LSB part. return OpStatus::SUCCESS; @@ -2087,7 +2099,7 @@ OpStatus LMS7002M::SetNCOFrequency(TRXDir dir, uint8_t index, float_type freq_Hz float_type LMS7002M::GetNCOFrequency(TRXDir dir, uint8_t index, bool fromChip) { if (index > 15) - return ReportError(ERANGE, "GetNCOFrequency_MHz(index = %d) - index out of range [0, 15]", int(index)); + return ReportError(ERANGE, "GetNCOFrequency_MHz(index = %d) - index out of range [0, 15]", index); float_type refClk_Hz = GetReferenceClk_TSP(dir); uint16_t addr = dir == TRXDir::Tx ? 0x0240 : 0x0440; uint32_t fcw = 0; @@ -2118,7 +2130,7 @@ OpStatus LMS7002M::SetNCOPhaseOffsetForMode0(TRXDir dir, float_type angle_deg) OpStatus LMS7002M::SetNCOPhaseOffset(TRXDir dir, uint8_t index, float_type angle_deg) { if (index > 15) - return ReportError(OpStatus::INVALID_VALUE, "SetNCOPhaseOffset(index = %d) - index out of range [0, 15]", int(index)); + return ReportError(OpStatus::INVALID_VALUE, "SetNCOPhaseOffset(index = %d) - index out of range [0, 15]", index); uint16_t addr = dir == TRXDir::Tx ? 0x0244 : 0x0444; uint16_t pho = static_cast(65536 * (angle_deg / 360)); SPI_write(addr + index, pho); @@ -2158,7 +2170,7 @@ std::vector LMS7002M::GetNCOPhases(TRXDir dir, float_type* frequency float_type LMS7002M::GetNCOPhaseOffset_Deg(TRXDir dir, uint8_t index) { if (index > 15) - return ReportError(ERANGE, "GetNCOPhaseOffset_Deg(index = %d) - index out of range [0, 15]", int(index)); + return ReportError(ERANGE, "GetNCOPhaseOffset_Deg(index = %d) - index out of range [0, 15]", index); uint16_t addr = dir == TRXDir::Tx ? 0x0244 : 0x0444; uint16_t pho = SPI_read(addr + index); float_type angle = 360 * pho / 65536.0; @@ -2253,7 +2265,8 @@ OpStatus LMS7002M::GetGFIRCoefficients(TRXDir dir, uint8_t gfirIndex, float_type if (coefCount > coefLimit) { - return ReportError(OpStatus::OUT_OF_RANGE, "GetGFIRCoefficients(coefCount=%d) - exceeds coefLimit=%d", coefCount, coefLimit); + return ReportError( + OpStatus::OUT_OF_RANGE, "GetGFIRCoefficients(coefCount=%d) - exceeds coefLimit=%d", coefCount, coefLimit); } std::vector addresses; @@ -2415,7 +2428,7 @@ OpStatus LMS7002M::SPI_write_batch(const uint16_t* spiAddr, const uint16_t* spiD continue; } - data.push_back((1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]); //msbit 1=SPI write + data.push_back((1 << 31) | (static_cast(spiAddr[i]) << 16) | spiData[i]); //msbit 1=SPI write if (wr0) mRegistersMap->SetValue(0, spiAddr[i], spiData[i]); if (wr1) @@ -2763,7 +2776,7 @@ bool LMS7002M::IsSynced() std::vector dataWr(addrToRead.size()); std::vector dataRd(addrToRead.size()); for (size_t i = 0; i < addrToRead.size(); ++i) - dataWr[i] = (uint32_t(addrToRead[i]) << 16); + dataWr[i] = (static_cast(addrToRead[i]) << 16); controlPort->SPI(dataWr.data(), dataRd.data(), dataWr.size()); for (size_t i = 0; i < addrToRead.size(); ++i) @@ -2800,7 +2813,7 @@ bool LMS7002M::IsSynced() dataWr.resize(addrToRead.size()); dataRd.resize(addrToRead.size()); for (size_t i = 0; i < addrToRead.size(); ++i) - dataWr[i] = (uint32_t(addrToRead[i]) << 16); + dataWr[i] = (static_cast(addrToRead[i]) << 16); controlPort->SPI(dataWr.data(), dataRd.data(), dataWr.size()); for (size_t i = 0; i < addrToRead.size(); ++i) dataReceived[i] = dataRd[i] & 0xFFFF; @@ -3092,8 +3105,8 @@ void LMS7002M::GetDCOffset(TRXDir dir, float_type& I, float_type& Q) { if (dir == TRXDir::Tx) { - I = int8_t(this->Get_SPI_Reg_bits(LMS7param(DCCORRI_TXTSP))) / 127.0; //signed 8-bit - Q = int8_t(this->Get_SPI_Reg_bits(LMS7param(DCCORRQ_TXTSP))) / 127.0; //signed 8-bit + I = static_cast(this->Get_SPI_Reg_bits(LMS7param(DCCORRI_TXTSP))) / 127.0; //signed 8-bit + Q = static_cast(this->Get_SPI_Reg_bits(LMS7param(DCCORRQ_TXTSP))) / 127.0; //signed 8-bit } else { @@ -3122,12 +3135,13 @@ OpStatus LMS7002M::SetIQBalance(const TRXDir dir, const float_type phase, const void LMS7002M::GetIQBalance(const TRXDir dir, float_type& phase, float_type& gainI, float_type& gainQ) { - int iqcorr = int16_t(this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(IQCORR_TXTSP) : LMS7param(IQCORR_RXTSP)) << 4) >> - 4; //sign extend 12-bit - int gcorri = - int16_t(this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(GCORRI_TXTSP) : LMS7param(GCORRI_RXTSP))); //unsigned 11-bit - int gcorrq = - int16_t(this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(GCORRQ_TXTSP) : LMS7param(GCORRQ_RXTSP))); //unsigned 11-bit + int iqcorr = + static_cast(this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(IQCORR_TXTSP) : LMS7param(IQCORR_RXTSP)) << 4) >> + 4; //sign extend 12-bit + int gcorri = static_cast( + this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(GCORRI_TXTSP) : LMS7param(GCORRI_RXTSP))); //unsigned 11-bit + int gcorrq = static_cast( + this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(GCORRQ_TXTSP) : LMS7param(GCORRQ_RXTSP))); //unsigned 11-bit phase = (M_PI / 2) * iqcorr / 2047.0; gainI = gcorri / 2047.0; diff --git a/src/lms7002m/LMS7002M_RxTxCalibrations.cpp b/src/lms7002m/LMS7002M_RxTxCalibrations.cpp index 2a48bb407..f8709f6e6 100644 --- a/src/lms7002m/LMS7002M_RxTxCalibrations.cpp +++ b/src/lms7002m/LMS7002M_RxTxCalibrations.cpp @@ -60,8 +60,8 @@ static uint8_t GetExtLoopPair(lime::LMS7002M& ctr, bool calibratingTx) */ static inline int16_t signextIqCorr(const uint16_t regVal) { - int16_t signedPhase = int16_t(regVal << 4); - return int16_t(signedPhase) >> 4; + int16_t signedPhase = static_cast(regVal << 4); + return signedPhase >> 4; } const double TrxCalib_RF_LimitLow = 2.5e6; @@ -240,7 +240,8 @@ OpStatus LMS7002M::CalibrateTx(float_type bandwidth_Hz, bool useExtLoopback) mcuControl->RunProcedure(useExtLoopback ? MCU_FUNCTION_CALIBRATE_TX_EXTLOOPB : MCU_FUNCTION_CALIBRATE_TX); status = mcuControl->WaitForMCU(1000); if (status != MCU_BD::MCU_NO_ERROR) - return ReportError(OpStatus::INVALID_VALUE, "Tx Calibration: MCU error %i (%s)", status, MCU_BD::MCUStatusMessage(status)); + return ReportError( + OpStatus::INVALID_VALUE, "Tx Calibration: MCU error %i (%s)", status, MCU_BD::MCUStatusMessage(status)); } //sync registers to cache @@ -360,7 +361,8 @@ OpStatus LMS7002M::CalibrateRx(float_type bandwidth_Hz, bool useExtLoopback) mcuControl->RunProcedure(useExtLoopback ? MCU_FUNCTION_CALIBRATE_RX_EXTLOOPB : MCU_FUNCTION_CALIBRATE_RX); int status = mcuControl->WaitForMCU(1000); if (status != MCU_BD::MCU_NO_ERROR) - return ReportError(OpStatus::INVALID_VALUE, "Rx calibration: MCU error %i (%s)", status, MCU_BD::MCUStatusMessage(status)); + return ReportError( + OpStatus::INVALID_VALUE, "Rx calibration: MCU error %i (%s)", status, MCU_BD::MCUStatusMessage(status)); } //sync registers to cache diff --git a/src/lms7002m/MCU_File.cpp b/src/lms7002m/MCU_File.cpp index be0c0688e..fee938d47 100644 --- a/src/lms7002m/MCU_File.cpp +++ b/src/lms7002m/MCU_File.cpp @@ -335,7 +335,7 @@ void MCU_File::ReadHex(unsigned long limit) { char header[256]; uint8_t i = 0; - for (i = 0; uint8_t(i + 3) < count; ++i) + for (i = 0; static_cast(i + 3) < count; ++i) { sscanf(&szLine[8 + i * 2], "%2lx", &tmp); header[i] = static_cast(tmp); @@ -373,8 +373,8 @@ void MCU_File::ReadHex(unsigned long limit) m_chunks.push_back(MemBlock()); m_chunks.back().m_startAddress = startAddress; } - unsigned char i = 0; - for (i = uint8_t(type - '1'); uint8_t(i + 3) < count; ++i) + uint8_t i = 0; + for (i = static_cast(type - '1'); static_cast(i + 3) < count; ++i) { sscanf(&szLine[8 + i * 2], "%2lx", &tmp); if (startAddress + i > limit) diff --git a/src/lms7suiteAppFrame.cpp b/src/lms7suiteAppFrame.cpp index f7a78e7f4..779cf243e 100644 --- a/src/lms7suiteAppFrame.cpp +++ b/src/lms7suiteAppFrame.cpp @@ -59,7 +59,7 @@ void LMS7SuiteAppFrame::OnGlobalLogEvent(const lime::LogLevel level, const char* wxCommandEvent evt; evt.SetString(wxString::FromAscii(message)); evt.SetEventType(LOG_MESSAGE); - evt.SetInt(int(level)); + evt.SetInt(static_cast(level)); wxPostEvent(obj_ptr, evt); } diff --git a/src/oglGraph/OpenGLGraph.cpp b/src/oglGraph/OpenGLGraph.cpp index af9a38d17..8a375f09e 100644 --- a/src/oglGraph/OpenGLGraph.cpp +++ b/src/oglGraph/OpenGLGraph.cpp @@ -594,7 +594,7 @@ void OpenGLGraph::CalculateGrid() } while (interval / divisor > 10 * xlines) divisor *= 10; - settings.gridXspacing = divisor * mult[int(0.5f + interval / xlines / divisor)]; + settings.gridXspacing = divisor * mult[static_cast(0.5f + interval / xlines / divisor)]; settings.gridXstart = static_cast(settings.visibleArea.x1 / settings.gridXspacing) * settings.gridXspacing; } else @@ -614,7 +614,7 @@ void OpenGLGraph::CalculateGrid() } while (interval / divisor > 10 * ylines) divisor *= 10; - settings.gridYspacing = divisor * mult[int(0.5f + interval / ylines / divisor)]; + settings.gridYspacing = divisor * mult[static_cast(0.5f + interval / ylines / divisor)]; settings.gridYstart = static_cast(settings.visibleArea.y1 / settings.gridYspacing) * settings.gridYspacing; } else diff --git a/src/protocols/LMS64CProtocol.cpp b/src/protocols/LMS64CProtocol.cpp index f7f7c4808..57b28cb1b 100644 --- a/src/protocols/LMS64CProtocol.cpp +++ b/src/protocols/LMS64CProtocol.cpp @@ -238,9 +238,9 @@ void FirmwareToDescriptor(const FirmwareInfo& fw, SDRDevice::Descriptor& descrip } else descriptor.expansionName = GetExpansionBoardName(static_cast(fw.expansionBoardId)); - descriptor.firmwareVersion = std::to_string(int(fw.firmware)); - descriptor.hardwareVersion = std::to_string(int(fw.hardware)); - descriptor.protocolVersion = std::to_string(int(fw.protocol)); + descriptor.firmwareVersion = std::to_string(fw.firmware); + descriptor.hardwareVersion = std::to_string(fw.hardware); + descriptor.protocolVersion = std::to_string(fw.protocol); descriptor.serialNumber = fw.boardSerialNumber; } diff --git a/src/utilities/rfTest.cpp b/src/utilities/rfTest.cpp index 92df59899..b6ddde260 100644 --- a/src/utilities/rfTest.cpp +++ b/src/utilities/rfTest.cpp @@ -454,7 +454,7 @@ bool TxTiming(SDRDevice& dev, bool MIMO, float tsDelay_ms) txMeta.timestamp, diff, 1000.0 * diff / sampleRate, - float(diff) / samplesInPkt); + static_cast(diff) / samplesInPkt); txPending = false; done = true; break; From b9afd149eb2f5390137632f0ed4c45575fc3a41f Mon Sep 17 00:00:00 2001 From: Dominykas Date: Thu, 22 Feb 2024 12:11:44 +0200 Subject: [PATCH 09/13] Fix a round being used where it actually wasn't a round --- src/lms7002m/LMS7002M.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index 1a11ddea0..042a14b44 100644 --- a/src/lms7002m/LMS7002M.cpp +++ b/src/lms7002m/LMS7002M.cpp @@ -1996,7 +1996,7 @@ OpStatus LMS7002M::SetFrequencySXWithSpurCancelation(TRXDir dir, float_type freq float newFreq(0); if (needCancelation) { - newFreq = std::round(freq_Hz / refClk) * refClk; + newFreq = static_cast(freq_Hz / refClk + 0.5) * refClk; TuneRxFilter(BW - BWOffset + 2 * abs(freq_Hz - newFreq)); status = SetFrequencySX(dir, newFreq); } From 974e053c70e60cef949af2bcf78b4581d79d9350 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Thu, 22 Feb 2024 12:14:57 +0200 Subject: [PATCH 10/13] Fix extraneous reorder in LMS7002M code --- src/lms7002m/LMS7002M.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index 042a14b44..12af82f4c 100644 --- a/src/lms7002m/LMS7002M.cpp +++ b/src/lms7002m/LMS7002M.cpp @@ -1774,9 +1774,9 @@ OpStatus LMS7002M::Modify_SPI_Reg_mask( data.push_back(reg_data); ++start; } - status = SPI_write_batch(&addresses[0], &data[0], addresses.size()); if (status != OpStatus::SUCCESS) return status; + status = SPI_write_batch(&addresses[0], &data[0], addresses.size()); return status; } From de0e634cc385e0562097c5d99c97b16b5e8f4a20 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Thu, 22 Feb 2024 13:18:18 +0200 Subject: [PATCH 11/13] Wrap GLEW version checks into a function --- src/oglGraph/GLFont.cpp | 52 +++++++++++++----------------------- src/oglGraph/OpenGLGraph.cpp | 21 +++++++++------ 2 files changed, 31 insertions(+), 42 deletions(-) diff --git a/src/oglGraph/GLFont.cpp b/src/oglGraph/GLFont.cpp index a3572a8e6..cf638f1c5 100644 --- a/src/oglGraph/GLFont.cpp +++ b/src/oglGraph/GLFont.cpp @@ -6,6 +6,18 @@ #include using namespace std; +static constexpr bool IsGlew1_5() +{ +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + return GLEW_VERSION_1_5; +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif +} + /** @brief Construct a new GLFont::GLFont object */ GLFont::GLFont() : m_texID(0) @@ -119,14 +131,7 @@ bool GLFont::load(const char* file) glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, texWidth, texHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap); glBindTexture(GL_TEXTURE_2D, 0); -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - if (!m_vboID && GLEW_VERSION_1_5) -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif + if (!m_vboID && IsGlew1_5()) { glGenBuffers(1, &m_vboID); glBindBuffer(GL_ARRAY_BUFFER, m_vboID); @@ -216,14 +221,7 @@ bool GLFont::loadFromArray(const char* array, unsigned int size) glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, texWidth, texHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap); glBindTexture(GL_TEXTURE_2D, 0); -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - if (!m_vboID && GLEW_VERSION_1_5) -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif + if (!m_vboID && IsGlew1_5()) { glGenBuffers(1, &m_vboID); glBindBuffer(GL_ARRAY_BUFFER, m_vboID); @@ -260,14 +258,7 @@ void GLFont::render_textWorldSpace(const char* text, float x, float y, float fon GLGlyph* g = NULL; glBindTexture(GL_TEXTURE_2D, m_texID); -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - if (GLEW_VERSION_1_5) -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif + if (IsGlew1_5()) { glBindBuffer(GL_ARRAY_BUFFER, m_vboID); } @@ -307,7 +298,7 @@ void GLFont::render_textWorldSpace(const char* text, float x, float y, float fon vbodata[14] = vbodata[6]; vbodata[15] = vbodata[11]; - // if(GLEW_VERSION_1_5) + // if(IsGlew1_5()) // { // glBufferData( GL_ARRAY_BUFFER, 16*sizeof(float), NULL, GL_DYNAMIC_DRAW ); // glBufferData( GL_ARRAY_BUFFER, 16*sizeof(float), vbodata, GL_DYNAMIC_DRAW ); @@ -360,14 +351,7 @@ void GLFont::render_textScreenSpace(const char* text, float x, float y, float fo GLGlyph* g = NULL; glBindTexture(GL_TEXTURE_2D, m_texID); -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - if (GLEW_VERSION_1_5) -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif + if (IsGlew1_5()) { glBindBuffer(GL_ARRAY_BUFFER, m_vboID); } @@ -408,7 +392,7 @@ void GLFont::render_textScreenSpace(const char* text, float x, float y, float fo vbodata[14] = vbodata[6]; vbodata[15] = vbodata[11]; - // if(GLEW_VERSION_1_5) + // if(IsGlew1_5()) // { // glBufferData( GL_ARRAY_BUFFER, 16*sizeof(float), (char*)0, GL_DYNAMIC_DRAW ); // glBufferData( GL_ARRAY_BUFFER, 16*sizeof(float), vbodata, GL_DYNAMIC_DRAW ); diff --git a/src/oglGraph/OpenGLGraph.cpp b/src/oglGraph/OpenGLGraph.cpp index 8a375f09e..eb5a353a9 100644 --- a/src/oglGraph/OpenGLGraph.cpp +++ b/src/oglGraph/OpenGLGraph.cpp @@ -32,6 +32,18 @@ const int OpenGLGraph::GLCanvasAttributes[8] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, WX_GL_STENCIL_SIZE, 0, 0, 0 }; +static constexpr bool IsGlew1_5() +{ +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + return GLEW_VERSION_1_5; +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif +} + GLG_settings::GLG_settings() : title("") , titleXaxis("") @@ -684,14 +696,7 @@ void OpenGLGraph::Draw() switchToDataView(); -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wold-style-cast" -#endif - if (settings.useVBO && GLEW_VERSION_1_5) -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif + if (settings.useVBO && IsGlew1_5()) { for (unsigned int i = 0; i < series.size(); i++) { From 4740307bd1a6839450ace95bb63f8ff7b8d66a7a Mon Sep 17 00:00:00 2001 From: Dominykas Date: Thu, 22 Feb 2024 14:50:17 +0200 Subject: [PATCH 12/13] Revert C compatibility for files --- src/CMakeLists.txt | 12 +- src/gnuPlotPipe.h | 4 +- ...librations.cpp => lms7002m_calibrations.c} | 88 +- .../common_src/lms7002m_calibrations.h | 11 +- ...7002m_controls.cpp => lms7002m_controls.c} | 836 +++++++++--------- ...ms7002m_filters.cpp => lms7002m_filters.c} | 49 +- src/mcu_program/common_src/lms7002m_filters.h | 8 + 7 files changed, 532 insertions(+), 476 deletions(-) rename src/mcu_program/common_src/{lms7002m_calibrations.cpp => lms7002m_calibrations.c} (95%) rename src/mcu_program/common_src/{lms7002m_controls.cpp => lms7002m_controls.c} (95%) rename src/mcu_program/common_src/{lms7002m_filters.cpp => lms7002m_filters.c} (93%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8191e986..c22083de4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,9 +57,9 @@ set(LIME_SUITE_SOURCES memory/MemoryPool.cpp mcu_program/spi.cpp - mcu_program/common_src/lms7002m_calibrations.cpp - mcu_program/common_src/lms7002m_controls.cpp - mcu_program/common_src/lms7002m_filters.cpp + mcu_program/common_src/lms7002m_calibrations.c + mcu_program/common_src/lms7002m_controls.c + mcu_program/common_src/lms7002m_filters.c API/LMS_APIWrapper.cpp @@ -68,6 +68,12 @@ set(LIME_SUITE_SOURCES include/limesuite/SDRDevice.cpp ) +SET_SOURCE_FILES_PROPERTIES( + mcu_program/common_src/lms7002m_calibrations.c + mcu_program/common_src/lms7002m_controls.c + mcu_program/common_src/lms7002m_filters.c + PROPERTIES LANGUAGE CXX) + set(LIME_SUITE_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include diff --git a/src/gnuPlotPipe.h b/src/gnuPlotPipe.h index 8a32fc5a4..4a417aeed 100644 --- a/src/gnuPlotPipe.h +++ b/src/gnuPlotPipe.h @@ -1,8 +1,8 @@ #ifndef GNUPLOT_PIPE_H #define GNUPLOT_PIPE_H -#include -#include +#include +#include /// @brief A class to pipe data into GNUPlot class GNUPlotPipe diff --git a/src/mcu_program/common_src/lms7002m_calibrations.cpp b/src/mcu_program/common_src/lms7002m_calibrations.c similarity index 95% rename from src/mcu_program/common_src/lms7002m_calibrations.cpp rename to src/mcu_program/common_src/lms7002m_calibrations.c index ad797e142..6b44e4e41 100644 --- a/src/mcu_program/common_src/lms7002m_calibrations.cpp +++ b/src/mcu_program/common_src/lms7002m_calibrations.c @@ -2,32 +2,32 @@ #include "LMS7002M_parameters_compact.h" #include "spi.h" #include "lms7002m_controls.h" -#include +#include #include "mcu_defines.h" +#include #define ENABLE_EXTERNAL_LOOPBACK 1 -#include +#ifdef __cplusplus //#define VERBOSE 1 //#define DRAW_GNU_PLOTS -#include -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include -#ifdef DRAW_GNU_PLOTS - #define PUSH_GMEASUREMENT_VALUES(value, rssi) gMeasurements.push_back({ value, rssi }) + #ifdef DRAW_GNU_PLOTS + #define PUSH_GMEASUREMENT_VALUES(value, rssi) gMeasurements.push_back({ value, rssi }) GNUPlotPipe saturationPlot; GNUPlotPipe IQImbalancePlot; GNUPlotPipe txDCPlot; -#else - #define PUSH_GMEASUREMENT_VALUES(value, rssi) -#endif -#include + #else + #define PUSH_GMEASUREMENT_VALUES(value, rssi) + #endif + #include typedef std::vector> MeasurementsVector; MeasurementsVector gMeasurements; @@ -51,13 +51,21 @@ void DrawMeasurement(GNUPlotPipe& gp, const MeasurementsVector& vec) gp.write("e\n"); } +extern "C" { +#else + #define VERBOSE 0 + #define PUSH_GMEASUREMENT_VALUES(value, rssi) + + #include "lms7002_regx51.h" //MCU timer sfr +#endif // __cplusplus + ///APPROXIMATE conversion float ChipRSSI_2_dBFS(uint32_t rssi) { uint32_t maxRSSI = 0x15FF4; if (rssi == 0) rssi = 1; - return 20 * log10(static_cast(rssi) / maxRSSI); + return 20 * log10((float)(rssi) / maxRSSI); } int16_t toSigned(int16_t val, uint8_t msblsb) @@ -78,6 +86,15 @@ uint16_t RSSIDelayCounter = 1; // MCU timer delay between RSSI measurements // [1:0] SEL_PATH_RFE, when calibrating Tx uint8_t extLoopbackPair = 0; +int16_t clamp(int16_t value, int16_t minBound, int16_t maxBound) +{ + if (value < minBound) + return minBound; + if (value > maxBound) + return maxBound; + return value; +} + static void FlipRisingEdge(const uint16_t addr, const uint8_t bits) { Modify_SPI_Reg_bits(addr, bits, 0); @@ -110,7 +127,7 @@ void UpdateRSSIDelay() decimation = 1; //bypass { float waitTime = sampleCount / ((GetReferenceClk_TSP_MHz(false) / 2) / decimation); - RSSIDelayCounter = (0xFFFF) - static_cast(waitTime * RefClk / 12); + RSSIDelayCounter = (0xFFFF) - (uint16_t)(waitTime * RefClk / 12); } } @@ -233,7 +250,7 @@ int CheckSaturationTxRx(bool extLoopback) Modify_SPI_Reg_bits(CMIX_BYP_RXTSP, 0); SetNCOFrequency(LMS7002M_Rx, calibrationSXOffset_Hz - offsetNCO + (bandwidthRF / calibUserBwDivider) * 2, 0); - g_pga = static_cast(Get_SPI_Reg_bits(G_PGA_RBB)); + g_pga = (uint8_t)Get_SPI_Reg_bits(G_PGA_RBB); #if ENABLE_EXTERNAL_LOOPBACK if (extLoopback) { @@ -242,7 +259,7 @@ int CheckSaturationTxRx(bool extLoopback) } else #endif - g_rfe = static_cast(Get_SPI_Reg_bits(G_RXLOOPB_RFE)); + g_rfe = (uint8_t)Get_SPI_Reg_bits(G_RXLOOPB_RFE); rssi = GetRSSI(); PUSH_GMEASUREMENT_VALUES(index, ChipRSSI_2_dBFS(rssi)); @@ -281,7 +298,7 @@ int CheckSaturationTxRx(bool extLoopback) break; Modify_SPI_Reg_bits(G_PGA_RBB, g_pga); rssi = GetRSSI(); - if (static_cast(rssi) / rssi_prev < 1.05) // pga should give ~1dB change + if ((float)rssi / rssi_prev < 1.05) // pga should give ~1dB change break; rssi_prev = rssi; PUSH_GMEASUREMENT_VALUES(++index, ChipRSSI_2_dBFS(rssi)); @@ -438,12 +455,12 @@ void AdjustAutoDC(const uint16_t address, bool tx) minValue = initVal = ReadAnalogDC(address); minRSSI = rssi = GetRSSI(); - WriteAnalogDC(address, std::clamp(initVal + 1, -range, range)); + WriteAnalogDC(address, clamp(initVal + 1, -range, range)); valChange = GetRSSI() < rssi ? 1 : -1; for (i = 8; i; --i) { - initVal = std::clamp(initVal + valChange, -range, range); + initVal = clamp(initVal + valChange, -range, range); WriteAnalogDC(address, initVal); rssi = GetRSSI(); if (rssi < minRSSI) @@ -563,10 +580,10 @@ void CalibrateTxDCAuto() qparams.result = 0; //ReadAnalogDC(qparams.param.address); for (i = 0; i < 3; ++i) { - iparams.minValue = std::clamp(iparams.result - offset[i], -1024, 1023); - iparams.maxValue = std::clamp(iparams.result + offset[i], -1024, 1023); - qparams.minValue = std::clamp(qparams.result - offset[i], -1024, 1023); - qparams.maxValue = std::clamp(qparams.result + offset[i], -1024, 1023); + iparams.minValue = clamp(iparams.result - offset[i], -1024, 1023); + iparams.maxValue = clamp(iparams.result + offset[i], -1024, 1023); + qparams.minValue = clamp(qparams.result - offset[i], -1024, 1023); + qparams.maxValue = clamp(qparams.result + offset[i], -1024, 1023); TxDcBinarySearch(&iparams); #ifdef DRAW_GNU_PLOTS @@ -711,8 +728,10 @@ void CalibrateIQImbalance(bool tx) uint8_t SetupCGEN() { - uint8_t cgenMultiplier = std::clamp(std::round(GetFrequencyCGEN() / 46.08e6), 2, 13); - uint8_t gfir3n = 4 * cgenMultiplier; + uint8_t cgenMultiplier; + uint8_t gfir3n; + cgenMultiplier = clamp((GetFrequencyCGEN() / 46.08e6) + 0.5, 2, 13); + gfir3n = 4 * cgenMultiplier; if (Get_SPI_Reg_bits(EN_ADCCLKH_CLKGN) == 1) gfir3n /= pow2(Get_SPI_Reg_bits(CLKH_OV_CLKL_CGEN)); @@ -911,7 +930,7 @@ uint8_t CalibrateTxSetup(bool extLoopback) LoadDC_REG_TX_IQ(); SetNCOFrequency(LMS7002M_Tx, bandwidthRF / calibUserBwDivider, 0); { - const uint8_t sel_band1_2_trf = static_cast(Get_SPI_Reg_bits(0x0103, MSB_LSB(11, 10))); + const uint8_t sel_band1_2_trf = (uint8_t)Get_SPI_Reg_bits(0x0103, MSB_LSB(11, 10)); #if ENABLE_EXTERNAL_LOOPBACK if (extLoopback) { @@ -962,11 +981,10 @@ uint8_t CalibrateTxSetup(bool extLoopback) uint8_t CalibrateTx(bool extLoopback) { const uint16_t x0020val = SPI_read(0x0020); -#ifdef VERBOSE +#if defined(VERBOSE) && defined(__cplusplus) auto beginTime = std::chrono::high_resolution_clock::now(); #endif #if VERBOSE - uint8_t sel_band1_trf = (uint8_t)Get_SPI_Reg_bits(SEL_BAND1_TRF); printf("Tx ch.%s , BW: %g MHz, RF output: %s, Gain: %i, loopb: %s\n", (x0020val & 3) == 0x1 ? "A" : "B", @@ -1301,7 +1319,7 @@ uint8_t CheckSaturationRx(const float_type bandwidth_Hz, bool extLoopback) { ROM const uint16_t target_rssi = 0x07000; //0x0B000 = -3 dBFS uint16_t rssi; - uint8_t cg_iamp = static_cast(Get_SPI_Reg_bits(CG_IAMP_TBB)); + uint8_t cg_iamp = (uint8_t)Get_SPI_Reg_bits(CG_IAMP_TBB); #ifdef DRAW_GNU_PLOTS int index = 0; GNUPlotPipe& gp = saturationPlot; @@ -1416,7 +1434,7 @@ uint8_t CheckSaturationRx(const float_type bandwidth_Hz, bool extLoopback) uint8_t CalibrateRx(bool extLoopback, bool dcOnly) { -#ifdef VERBOSE +#if defined(VERBOSE) && defined(__cplusplus) auto beginTime = std::chrono::high_resolution_clock::now(); #endif uint8_t status; @@ -1467,7 +1485,7 @@ uint8_t CalibrateRx(bool extLoopback, bool dcOnly) goto RxCalibrationEndStage; if (!extLoopback) { - if (Get_SPI_Reg_bits(SEL_PATH_RFE) == 2) + if ((uint8_t)Get_SPI_Reg_bits(SEL_PATH_RFE) == 2) { Modify_SPI_Reg_bits(PD_RLOOPB_2_RFE, 0); Modify_SPI_Reg_bits(EN_INSHSW_LB2_RFE, 0); @@ -1540,3 +1558,7 @@ RxCalibrationEndStage : { #endif //LMS_VERBOSE_OUTPUT return MCU_NO_ERROR; } + +#ifdef __cplusplus +} // extern C +#endif diff --git a/src/mcu_program/common_src/lms7002m_calibrations.h b/src/mcu_program/common_src/lms7002m_calibrations.h index e2c426588..b2a7bbb52 100644 --- a/src/mcu_program/common_src/lms7002m_calibrations.h +++ b/src/mcu_program/common_src/lms7002m_calibrations.h @@ -1,13 +1,18 @@ #ifndef LMS7002M_CALIBRATIONS_H #define LMS7002M_CALIBRATIONS_H -#include "typedefs.h" +#ifdef __cplusplus namespace lime { class LMS7002M; } void SetupCalibrations(lime::LMS7002M* chip, double BW); +extern "C" { +#endif + +#include "typedefs.h" + int16_t ReadAnalogDC(const uint16_t addr); void UpdateRSSIDelay(); uint32_t GetRSSI(); @@ -20,4 +25,8 @@ void CalibrateRxDCAuto(); uint8_t RunAGC(uint32_t wantedRSSI); int16_t clamp(int16_t value, int16_t minBound, int16_t maxBound); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/mcu_program/common_src/lms7002m_controls.cpp b/src/mcu_program/common_src/lms7002m_controls.c similarity index 95% rename from src/mcu_program/common_src/lms7002m_controls.cpp rename to src/mcu_program/common_src/lms7002m_controls.c index 8e77b3eaf..00e8d9798 100644 --- a/src/mcu_program/common_src/lms7002m_controls.cpp +++ b/src/mcu_program/common_src/lms7002m_controls.c @@ -4,13 +4,15 @@ #include "math.h" #include "typedefs.h" #include "mcu_defines.h" +#include #ifdef __cplusplus - #include - #include -using namespace std; #include #include + #include +using namespace std; + +extern "C" { #else #include "lms7002_regx51.h" //MCU timer sfr uint16_t gComparatorDelayCounter = 0xFF00; // ~100us @ ref 30.72MHz @@ -95,88 +97,421 @@ void SaveChipState(bool wr) SPI_write(0x0020, ch); } +void SetDefaultsSX() +{ + ROM const uint16_t SXAddr[] = { 0x011C, 0x011D, 0x011E, 0x011F, 0x0121, 0x0122, 0x0123 }; + ROM const uint16_t SXdefVals[] = { 0xAD43, 0x0400, 0x0780, 0x3640, 0x3404, 0x033F, 0x067B }; + + uint8_t i; + for (i = sizeof(SXAddr) / sizeof(uint16_t); i; --i) + SPI_write(SXAddr[i - 1], SXdefVals[i - 1]); + //keep 0x0120[7:0]ICT_VCO bias value intact + Modify_SPI_Reg_bits(0x0120, MSB_LSB(15, 8), 0xB9FF); +} + +void ClockLogicResets() +{ + //MCLK2 toggle + uint16_t reg = SPI_read(0x002B); + SPI_write(0x002B, reg ^ (1 << 9)); + SPI_write(0x002B, reg); + + //TSP logic reset + reg = SPI_read(0x0020); + SPI_write(0x0020, reg & ~0xAA00); + SPI_write(0x0020, reg); +} + +float_type GetFrequencyCGEN() +{ + const float_type dMul = (RefClk / 2.0) / (Get_SPI_Reg_bits(DIV_OUTCH_CGEN) + 1); //DIV_OUTCH_CGEN + const uint16_t gINT = Get_SPI_Reg_bits(0x0088, MSB_LSB(13, 0)); //read whole register to reduce SPI transfers + const uint32_t gFRAC = ((uint32_t)(gINT & 0xF) << 16) | Get_SPI_Reg_bits(0x0087, MSB_LSB(15, 0)); + return dMul * (((gINT >> 4) + 1 + gFRAC / 1048576.0)); +} + +uint8_t SetFrequencyCGEN(float_type freq) +{ + float_type dFvco; + float_type intpart; + //VCO frequency selection according to F_CLKH + { + uint8_t iHdiv_high = (2.94e9 / 2 / freq) - 1; + uint8_t iHdiv_low = (1.93e9 / 2 / freq); + uint8_t iHdiv = (iHdiv_low + iHdiv_high) / 2; + dFvco = 2 * (iHdiv + 1) * freq; + Modify_SPI_Reg_bits(DIV_OUTCH_CGEN, iHdiv); + } + //Integer division + intpart = dFvco / RefClk; + Modify_SPI_Reg_bits(INT_SDM_CGEN, intpart - 1); //INT_SDM_CGEN + //Fractional division + { + const float_type dFrac = intpart - (uint32_t)(dFvco / RefClk); + const uint32_t gFRAC = (uint32_t)(dFrac * 1048576); + Modify_SPI_Reg_bits(0x0087, MSB_LSB(15, 0), gFRAC & 0xFFFF); //INT_SDM_CGEN[15:0] + Modify_SPI_Reg_bits(0x0088, MSB_LSB(3, 0), gFRAC >> 16); //INT_SDM_CGEN[19:16] + } + +#if VERBOSE + //printf("CGEN: Freq=%g MHz, VCO=%g GHz, INT=%i, FRAC=%i, DIV_OUTCH_CGEN=%i\n", freq/1e6, dFvco/1e9, gINT, gFRAC, iHdiv); +#endif // NDEBUG + if (TuneVCO(VCO_CGEN) != 0) + return MCU_CGEN_TUNE_FAILED; + return 0; +} + +float_type GetReferenceClk_TSP_MHz(bool tx) +{ + const float_type cgenFreq = GetFrequencyCGEN(); + const float_type clklfreq = cgenFreq / pow2(Get_SPI_Reg_bits(CLKH_OV_CLKL_CGEN)); + if (Get_SPI_Reg_bits(EN_ADCCLKH_CLKGN) == 0) + return tx ? clklfreq : cgenFreq / 4; + else + return tx ? cgenFreq : clklfreq / 4; +} + +void SetNCOFrequency(const bool tx, const float freq, uint8_t index) +{ + const uint16_t addr = (tx ? 0x0242 : 0x0442) + index * 2; + const uint32_t fcw = (uint32_t)((freq / GetReferenceClk_TSP_MHz(tx)) * 4294967296.0); + SPI_write(addr, (fcw >> 16)); //NCO frequency control word register MSB part. + SPI_write(addr + 1, fcw); //NCO frequency control word register LSB part. +} + +float_type GetFrequencySX(const bool Tx) +{ + const uint16_t ch = SPI_read(0x0020); //(uint8_t)Get_SPI_Reg_bits(MAC); //remember previously used channel + Modify_SPI_Reg_bits(MAC, Tx ? 2 : 1); // Rx mac = 1, Tx mac = 2 + { + const uint16_t gINT = Get_SPI_Reg_bits(0x011E, MSB_LSB(13, 0)); // read whole register to reduce SPI transfers + const uint32_t gFRAC = ((uint32_t)(gINT & 0xF) << 16) | SPI_read(0x011D); + const uint8_t enDiv2 = Get_SPI_Reg_bits(EN_DIV2_DIVPROG) + 1; + const uint8_t divLoch = Get_SPI_Reg_bits(DIV_LOCH) + 1; + SPI_write(0x0020, ch); + //Calculate real frequency according to the calculated parameters + return (enDiv2) * (RefClk / pow2(divLoch)) * ((gINT >> 4) + 4 + (gFRAC / 1048576.0)); + } +} + +uint8_t SetFrequencySX(const bool tx, const float_type freq_Hz) +{ + int16_t tuneScore[3] = { 255, 255, 255 }; // best is closest to 0 + const uint16_t macBck = SPI_read(0x0020); + bool canDeliverFrequency = false; + + Modify_SPI_Reg_bits(MAC, tx ? 2 : 1); + //find required VCO frequency + { + float_type VCOfreq; + float_type temp; + { + uint8_t div_loch; + for (div_loch = 7; div_loch; --div_loch) + { + VCOfreq = pow2(div_loch) * freq_Hz; + if ((VCOfreq >= 3800e6) && (VCOfreq <= 7714e6)) + break; + } + Modify_SPI_Reg_bits(DIV_LOCH, div_loch - 1); + } + { + uint32_t fractionalPart; + const uint8_t enDiv2 = (VCOfreq > 5500e6) ? 1 : 0; + Modify_SPI_Reg_bits(EN_DIV2_DIVPROG, enDiv2); //EN_DIV2_DIVPROG + temp = VCOfreq / (RefClk * (1 + enDiv2)); + fractionalPart = (uint32_t)((temp - (uint32_t)(temp)) * 1048576); + + Modify_SPI_Reg_bits(INT_SDM, (uint16_t)(temp - 4)); //INT_SDM + Modify_SPI_Reg_bits(0x011E, MSB_LSB(3, 0), (fractionalPart >> 16)); //FRAC_SDM[19:16] + SPI_write(0x011D, fractionalPart & 0xFFFF); //FRAC_SDM[15:0] + } + } + while (1) + { + uint8_t sel_vco; + uint8_t bestvco = 0; + for (sel_vco = 0; sel_vco < 3; ++sel_vco) + { + Modify_SPI_Reg_bits(SEL_VCO, sel_vco); + if (TuneVCO(1) == MCU_NO_ERROR) + { + tuneScore[sel_vco] = Get_SPI_Reg_bits(CSW_VCO) - 128; + canDeliverFrequency = true; + } + if (abs(tuneScore[sel_vco]) < abs(tuneScore[bestvco])) + bestvco = sel_vco; + } + if (canDeliverFrequency) + { + Modify_SPI_Reg_bits(SEL_VCO, bestvco); + Modify_SPI_Reg_bits(CSW_VCO, tuneScore[bestvco] + 128); + break; + } + { + uint16_t bias = Get_SPI_Reg_bits(ICT_VCO); + if (bias == 255) + break; + Modify_SPI_Reg_bits(ICT_VCO, bias + 32 > 255 ? 255 : bias + 32); + } + } + SPI_write(0x0020, macBck); + if (canDeliverFrequency == false) + return tx ? MCU_SXT_TUNE_FAILED : MCU_SXR_TUNE_FAILED; + return MCU_NO_ERROR; +} + +static uint8_t ReadCMP(const bool SX) +{ #ifdef __cplusplus - #include -void SetDefaults(uint16_t start, uint16_t end) + std::this_thread::sleep_for(std::chrono::microseconds(100)); +#else + TR0 = 0; //stop timer 0 + TH0 = (gComparatorDelayCounter >> 8); + TL0 = (gComparatorDelayCounter & 0xFF); + TF0 = 0; // clear overflow + TR0 = 1; //start timer 0 + while (!TF0) + ; // wait for timer overflow +#endif + return (uint8_t)(Get_SPI_Reg_bits(SX ? 0x0123 : 0x008C, MSB_LSB(13, 12))); +} + +uint8_t TuneVCO(bool SX) // 0-cgen, 1-SXR, 2-SXT { - ROM const uint16_t defaultAddrs[] = { 0x0020, - 0x0021, - 0x0022, - 0x0023, - 0x0024, - 0x0025, - 0x0026, - 0x0027, - 0x0028, - 0x0029, - 0x002A, - 0x002B, - 0x002C, - 0x002E, - 0x002F, - 0x0081, - 0x0082, - 0x0084, - 0x0085, - 0x0086, - 0x0087, - 0x0088, - 0x0089, - 0x008A, - 0x008B, - 0x008C, - 0x0092, - 0x0093, - 0x0094, - 0x0095, - 0x0096, - 0x0097, - 0x0098, - 0x0099, - 0x009A, - 0x009B, - 0x009C, - 0x009D, - 0x009E, - 0x009F, - 0x00A0, - 0x00A1, - 0x00A2, - 0x00A3, - 0x00A4, - 0x00A5, - 0x00A6, - 0x00A7, - 0x00A8, - 0x00AA, - 0x00AB, - 0x00AD, - 0x00AE, - 0x0100, - 0x0101, - 0x0102, - 0x0103, - 0x0104, - 0x0105, - 0x0106, - 0x0107, - 0x0108, - 0x0109, - 0x010A, - 0x010B, - 0x010C, - 0x010D, - 0x010E, - 0x010F, - 0x0110, - 0x0111, - 0x0112, - 0x0113, - 0x0114, - 0x0115, - 0x0116, - 0x0117, - 0x0118, + typedef struct { + uint8_t high; + uint8_t low; + uint8_t hasLock; + } CSWInteval; + + uint16_t addrCSW_VCO; + uint8_t msblsb; + + CSWInteval cswSearch[2]; + cswSearch[0].high = 0; //search interval lowest value + cswSearch[0].low = 127; + cswSearch[1].high = 128; + cswSearch[1].low = 255; + cswSearch[1].hasLock = cswSearch[0].hasLock = false; + + if (SX) + { + addrCSW_VCO = 0x0121; + msblsb = MSB_LSB(10, 3); //CSW msb lsb + //assuming the active channel is already correct + Modify_SPI_Reg_bits(0x011C, MSB_LSB(2, 1), 0); //activate VCO and comparator + } + else //CGEN + { + addrCSW_VCO = 0x008B; + msblsb = MSB_LSB(8, 1); //CSW msb lsb + Modify_SPI_Reg_bits(0x0086, MSB_LSB(2, 1), 0); //activate VCO and comparator + } +#ifndef __cplusplus + gComparatorDelayCounter = 0xFFFF - (uint16_t)((0.0009 / 12) * RefClk); // ~900us +#endif + //check if lock is within VCO range + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, 0); + if (ReadCMP(SX) == 3) //VCO too high + return MCU_ERROR; + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, 255); + if (ReadCMP(SX) == 0) //VCO too low + return MCU_ERROR; + + //search intervals [0-127][128-255] + { + uint8_t t; + for (t = 0; t < 2; ++t) + { + uint8_t mask; + for (mask = (1 << 6); mask; mask >>= 1) + { + uint8_t cmpValue; + cswSearch[t].high |= mask; // CSW_VCO=1 + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswSearch[t].high); + cmpValue = ReadCMP(SX); + if (cmpValue == 0x03) // reduce CSW + cswSearch[t].high ^= mask; // CSW_VCO=0 + else if (cmpValue == 0x02 && cswSearch[t].high <= cswSearch[t].low) + { + cswSearch[t].hasLock = true; + cswSearch[t].low = cswSearch[t].high; + } + } + for (; cswSearch[t].low; --cswSearch[t].low) + { + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswSearch[t].low); + if (ReadCMP(SX) != 0x2) + { + if (cswSearch[t].low < cswSearch[t].high) + ++cswSearch[t].low; + break; + } + } + } + } + { + uint8_t cswValue; + //compare which interval is wider + { + if (cswSearch[1].hasLock && (cswSearch[1].high - cswSearch[1].low >= cswSearch[0].high - cswSearch[0].low)) + cswValue = cswSearch[1].low + ((cswSearch[1].high - cswSearch[1].low) >> 1); + else + cswValue = cswSearch[0].low + ((cswSearch[0].high - cswSearch[0].low) >> 1); + } + + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswValue); + if (ReadCMP(SX) != 0x2) //just in case high-low==1, if low fails, check if high locks + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, ++cswValue); + } + if (ReadCMP(SX) == 0x2) + return MCU_NO_ERROR; + return MCU_ERROR; +} + +void WriteMaskedRegs(const RegisterBatch ROM* regs) +{ + uint8_t i; + uint8_t index; + for (i = regs->cnt; i; --i) + { + index = i - 1; + SPI_write(regs->addr[index], (SPI_read(regs->addr[index]) & ~regs->mask[index]) | regs->val[index]); + } + for (i = regs->wrOnlyAddrCnt; i; --i) + { + index = i - 1; + SPI_write(regs->wrOnlyAddr[index], i > regs->wrOnlyDataCnt ? 0 : regs->wrOnlyData[index]); + } +} + +uint8_t GetValueOf_c_ctl_pga_rbb(uint8_t g_pga_rbb) +{ + if (g_pga_rbb < 21) + return 1; + if (g_pga_rbb < 13) + return 2; + if (g_pga_rbb < 8) + return 3; + return 0; +} + +void EnableChannelPowerControls() +{ + uint16_t afe = SPI_read(0x0082); + uint16_t value = SPI_read(0x0020); + if ((value & 3) == 1) + { + value = value | 0x0014; + afe &= ~0x14; + } + else + { + value = value | 0x0028; + afe &= ~0x0A; + } + SPI_write(0x0020, value); + SPI_write(0x0082, afe); +} + +void EnableMIMOBuffersIfNecessary() +{ + //modifications when calibrating channel B + uint16_t x0020val = SPI_read(0x0020); + if ((x0020val & 0x3) == 2) + { + Modify_SPI_Reg_bits(MAC, 1); + Modify_SPI_Reg_bits(EN_NEXTRX_RFE, 1); + Modify_SPI_Reg_bits(EN_NEXTTX_TRF, 1); + SPI_write(0x0020, x0020val); + } +} + +#ifdef __cplusplus +} // extern C +#endif + +void SetDefaults(uint16_t start, uint16_t end) +{ + ROM const uint16_t defaultAddrs[] = { 0x0020, + 0x0021, + 0x0022, + 0x0023, + 0x0024, + 0x0025, + 0x0026, + 0x0027, + 0x0028, + 0x0029, + 0x002A, + 0x002B, + 0x002C, + 0x002E, + 0x002F, + 0x0081, + 0x0082, + 0x0084, + 0x0085, + 0x0086, + 0x0087, + 0x0088, + 0x0089, + 0x008A, + 0x008B, + 0x008C, + 0x0092, + 0x0093, + 0x0094, + 0x0095, + 0x0096, + 0x0097, + 0x0098, + 0x0099, + 0x009A, + 0x009B, + 0x009C, + 0x009D, + 0x009E, + 0x009F, + 0x00A0, + 0x00A1, + 0x00A2, + 0x00A3, + 0x00A4, + 0x00A5, + 0x00A6, + 0x00A7, + 0x00A8, + 0x00AA, + 0x00AB, + 0x00AD, + 0x00AE, + 0x0100, + 0x0101, + 0x0102, + 0x0103, + 0x0104, + 0x0105, + 0x0106, + 0x0107, + 0x0108, + 0x0109, + 0x010A, + 0x010B, + 0x010C, + 0x010D, + 0x010E, + 0x010F, + 0x0110, + 0x0111, + 0x0112, + 0x0113, + 0x0114, + 0x0115, + 0x0116, + 0x0117, + 0x0118, 0x0119, 0x011A, 0x011C, @@ -509,7 +844,7 @@ void SetDefaults(uint16_t start, uint16_t end) 0x0000, 0x00A0, 0x1020 }; - #ifdef __cplusplus +#ifdef __cplusplus //int status = 0; std::vector addrs; std::vector values; @@ -527,338 +862,7 @@ void SetDefaults(uint16_t start, uint16_t end) } } SPI_write_batch(addrs.data(), values.data(), addrs.size()); - #else +#else - #endif -} #endif -void SetDefaultsSX() -{ - ROM const uint16_t SXAddr[] = { 0x011C, 0x011D, 0x011E, 0x011F, 0x0121, 0x0122, 0x0123 }; - ROM const uint16_t SXdefVals[] = { 0xAD43, 0x0400, 0x0780, 0x3640, 0x3404, 0x033F, 0x067B }; - - uint8_t i; - for (i = sizeof(SXAddr) / sizeof(uint16_t); i; --i) - SPI_write(SXAddr[i - 1], SXdefVals[i - 1]); - //keep 0x0120[7:0]ICT_VCO bias value intact - Modify_SPI_Reg_bits(0x0120, MSB_LSB(15, 8), 0xB9FF); -} - -void ClockLogicResets() -{ - //MCLK2 toggle - uint16_t reg = SPI_read(0x002B); - SPI_write(0x002B, reg ^ (1 << 9)); - SPI_write(0x002B, reg); - - //TSP logic reset - reg = SPI_read(0x0020); - SPI_write(0x0020, reg & ~0xAA00); - SPI_write(0x0020, reg); -} - -float_type GetFrequencyCGEN() -{ - const float_type dMul = (RefClk / 2.0) / (Get_SPI_Reg_bits(DIV_OUTCH_CGEN) + 1); //DIV_OUTCH_CGEN - const uint16_t gINT = Get_SPI_Reg_bits(0x0088, MSB_LSB(13, 0)); //read whole register to reduce SPI transfers - const uint32_t gFRAC = (static_cast(gINT & 0xF) << 16) | Get_SPI_Reg_bits(0x0087, MSB_LSB(15, 0)); - return dMul * (((gINT >> 4) + 1 + gFRAC / 1048576.0)); -} - -uint8_t SetFrequencyCGEN(float_type freq) -{ - float_type dFvco; - float_type intpart; - //VCO frequency selection according to F_CLKH - { - uint8_t iHdiv_high = (2.94e9 / 2 / freq) - 1; - uint8_t iHdiv_low = (1.93e9 / 2 / freq); - uint8_t iHdiv = (iHdiv_low + iHdiv_high) / 2; - dFvco = 2 * (iHdiv + 1) * freq; - Modify_SPI_Reg_bits(DIV_OUTCH_CGEN, iHdiv); - } - //Integer division - intpart = dFvco / RefClk; - Modify_SPI_Reg_bits(INT_SDM_CGEN, intpart - 1); //INT_SDM_CGEN - //Fractional division - { - const float_type dFrac = intpart - static_cast(dFvco / RefClk); - const uint32_t gFRAC = static_cast(dFrac * 1048576); - Modify_SPI_Reg_bits(0x0087, MSB_LSB(15, 0), gFRAC & 0xFFFF); //INT_SDM_CGEN[15:0] - Modify_SPI_Reg_bits(0x0088, MSB_LSB(3, 0), gFRAC >> 16); //INT_SDM_CGEN[19:16] - } - -#if VERBOSE - //printf("CGEN: Freq=%g MHz, VCO=%g GHz, INT=%i, FRAC=%i, DIV_OUTCH_CGEN=%i\n", freq/1e6, dFvco/1e9, gINT, gFRAC, iHdiv); -#endif // NDEBUG - if (TuneVCO(VCO_CGEN) != 0) - return MCU_CGEN_TUNE_FAILED; - return 0; -} - -float_type GetReferenceClk_TSP_MHz(bool tx) -{ - const float_type cgenFreq = GetFrequencyCGEN(); - const float_type clklfreq = cgenFreq / pow2(Get_SPI_Reg_bits(CLKH_OV_CLKL_CGEN)); - if (Get_SPI_Reg_bits(EN_ADCCLKH_CLKGN) == 0) - return tx ? clklfreq : cgenFreq / 4; - else - return tx ? cgenFreq : clklfreq / 4; -} - -void SetNCOFrequency(const bool tx, const float freq, uint8_t index) -{ - const uint16_t addr = (tx ? 0x0242 : 0x0442) + index * 2; - const uint32_t fcw = static_cast((freq / GetReferenceClk_TSP_MHz(tx)) * 4294967296.0); - SPI_write(addr, (fcw >> 16)); //NCO frequency control word register MSB part. - SPI_write(addr + 1, fcw); //NCO frequency control word register LSB part. -} - -float_type GetFrequencySX(const bool Tx) -{ - const uint16_t ch = SPI_read(0x0020); //(uint8_t)Get_SPI_Reg_bits(MAC); //remember previously used channel - Modify_SPI_Reg_bits(MAC, Tx ? 2 : 1); // Rx mac = 1, Tx mac = 2 - { - const uint16_t gINT = Get_SPI_Reg_bits(0x011E, MSB_LSB(13, 0)); // read whole register to reduce SPI transfers - const uint32_t gFRAC = (static_cast(gINT & 0xF) << 16) | SPI_read(0x011D); - const uint8_t enDiv2 = Get_SPI_Reg_bits(EN_DIV2_DIVPROG) + 1; - const uint8_t divLoch = Get_SPI_Reg_bits(DIV_LOCH) + 1; - SPI_write(0x0020, ch); - //Calculate real frequency according to the calculated parameters - return (enDiv2) * (RefClk / pow2(divLoch)) * ((gINT >> 4) + 4 + (gFRAC / 1048576.0)); - } -} - -uint8_t SetFrequencySX(const bool tx, const float_type freq_Hz) -{ - int16_t tuneScore[3] = { 255, 255, 255 }; // best is closest to 0 - const uint16_t macBck = SPI_read(0x0020); - bool canDeliverFrequency = false; - - Modify_SPI_Reg_bits(MAC, tx ? 2 : 1); - //find required VCO frequency - { - float_type VCOfreq; - float_type temp; - { - uint8_t div_loch; - for (div_loch = 7; div_loch; --div_loch) - { - VCOfreq = pow2(div_loch) * freq_Hz; - if ((VCOfreq >= 3800e6) && (VCOfreq <= 7714e6)) - break; - } - Modify_SPI_Reg_bits(DIV_LOCH, div_loch - 1); - } - { - uint32_t fractionalPart; - const uint8_t enDiv2 = (VCOfreq > 5500e6) ? 1 : 0; - Modify_SPI_Reg_bits(EN_DIV2_DIVPROG, enDiv2); //EN_DIV2_DIVPROG - temp = VCOfreq / (RefClk * (1 + enDiv2)); - fractionalPart = static_cast((temp - static_cast(temp)) * 1048576); - - Modify_SPI_Reg_bits(INT_SDM, static_cast(temp - 4)); //INT_SDM - Modify_SPI_Reg_bits(0x011E, MSB_LSB(3, 0), (fractionalPart >> 16)); //FRAC_SDM[19:16] - SPI_write(0x011D, fractionalPart & 0xFFFF); //FRAC_SDM[15:0] - } - } - while (1) - { - uint8_t sel_vco; - uint8_t bestvco = 0; - for (sel_vco = 0; sel_vco < 3; ++sel_vco) - { - Modify_SPI_Reg_bits(SEL_VCO, sel_vco); - if (TuneVCO(1) == MCU_NO_ERROR) - { - tuneScore[sel_vco] = Get_SPI_Reg_bits(CSW_VCO) - 128; - canDeliverFrequency = true; - } - if (abs(tuneScore[sel_vco]) < abs(tuneScore[bestvco])) - bestvco = sel_vco; - } - if (canDeliverFrequency) - { - Modify_SPI_Reg_bits(SEL_VCO, bestvco); - Modify_SPI_Reg_bits(CSW_VCO, tuneScore[bestvco] + 128); - break; - } - { - uint16_t bias = Get_SPI_Reg_bits(ICT_VCO); - if (bias == 255) - break; - Modify_SPI_Reg_bits(ICT_VCO, bias + 32 > 255 ? 255 : bias + 32); - } - } - SPI_write(0x0020, macBck); - if (canDeliverFrequency == false) - return tx ? MCU_SXT_TUNE_FAILED : MCU_SXR_TUNE_FAILED; - return MCU_NO_ERROR; -} - -static uint8_t ReadCMP(const bool SX) -{ -#ifdef __cplusplus - std::this_thread::sleep_for(std::chrono::microseconds(100)); -#else - TR0 = 0; //stop timer 0 - TH0 = (gComparatorDelayCounter >> 8); - TL0 = (gComparatorDelayCounter & 0xFF); - TF0 = 0; // clear overflow - TR0 = 1; //start timer 0 - while (!TF0) - ; // wait for timer overflow -#endif - return static_cast(Get_SPI_Reg_bits(SX ? 0x0123 : 0x008C, MSB_LSB(13, 12))); -} - -uint8_t TuneVCO(bool SX) // 0-cgen, 1-SXR, 2-SXT -{ - typedef struct { - uint8_t high; - uint8_t low; - uint8_t hasLock; - } CSWInteval; - - uint16_t addrCSW_VCO; - uint8_t msblsb; - - CSWInteval cswSearch[2]; - cswSearch[0].high = 0; //search interval lowest value - cswSearch[0].low = 127; - cswSearch[1].high = 128; - cswSearch[1].low = 255; - cswSearch[1].hasLock = cswSearch[0].hasLock = false; - - if (SX) - { - addrCSW_VCO = 0x0121; - msblsb = MSB_LSB(10, 3); //CSW msb lsb - //assuming the active channel is already correct - Modify_SPI_Reg_bits(0x011C, MSB_LSB(2, 1), 0); //activate VCO and comparator - } - else //CGEN - { - addrCSW_VCO = 0x008B; - msblsb = MSB_LSB(8, 1); //CSW msb lsb - Modify_SPI_Reg_bits(0x0086, MSB_LSB(2, 1), 0); //activate VCO and comparator - } -#ifndef __cplusplus - gComparatorDelayCounter = 0xFFFF - (uint16_t)((0.0009 / 12) * RefClk); // ~900us -#endif - //check if lock is within VCO range - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, 0); - if (ReadCMP(SX) == 3) //VCO too high - return MCU_ERROR; - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, 255); - if (ReadCMP(SX) == 0) //VCO too low - return MCU_ERROR; - - //search intervals [0-127][128-255] - { - uint8_t t; - for (t = 0; t < 2; ++t) - { - uint8_t mask; - for (mask = (1 << 6); mask; mask >>= 1) - { - uint8_t cmpValue; - cswSearch[t].high |= mask; // CSW_VCO=1 - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswSearch[t].high); - cmpValue = ReadCMP(SX); - if (cmpValue == 0x03) // reduce CSW - cswSearch[t].high ^= mask; // CSW_VCO=0 - else if (cmpValue == 0x02 && cswSearch[t].high <= cswSearch[t].low) - { - cswSearch[t].hasLock = true; - cswSearch[t].low = cswSearch[t].high; - } - } - for (; cswSearch[t].low; --cswSearch[t].low) - { - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswSearch[t].low); - if (ReadCMP(SX) != 0x2) - { - if (cswSearch[t].low < cswSearch[t].high) - ++cswSearch[t].low; - break; - } - } - } - } - { - uint8_t cswValue; - //compare which interval is wider - { - if (cswSearch[1].hasLock && (cswSearch[1].high - cswSearch[1].low >= cswSearch[0].high - cswSearch[0].low)) - cswValue = cswSearch[1].low + ((cswSearch[1].high - cswSearch[1].low) >> 1); - else - cswValue = cswSearch[0].low + ((cswSearch[0].high - cswSearch[0].low) >> 1); - } - - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswValue); - if (ReadCMP(SX) != 0x2) //just in case high-low==1, if low fails, check if high locks - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, ++cswValue); - } - if (ReadCMP(SX) == 0x2) - return MCU_NO_ERROR; - return MCU_ERROR; -} - -void WriteMaskedRegs(const RegisterBatch ROM* regs) -{ - uint8_t i; - uint8_t index; - for (i = regs->cnt; i; --i) - { - index = i - 1; - SPI_write(regs->addr[index], (SPI_read(regs->addr[index]) & ~regs->mask[index]) | regs->val[index]); - } - for (i = regs->wrOnlyAddrCnt; i; --i) - { - index = i - 1; - SPI_write(regs->wrOnlyAddr[index], i > regs->wrOnlyDataCnt ? 0 : regs->wrOnlyData[index]); - } -} - -uint8_t GetValueOf_c_ctl_pga_rbb(uint8_t g_pga_rbb) -{ - if (g_pga_rbb < 21) - return 1; - if (g_pga_rbb < 13) - return 2; - if (g_pga_rbb < 8) - return 3; - return 0; -} - -void EnableChannelPowerControls() -{ - uint16_t afe = SPI_read(0x0082); - uint16_t value = SPI_read(0x0020); - if ((value & 3) == 1) - { - value = value | 0x0014; - afe &= ~0x14; - } - else - { - value = value | 0x0028; - afe &= ~0x0A; - } - SPI_write(0x0020, value); - SPI_write(0x0082, afe); -} - -void EnableMIMOBuffersIfNecessary() -{ - //modifications when calibrating channel B - uint16_t x0020val = SPI_read(0x0020); - if ((x0020val & 0x3) == 2) - { - Modify_SPI_Reg_bits(MAC, 1); - Modify_SPI_Reg_bits(EN_NEXTRX_RFE, 1); - Modify_SPI_Reg_bits(EN_NEXTTX_TRF, 1); - SPI_write(0x0020, x0020val); - } } diff --git a/src/mcu_program/common_src/lms7002m_filters.cpp b/src/mcu_program/common_src/lms7002m_filters.c similarity index 93% rename from src/mcu_program/common_src/lms7002m_filters.cpp rename to src/mcu_program/common_src/lms7002m_filters.c index 74cf002fa..0510aa2da 100644 --- a/src/mcu_program/common_src/lms7002m_filters.cpp +++ b/src/mcu_program/common_src/lms7002m_filters.c @@ -3,9 +3,12 @@ #include "lms7002m_filters.h" #include "LMS7002M_parameters_compact.h" #include "spi.h" -#include +#include #include "mcu_defines.h" -#include + +#ifdef __cplusplus +extern "C" { +#endif enum { SEARCH_SUCCESS = 0, SEARCH_NEED_TO_DECREASE, SEARCH_NEED_TO_INCREASE }; @@ -21,7 +24,7 @@ static ROM const float_type TxLPF_RF_LimitHigh = 130e6; static uint8_t ConfigCGEN_ForLPF_IF(float IF_Hz) { - uint8_t cgenMultiplier = std::clamp(std::round(IF_Hz * 20 / 46.08e6), 2, 13); + uint8_t cgenMultiplier = clamp(round(IF_Hz * 20 / 46.08e6), 2, 13); return SetFrequencyCGEN(46.08e6 * cgenMultiplier + 10e6); } @@ -38,7 +41,7 @@ static uint8_t RxFilterSearch(const uint16_t addr, const uint8_t msblsb, const u value -= stepSize; else value += stepSize; - value = std::clamp(value, 0, maxValue); + value = clamp(value, 0, maxValue); Modify_SPI_Reg_bits(addr, msblsb, value); if (doDecrement != (GetRSSI() < rssi_3dB)) break; @@ -52,7 +55,7 @@ static uint8_t RxFilterSearch(const uint16_t addr, const uint8_t msblsb, const u value += stepSize; else value -= stepSize; - value = std::clamp(value, 0, maxValue); + value = clamp(value, 0, maxValue); Modify_SPI_Reg_bits(addr, msblsb, value); } return 0; @@ -303,19 +306,19 @@ uint8_t TuneRxFilterSetup(const float_type rx_lpf_IF) int8_t ccomp_tia_rfe; if (g_tia_rfe > 1) { - cfb_tia_rfe = static_cast(1680e6 / rx_lpf_IF - 10); + cfb_tia_rfe = (int16_t)(1680e6 / rx_lpf_IF - 10); ccomp_tia_rfe = cfb_tia_rfe / 100; } else if (g_tia_rfe == 1) { - cfb_tia_rfe = static_cast(5400e6 / rx_lpf_IF - 15); + cfb_tia_rfe = (int16_t)(5400e6 / rx_lpf_IF - 15); ccomp_tia_rfe = cfb_tia_rfe / 100 + 1; } else return MCU_RX_INVALID_TIA; - SPI_write(0x0112, (std::clamp(ccomp_tia_rfe, 0, 15) << 8) | std::clamp(cfb_tia_rfe, 0, 4095)); + SPI_write(0x0112, (clamp(ccomp_tia_rfe, 0, 15) << 8) | clamp(cfb_tia_rfe, 0, 4095)); - Modify_SPI_Reg_bits(RCOMP_TIA_RFE, std::clamp(15 - cfb_tia_rfe / 100, 0, 15)); + Modify_SPI_Reg_bits(RCOMP_TIA_RFE, clamp(15 - cfb_tia_rfe / 100, 0, 15)); } { const int8_t rcc_ctl_pga_rbb = (430 * pow(0.65, g_pga_rbb / 10) - 110.35) / 20.45 + 16; @@ -328,7 +331,7 @@ uint8_t TuneRxFilterSetup(const float_type rx_lpf_IF) Modify_SPI_Reg_bits(INPUT_CTL_PGA_RBB, 0); { const float freqIF = rx_lpf_IF * 1.3; - int16_t c_ctl_lpfl_rbb = std::clamp(2160e6 / freqIF - 103, 0, 2047); + int16_t c_ctl_lpfl_rbb = clamp(2160e6 / freqIF - 103, 0, 2047); uint8_t rcc_ctl_lpfl_rbb = 5; if (freqIF < 15e6) @@ -350,8 +353,8 @@ uint8_t TuneRxFilterSetup(const float_type rx_lpf_IF) Modify_SPI_Reg_bits(INPUT_CTL_PGA_RBB, 1); { const float lpfIF_adjusted = rx_lpf_IF * 1.3; - uint8_t c_ctl_lpfh_rbb = std::clamp(6000e6 / lpfIF_adjusted - 50, 0, 255); - uint8_t rcc_ctl_lpfh_rbb = std::clamp(lpfIF_adjusted / 10e6 - 3, 0, 7); + uint8_t c_ctl_lpfh_rbb = clamp(6000e6 / lpfIF_adjusted - 50, 0, 255); + uint8_t rcc_ctl_lpfh_rbb = clamp(lpfIF_adjusted / 10e6 - 3, 0, 7); Modify_SPI_Reg_bits(0x0116, MSB_LSB(10, 0), (rcc_ctl_lpfh_rbb << 8) | c_ctl_lpfh_rbb); } } @@ -467,24 +470,24 @@ uint8_t TuneRxFilter(const float_type rx_lpf_freq_RF) uint16_t cfb_tia_rfe; uint8_t g_tia_rfe = Get_SPI_Reg_bits(G_TIA_RFE); if (g_tia_rfe == 3 || g_tia_rfe == 2) - cfb_tia_rfe = static_cast(1680e6 / (rx_lpf_IF * 0.72) - 10); + cfb_tia_rfe = (int)(1680e6 / (rx_lpf_IF * 0.72) - 10); else if (g_tia_rfe == 1) - cfb_tia_rfe = static_cast(5400e6 / (rx_lpf_IF * 0.72) - 15); + cfb_tia_rfe = (int)(5400e6 / (rx_lpf_IF * 0.72) - 15); else { status = MCU_RX_INVALID_TIA; goto RxFilterSearchEndStage; } - cfb_tia_rfe = std::clamp(cfb_tia_rfe, 0, 4095); + cfb_tia_rfe = clamp(cfb_tia_rfe, 0, 4095); Modify_SPI_Reg_bits(CFB_TIA_RFE, cfb_tia_rfe); { uint8_t ccomp_tia_rfe = cfb_tia_rfe / 100; if (g_tia_rfe == 1) ccomp_tia_rfe += 1; - Modify_SPI_Reg_bits(CCOMP_TIA_RFE, std::clamp(ccomp_tia_rfe, 0, 15)); + Modify_SPI_Reg_bits(CCOMP_TIA_RFE, clamp(ccomp_tia_rfe, 0, 15)); } - Modify_SPI_Reg_bits(RCOMP_TIA_RFE, std::clamp(15 - cfb_tia_rfe / 100, 0, 15)); + Modify_SPI_Reg_bits(RCOMP_TIA_RFE, clamp(15 - cfb_tia_rfe / 100, 0, 15)); } } else //if(rx_lpf_IF > 54e6) @@ -718,14 +721,14 @@ uint8_t TuneTxFilterSetup(const float_type tx_lpf_IF) const float_type freq = (16.0 / 20.0) * tx_lpf_IF / 1e6; int16_t rcal_lpflad_tbb = pow(freq, 4) * 1.29858903647958e-16 + pow(freq, 3) * (-0.000110746929967704) + pow(freq, 2) * 0.00277593485991029 + freq * 21.0384293169607 + (-48.4092606238297); - Modify_SPI_Reg_bits(RCAL_LPFLAD_TBB, std::clamp(rcal_lpflad_tbb, 0, 255)); + Modify_SPI_Reg_bits(RCAL_LPFLAD_TBB, clamp(rcal_lpflad_tbb, 0, 255)); } else { const float_type freq = tx_lpf_IF / 1e6; int16_t rcal_lpfh_tbb = pow(freq, 4) * 1.10383261611112e-06 + pow(freq, 3) * (-0.000210800032517545) + pow(freq, 2) * 0.0190494874803309 + freq * 1.43317445923528 + (-47.6950779298333); - Modify_SPI_Reg_bits(RCAL_LPFH_TBB, std::clamp(rcal_lpfh_tbb, 0, 255)); + Modify_SPI_Reg_bits(RCAL_LPFH_TBB, clamp(rcal_lpfh_tbb, 0, 255)); } //CGEN @@ -800,13 +803,13 @@ static uint8_t SearchTxFilterCCAL_RCAL(uint16_t addr, uint8_t msblsb) uint8_t R = Get_SPI_Reg_bits(addr, msblsb); if (R == 0 || R == 255) return MCU_NO_ERROR; // reached filter bandwidth limit - Modify_SPI_Reg_bits(addr, msblsb, std::clamp(R + rcal_step, 0, 255)); + Modify_SPI_Reg_bits(addr, msblsb, clamp(R + rcal_step, 0, 255)); Modify_SPI_Reg_bits(CCAL_LPFLAD_TBB, 16); } else if (needToChangeCCAL) { uint8_t ccal_lpflad_tbb = Get_SPI_Reg_bits(CCAL_LPFLAD_TBB); - ccal_lpflad_tbb = std::clamp(ccal_lpflad_tbb + 1, 0, 31); + ccal_lpflad_tbb = clamp(ccal_lpflad_tbb + 1, 0, 31); Modify_SPI_Reg_bits(CCAL_LPFLAD_TBB, ccal_lpflad_tbb); } --iterationsLeft; @@ -862,3 +865,7 @@ TxFilterSearchEndStage : { return MCU_NO_ERROR; } + +#ifdef __cplusplus +} +#endif diff --git a/src/mcu_program/common_src/lms7002m_filters.h b/src/mcu_program/common_src/lms7002m_filters.h index 68e36cf71..9d59019e5 100644 --- a/src/mcu_program/common_src/lms7002m_filters.h +++ b/src/mcu_program/common_src/lms7002m_filters.h @@ -3,7 +3,15 @@ #include "typedefs.h" +#ifdef __cplusplus +extern "C" { +#endif + uint8_t TuneTxFilter(const float_type bandwidth); uint8_t TuneRxFilter(const float_type rx_lpf_freq_RF); +#ifdef __cplusplus +} +#endif + #endif From b6671ec66b1fae44ceb50b77688ed6eac7d8fcf4 Mon Sep 17 00:00:00 2001 From: Dominykas Date: Thu, 22 Feb 2024 15:20:44 +0200 Subject: [PATCH 13/13] Fix Windows compilation --- src/mcu_program/spi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mcu_program/spi.cpp b/src/mcu_program/spi.cpp index 24590a6b1..e2f8f2e1e 100644 --- a/src/mcu_program/spi.cpp +++ b/src/mcu_program/spi.cpp @@ -5,8 +5,8 @@ static lime::LMS7002M* serPort; -extern float bandwidthRF; -extern float RefClk; +extern "C" float bandwidthRF; +extern "C" float RefClk; void SetupCalibrations(lime::LMS7002M* chip, double BW) {