Skip to content

Commit

Permalink
Merge branch 'litepcie-update' into litepcie-update-windows-fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
DominykasPetke committed Feb 23, 2024
2 parents 9de554f + 4f38d26 commit 9eaea63
Show file tree
Hide file tree
Showing 50 changed files with 1,051 additions and 917 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ if(CMAKE_COMPILER_IS_GNUCXX)
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")
Expand Down
2 changes: 1 addition & 1 deletion SoapyLMS7/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(direction)] = rate;
return;
}

Expand Down
40 changes: 20 additions & 20 deletions amarisoft-plugin/trx_limesuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (int64_t)n * 1000000 + (((int64_t)r * 1000000) / fs);
return n * 1000000 + (r * 1000000 / fs);
}

struct PortChPair {
Expand Down Expand Up @@ -297,7 +297,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<LimeState*>(s->opaque);
for (long p = 0; p < lime->deviceCount; ++p)
{
StreamStatus& stats = portStreamStates[p];
Expand All @@ -311,7 +311,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<LimeState*>(s->opaque);
std::stringstream ss;
for (long p = 0; p < lime->deviceCount; ++p)
{
Expand All @@ -332,7 +332,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<char*>(malloc(len + 1));
cb(buffer, "%s\n", ss.str().c_str());
}

Expand All @@ -351,7 +351,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<LimeState*>(s->opaque);
int samplesConsumed =
lime->device[port]->StreamTx(lime->chipIndex[port], reinterpret_cast<const lime::complex32f_t**>(samples), count, &meta);
if (logVerbosity == LogLevel::DEBUG && samplesConsumed != count)
Expand All @@ -372,7 +372,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<LimeState*>(s->opaque);

SDRDevice::StreamMeta meta;
meta.useTimestamp = false;
Expand Down Expand Up @@ -497,7 +497,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<LimeState*>(s1->opaque);
int txExpectedSamples = lime->samplesInPacket[0];
if (lime->streamCfg[0].extraConfig.txSamplesInPacket > 0)
{
Expand All @@ -509,7 +509,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<LimeState*>(s1->opaque);
const PortChPair& pair = gMapTxChannelToPortCh[channel_num];
if (s->rxPowerAvailable[pair.port][pair.ch])
{
Expand All @@ -522,7 +522,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<LimeState*>(s1->opaque);
const PortChPair& pair = gMapTxChannelToPortCh[channel_num];
if (s->txPowerAvailable[pair.port][pair.ch])
{
Expand All @@ -537,9 +537,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<LimeState*>(s1->opaque);
int row = gain;
if (row < 0 || row >= (int)(sizeof(txGainTable) / sizeof(TxGainRow)))
if (row < 0 || row >= static_cast<int>(sizeof(txGainTable) / sizeof(TxGainRow)))
return;

std::lock_guard<std::mutex> lk(gainsMutex);
Expand All @@ -560,9 +560,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<LimeState*>(s1->opaque);
int row = gain;
if (row < 0 || row >= (int)(sizeof(rxGainTable) / sizeof(RxGainRow)))
if (row < 0 || row >= static_cast<int>(sizeof(rxGainTable) / sizeof(RxGainRow)))
return;

std::lock_guard<std::mutex> lk(gainsMutex);
Expand All @@ -583,7 +583,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<LimeState*>(s1->opaque);

try
{
Expand All @@ -598,7 +598,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<float>(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];
Expand Down Expand Up @@ -649,7 +649,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<uint8_t>(p), static_cast<uint8_t>(ch) };
Log(LogLevel::INFO,
"Port[%i] Rx CH[%i] %s, SR: %.3f MHz BW: %.3f MHz | chipIndex: %i, path: %i('%s')\n",
p,
Expand Down Expand Up @@ -696,7 +696,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<uint8_t>(p), static_cast<uint8_t>(ch) };
Log(LogLevel::INFO,
"Port[%i] Tx CH[%i] %s, SR: %.3f MHz BW: %.3f MHz | chipIndex: %i, path: %i('%s')\n",
p,
Expand Down Expand Up @@ -790,7 +790,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState)
}

stream.statusCallback = OnStreamStatusChange;
stream.userData = (void*)&portStreamStates[p];
stream.userData = static_cast<void*>(&portStreamStates[p]);
stream.hintSampleRate = samplingRate;

stream.extraConfig = lime->streamCfg[p].extraConfig;
Expand Down Expand Up @@ -830,7 +830,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<LimeState*>(s1->opaque);
for (int p = 0; p < lime->deviceCount; ++p)
{
SDRDevice* portDevice = lime->device[p];
Expand Down
64 changes: 32 additions & 32 deletions src/ADF4002/ADF4002.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int ADF4002::UploadConfig()

std::vector<uint32_t> 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<uint32_t>(data[i]) << 16 | static_cast<uint32_t>(data[i + 1]) << 8 | data[i + 2]);

// ADF4002 needs to be writen 4 values of 24 bits
mComms->SPI(dataWr.data(), nullptr, 4);
Expand Down Expand Up @@ -95,7 +95,7 @@ void ADF4002::MakeData()
m_registers[0x00] = 0x00;
//R Value LSB
itmp = txtRCnt;
btmp = (char)itmp;
btmp = static_cast<char>(itmp);
btmp = btmp << 2;
m_registers[0x00] |= btmp;
//Addr
Expand All @@ -106,20 +106,20 @@ void ADF4002::MakeData()
//======= register addr 0x01 =======
m_registers[0x01] = 0x00;
//R Value MSB
btmp = (char)(itmp >> 6);
btmp = static_cast<char>((itmp >> 6));
btmp = btmp << 0;
m_registers[0x01] |= btmp;

//======= register addr 0x02 =======
m_registers[0x02] = 0x00;
//Anti-Backlash
btmp = (char)cmbABW;
btmp = static_cast<char>(cmbABW);
if (btmp > 0)
btmp++;
btmp = btmp << 0;
m_registers[0x02] |= btmp;
//Lock Detact Precision
btmp = (char)cmbLDP;
btmp = static_cast<char>(cmbLDP);
btmp = btmp << 4;
m_registers[0x02] |= btmp;

Expand All @@ -134,19 +134,19 @@ void ADF4002::MakeData()
m_registers[0x04] = 0x00;
//N Value LSB
itmp = txtNCnt;
btmp = (char)itmp;
btmp = static_cast<char>(itmp);
btmp = btmp << 0;
m_registers[0x04] |= btmp;

//======= register addr 0x05 =======
m_registers[0x05] = 0x00;
//N Value MSB
itmp = txtNCnt;
btmp = (char)(itmp >> 8);
btmp = static_cast<char>((itmp >> 8));
btmp = btmp << 0;
m_registers[0x05] |= btmp;
//CP Gain
btmp = (char)cmbCPG;
btmp = static_cast<char>(cmbCPG);
btmp = btmp << 5;
m_registers[0x05] |= btmp;

Expand All @@ -157,55 +157,55 @@ void ADF4002::MakeData()
btmp = btmp << 0;
m_registers[0x06] |= btmp;
//Counter Reset
btmp = (char)rgrCR_f;
btmp = static_cast<char>(rgrCR_f);
btmp = btmp << 2;
m_registers[0x06] |= btmp;
//PD 1
btmp = (char)rgrPD1_f;
btmp = static_cast<char>(rgrPD1_f);
btmp = btmp << 3;
m_registers[0x06] |= btmp;
//Muxout Control
btmp = (char)cmbMOC_f;
btmp = static_cast<char>(cmbMOC_f);
btmp = btmp << 4;
m_registers[0x06] |= btmp;
//PD Polarity
btmp = (char)rgrPDP_f;
btmp = static_cast<char>(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<char>(rgrCPS_f);
btmp = btmp << 0;
m_registers[0x07] |= btmp;
//Fastlock
btmp = (char)cmbFL_f;
btmp = static_cast<char>(cmbFL_f);
if (btmp > 0)
btmp++;
btmp = btmp << 1;
m_registers[0x07] |= btmp;
//Timer Counter
btmp = (char)cmbTC_f;
btmp = static_cast<char>(cmbTC_f);
btmp = btmp << 3;
m_registers[0x07] |= btmp;
//Current Setting 1 MSB
btmp = (char)cmbCS1_f;
btmp = static_cast<char>(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<char>(cmbCS1_f);
btmp = btmp >> 1;
m_registers[0x08] |= btmp;
//Current Setting 2
btmp = (char)cmbCS2_f;
btmp = static_cast<char>(cmbCS2_f);
btmp = btmp << 2;
m_registers[0x08] |= btmp;
//PD 2
btmp = (char)rgrPD2_f;
btmp = static_cast<char>(rgrPD2_f);
btmp = btmp << 5;
m_registers[0x08] |= btmp;

Expand All @@ -216,55 +216,55 @@ void ADF4002::MakeData()
btmp = btmp << 0;
m_registers[0x09] |= btmp;
//Counter Reset
btmp = (char)rgrCR_i;
btmp = static_cast<char>(rgrCR_i);
btmp = btmp << 2;
m_registers[0x09] |= btmp;
//PD 1
btmp = (char)rgrPD1_i;
btmp = static_cast<char>(rgrPD1_i);
btmp = btmp << 3;
m_registers[0x09] |= btmp;
//Muxout Control
btmp = (char)cmbMOC_i;
btmp = static_cast<char>(cmbMOC_i);
btmp = btmp << 4;
m_registers[0x09] |= btmp;
//PD Polarity
btmp = (char)rgrPDP_i;
btmp = static_cast<char>(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<char>(rgrCPS_i);
btmp = btmp << 0;
m_registers[0x0A] |= btmp;
//Fastlock
btmp = (char)cmbFL_i;
btmp = static_cast<char>(cmbFL_i);
if (btmp > 0)
btmp++;
btmp = btmp << 1;
m_registers[0x0A] |= btmp;
//Timer Counter
btmp = (char)cmbTC_i;
btmp = static_cast<char>(cmbTC_i);
btmp = btmp << 3;
m_registers[0x0A] |= btmp;
//Current Setting 1 MSB
btmp = (char)cmbCS1_i;
btmp = static_cast<char>(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<char>(cmbCS1_i);
btmp = btmp >> 1;
m_registers[0x0B] |= btmp;
//Current Setting 2
btmp = (char)cmbCS2_i;
btmp = static_cast<char>(cmbCS2_i);
btmp = btmp << 2;
m_registers[0x0B] |= btmp;
//PD 2
btmp = (char)rgrPD2_i;
btmp = static_cast<char>(rgrPD2_i);
btmp = btmp << 5;
m_registers[0x0B] |= btmp;

Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 9eaea63

Please sign in to comment.