added float control on bandwidth and sample rate in the API

fixed enums of bandwidth
pull/146/head
David Michaeli 2023-09-28 15:11:01 +00:00
rodzic 6016e3c1e2
commit 4228a07223
6 zmienionych plików z 142 dodań i 54 usunięć

Wyświetl plik

@ -95,6 +95,7 @@ int cariboulite_init(bool force_fpga_prog, cariboulite_log_level_en log_lvl)
//=============================================================================
void cariboulite_close(void)
{
if (!ctx.initialized) return;
cariboulite_release_driver(&sys);
}

Wyświetl plik

@ -150,7 +150,7 @@ unsigned int cariboulite_get_sn();
* passed to the radio manipulation functions in "cariboulite_radio.h"
*
* @param type the radio channel (6G/2.4G or ISM)
* @return 0 (sucess), -1 (fail)
* @return the handle of the channel, or NULL if invalid channel id
*/
cariboulite_radio_state_st* cariboulite_get_radio(cariboulite_channel_en ch);

Wyświetl plik

@ -21,6 +21,11 @@
#define GET_MODEM_CH(rad_ch) ((rad_ch)==cariboulite_channel_s1g ? at86rf215_rf_channel_900mhz : at86rf215_rf_channel_2400mhz)
#define GET_SMI_CH(rad_ch) ((rad_ch)==cariboulite_channel_s1g ? caribou_smi_channel_900 : caribou_smi_channel_2400)
static float sample_rate_middles[] = {3000, 1666, 1166, 900, 733, 583, 450};
static float rx_bandwidth_middles[] = {225, 281, 356, 450, 562, 706, 893, 1125, 1406, 1781, 2250};
static float tx_bandwidth_middles[] = {90, 112, 142, 180, 225, 282, 357, 450, 562, 712, 900};
//=========================================================================
int cariboulite_radio_init(cariboulite_radio_state_st* radio, sys_st *sys, cariboulite_channel_en type)
{
@ -182,19 +187,6 @@ int cariboulite_radio_set_rx_bandwidth(cariboulite_radio_state_st* radio,
cariboulite_radio_rx_bw_en rx_bw)
{
cariboulite_radio_f_cut_en fcut = cariboulite_radio_rx_f_cut_half_fs;
// Automatically calculate the digital f_cut
if (rx_bw >= cariboulite_radio_rx_bw_BW160KHZ_IF250KHZ && rx_bw <= cariboulite_radio_rx_bw_BW500KHZ_IF500KHZ)
fcut = cariboulite_radio_rx_f_cut_0_25_half_fs;
else if (rx_bw >= cariboulite_radio_rx_bw_BW630KHZ_IF1000KHZ && rx_bw <= cariboulite_radio_rx_bw_BW630KHZ_IF1000KHZ)
fcut = cariboulite_radio_rx_f_cut_0_375_half_fs;
else if (rx_bw >= cariboulite_radio_rx_bw_BW800KHZ_IF1000KHZ && rx_bw <= cariboulite_radio_rx_bw_BW1000KHZ_IF1000KHZ)
fcut = cariboulite_radio_rx_f_cut_0_5_half_fs;
else if (rx_bw >= cariboulite_radio_rx_bw_BW1250KHZ_IF2000KHZ && rx_bw <= cariboulite_radio_rx_bw_BW1250KHZ_IF2000KHZ)
fcut = cariboulite_radio_rx_f_cut_0_75_half_fs;
else
fcut = cariboulite_radio_rx_f_cut_half_fs;
radio->rx_fcut = fcut;
at86rf215_radio_set_rx_bw_samp_st cfg =
@ -213,6 +205,27 @@ int cariboulite_radio_set_rx_bandwidth(cariboulite_radio_state_st* radio,
return 0;
}
//=========================================================================
int cariboulite_radio_set_rx_bandwidth_flt(cariboulite_radio_state_st* radio, float bw_hz)
{
cariboulite_radio_rx_bw_en bw = cariboulite_radio_rx_bw_200KHz;
if (bw_hz <= rx_bandwidth_middles[0]) bw = cariboulite_radio_rx_bw_200KHz;
else if (bw_hz <= rx_bandwidth_middles[1]) bw = cariboulite_radio_rx_bw_250KHz;
else if (bw_hz <= rx_bandwidth_middles[2]) bw = cariboulite_radio_rx_bw_312KHz;
else if (bw_hz <= rx_bandwidth_middles[3]) bw = cariboulite_radio_rx_bw_400KHz;
else if (bw_hz <= rx_bandwidth_middles[4]) bw = cariboulite_radio_rx_bw_500KHz;
else if (bw_hz <= rx_bandwidth_middles[5]) bw = cariboulite_radio_rx_bw_625KHz;
else if (bw_hz <= rx_bandwidth_middles[6]) bw = cariboulite_radio_rx_bw_787KHz;
else if (bw_hz <= rx_bandwidth_middles[7]) bw = cariboulite_radio_rx_bw_1000KHz;
else if (bw_hz <= rx_bandwidth_middles[8]) bw = cariboulite_radio_rx_bw_1250KHz;
else if (bw_hz <= rx_bandwidth_middles[9]) bw = cariboulite_radio_rx_bw_1562KHz;
else if (bw_hz <= rx_bandwidth_middles[10]) bw = cariboulite_radio_rx_bw_2000KHz;
else bw = cariboulite_radio_rx_bw_2500KHz;
return cariboulite_radio_set_rx_bandwidth(radio, bw);
}
//=========================================================================
int cariboulite_radio_get_rx_bandwidth(cariboulite_radio_state_st* radio,
cariboulite_radio_rx_bw_en *rx_bw)
@ -226,6 +239,33 @@ int cariboulite_radio_get_rx_bandwidth(cariboulite_radio_state_st* radio,
return 0;
}
//=========================================================================
int cariboulite_radio_get_rx_bandwidth_flt(cariboulite_radio_state_st* radio, float* bw_hz)
{
cariboulite_radio_rx_bw_en bw;
cariboulite_radio_get_rx_bandwidth(radio, &bw);
if (bw_hz == NULL) return 0;
switch(bw)
{
case cariboulite_radio_rx_bw_200KHz: *bw_hz = 200e5; break;
case cariboulite_radio_rx_bw_250KHz: *bw_hz = 250e5; break;
case cariboulite_radio_rx_bw_312KHz: *bw_hz = 312e5; break;
case cariboulite_radio_rx_bw_400KHz: *bw_hz = 400e5; break;
case cariboulite_radio_rx_bw_500KHz: *bw_hz = 500e5; break;
case cariboulite_radio_rx_bw_625KHz: *bw_hz = 625e5; break;
case cariboulite_radio_rx_bw_787KHz: *bw_hz = 787e5; break;
case cariboulite_radio_rx_bw_1000KHz: *bw_hz = 1000e5; break;
case cariboulite_radio_rx_bw_1250KHz: *bw_hz = 1250e5; break;
case cariboulite_radio_rx_bw_1562KHz: *bw_hz = 1562e5; break;
case cariboulite_radio_rx_bw_2000KHz: *bw_hz = 2000e5; break;
case cariboulite_radio_rx_bw_2500KHz:
default: *bw_hz = 2500e5; break;
}
return 0;
}
//=========================================================================
int cariboulite_radio_set_rx_samp_cutoff(cariboulite_radio_state_st* radio,
cariboulite_radio_sample_rate_en rx_sample_rate,
@ -265,6 +305,24 @@ int cariboulite_radio_set_rx_samp_cutoff(cariboulite_radio_state_st* radio,
return 0;
}
//=========================================================================
int cariboulite_radio_set_rx_sample_rate_flt(cariboulite_radio_state_st* radio, float sample_rate_hz)
{
cariboulite_radio_sample_rate_en rx_sample_rate = cariboulite_radio_rx_sample_rate_4000khz;
cariboulite_radio_f_cut_en rx_cutoff = radio->rx_fcut;
if (sample_rate_hz >= sample_rate_middles[0]) rx_sample_rate = cariboulite_radio_rx_sample_rate_4000khz;
else if (sample_rate_hz >= sample_rate_middles[1]) rx_sample_rate = cariboulite_radio_rx_sample_rate_2000khz;
else if (sample_rate_hz >= sample_rate_middles[2]) rx_sample_rate = cariboulite_radio_rx_sample_rate_1333khz;
else if (sample_rate_hz >= sample_rate_middles[3]) rx_sample_rate = cariboulite_radio_rx_sample_rate_1000khz;
else if (sample_rate_hz >= sample_rate_middles[4]) rx_sample_rate = cariboulite_radio_rx_sample_rate_800khz;
else if (sample_rate_hz >= sample_rate_middles[5]) rx_sample_rate = cariboulite_radio_rx_sample_rate_666khz;
else if (sample_rate_hz >= sample_rate_middles[6]) rx_sample_rate = cariboulite_radio_rx_sample_rate_500khz;
else rx_sample_rate = cariboulite_radio_rx_sample_rate_400khz;
return cariboulite_radio_set_rx_samp_cutoff(radio, rx_sample_rate, rx_cutoff);
}
//=========================================================================
int cariboulite_radio_get_rx_samp_cutoff(cariboulite_radio_state_st* radio,
cariboulite_radio_sample_rate_en *rx_sample_rate,
@ -276,6 +334,30 @@ int cariboulite_radio_get_rx_samp_cutoff(cariboulite_radio_state_st* radio,
return 0;
}
//=========================================================================
int cariboulite_radio_get_rx_sample_rate_flt(cariboulite_radio_state_st* radio, float *sample_rate_hz)
{
cariboulite_radio_sample_rate_en rx_sample_rate;
cariboulite_radio_get_rx_samp_cutoff(radio, &rx_sample_rate, NULL);
if (sample_rate_hz == NULL) return 0;
*sample_rate_hz = 4000000;
switch(rx_sample_rate)
{
case cariboulite_radio_rx_sample_rate_4000khz: *sample_rate_hz = 4000000; break;
case cariboulite_radio_rx_sample_rate_2000khz: *sample_rate_hz = 2000000; break;
case cariboulite_radio_rx_sample_rate_1333khz: *sample_rate_hz = 1333000; break;
case cariboulite_radio_rx_sample_rate_1000khz: *sample_rate_hz = 1000000; break;
case cariboulite_radio_rx_sample_rate_800khz: *sample_rate_hz = 800000; break;
case cariboulite_radio_rx_sample_rate_666khz: *sample_rate_hz = 666000; break;
case cariboulite_radio_rx_sample_rate_500khz: *sample_rate_hz = 500000; break;
case cariboulite_radio_rx_sample_rate_400khz: *sample_rate_hz = 400000; break;
default: *sample_rate_hz = 4000000; break;
}
return 0;
}
//=========================================================================
int cariboulite_radio_set_tx_power(cariboulite_radio_state_st* radio, int tx_power_dbm)
{

Wyświetl plik

@ -54,18 +54,18 @@ typedef enum
typedef enum
{
cariboulite_radio_rx_bw_BW160KHZ_IF250KHZ = 0x0, // cariboulite_radio_rx_f_cut_0_25_half_fs
cariboulite_radio_rx_bw_BW200KHZ_IF250KHZ = 0x1, // cariboulite_radio_rx_f_cut_0_25_half_fs
cariboulite_radio_rx_bw_BW250KHZ_IF250KHZ = 0x2, // cariboulite_radio_rx_f_cut_0_25_half_fs
cariboulite_radio_rx_bw_BW320KHZ_IF500KHZ = 0x3, // cariboulite_radio_rx_f_cut_0_25_half_fs
cariboulite_radio_rx_bw_BW400KHZ_IF500KHZ = 0x4, // cariboulite_radio_rx_f_cut_0_25_half_fs
cariboulite_radio_rx_bw_BW500KHZ_IF500KHZ = 0x5, // cariboulite_radio_rx_f_cut_0_25_half_fs
cariboulite_radio_rx_bw_BW630KHZ_IF1000KHZ = 0x6, // cariboulite_radio_rx_f_cut_0_375_half_fs
cariboulite_radio_rx_bw_BW800KHZ_IF1000KHZ = 0x7, // cariboulite_radio_rx_f_cut_0_5_half_fs
cariboulite_radio_rx_bw_BW1000KHZ_IF1000KHZ = 0x8, // cariboulite_radio_rx_f_cut_0_5_half_fs
cariboulite_radio_rx_bw_BW1250KHZ_IF2000KHZ = 0x9, // cariboulite_radio_rx_f_cut_0_75_half_fs
cariboulite_radio_rx_bw_BW1600KHZ_IF2000KHZ = 0xA, // cariboulite_radio_rx_f_cut_half_fs
cariboulite_radio_rx_bw_BW2000KHZ_IF2000KHZ = 0xB, // cariboulite_radio_rx_f_cut_half_fs
cariboulite_radio_rx_bw_200KHz = 0x0,
cariboulite_radio_rx_bw_250KHz = 0x1,
cariboulite_radio_rx_bw_312KHz = 0x2,
cariboulite_radio_rx_bw_400KHz = 0x3,
cariboulite_radio_rx_bw_500KHz = 0x4,
cariboulite_radio_rx_bw_625KHz = 0x5,
cariboulite_radio_rx_bw_787KHz = 0x6,
cariboulite_radio_rx_bw_1000KHz = 0x7,
cariboulite_radio_rx_bw_1250KHz = 0x8,
cariboulite_radio_rx_bw_1562KHz = 0x9,
cariboulite_radio_rx_bw_2000KHz = 0xA,
cariboulite_radio_rx_bw_2500KHz = 0xB,
} cariboulite_radio_rx_bw_en;
typedef enum
@ -324,6 +324,7 @@ int cariboulite_radio_get_rx_gain_limits(cariboulite_radio_state_st* radio,
*/
int cariboulite_radio_set_rx_bandwidth(cariboulite_radio_state_st* radio,
cariboulite_radio_rx_bw_en rx_bw);
int cariboulite_radio_set_rx_bandwidth_flt(cariboulite_radio_state_st* radio, float bw_hz);
/**
* @brief Modem get RX analog bandwidth
@ -336,6 +337,7 @@ int cariboulite_radio_set_rx_bandwidth(cariboulite_radio_state_st* radio,
*/
int cariboulite_radio_get_rx_bandwidth(cariboulite_radio_state_st* radio,
cariboulite_radio_rx_bw_en *rx_bw);
int cariboulite_radio_get_rx_bandwidth_flt(cariboulite_radio_state_st* radio, float* bw_hz);
/**
* @brief Modem set RX sample cut-off bandwidth
@ -350,6 +352,7 @@ int cariboulite_radio_get_rx_bandwidth(cariboulite_radio_state_st* radio,
int cariboulite_radio_set_rx_samp_cutoff(cariboulite_radio_state_st* radio,
cariboulite_radio_sample_rate_en rx_sample_rate,
cariboulite_radio_f_cut_en rx_cutoff);
int cariboulite_radio_set_rx_sample_rate_flt(cariboulite_radio_state_st* radio, float sample_rate_hz);
/**
* @brief Modem get RX sample cut-off bandwidth
@ -364,6 +367,7 @@ int cariboulite_radio_set_rx_samp_cutoff(cariboulite_radio_state_st* radio,
int cariboulite_radio_get_rx_samp_cutoff(cariboulite_radio_state_st* radio,
cariboulite_radio_sample_rate_en *rx_sample_rate,
cariboulite_radio_f_cut_en *rx_cutoff);
int cariboulite_radio_get_rx_sample_rate_flt(cariboulite_radio_state_st* radio, float *sample_rate_hz);
/**
* @brief Modem set TX power

Wyświetl plik

@ -393,12 +393,12 @@ int cariboulite_init_submodules (sys_st* sys)
cariboulite_radio_set_rx_samp_cutoff(&sys->radio_low, cariboulite_radio_rx_sample_rate_4000khz, cariboulite_radio_rx_f_cut_half_fs);
cariboulite_radio_set_tx_samp_cutoff(&sys->radio_low, cariboulite_radio_rx_sample_rate_4000khz, cariboulite_radio_rx_f_cut_half_fs);
cariboulite_radio_set_rx_bandwidth(&sys->radio_low, cariboulite_radio_rx_bw_BW2000KHZ_IF2000KHZ);
cariboulite_radio_set_rx_bandwidth(&sys->radio_low, cariboulite_radio_rx_bw_2500KHz);
cariboulite_radio_set_tx_bandwidth(&sys->radio_low, cariboulite_radio_tx_cut_off_1000khz);
cariboulite_radio_set_rx_samp_cutoff(&sys->radio_high, cariboulite_radio_rx_sample_rate_4000khz, cariboulite_radio_rx_f_cut_half_fs);
cariboulite_radio_set_tx_samp_cutoff(&sys->radio_high, cariboulite_radio_rx_sample_rate_4000khz, cariboulite_radio_rx_f_cut_half_fs);
cariboulite_radio_set_rx_bandwidth(&sys->radio_high, cariboulite_radio_rx_bw_BW2000KHZ_IF2000KHZ);
cariboulite_radio_set_rx_bandwidth(&sys->radio_high, cariboulite_radio_rx_bw_2500KHz);
cariboulite_radio_set_tx_bandwidth(&sys->radio_high, cariboulite_radio_tx_cut_off_1000khz);
cariboulite_radio_activate_channel(&sys->radio_low, cariboulite_channel_dir_rx, false);
@ -816,5 +816,6 @@ void cariboulite_print_board_info(sys_st *sys, bool log)
cariboulite_radio_state_st* cariboulite_get_radio_handle(sys_st* sys, cariboulite_channel_en type)
{
if (type == cariboulite_channel_s1g) return &sys->radio_low;
else return &sys->radio_high;
else if (type == cariboulite_channel_hif) return &sys->radio_high;
return NULL;
}

Wyświetl plik

@ -311,38 +311,38 @@ std::vector<double> Cariboulite::listSampleRates( const int direction, const siz
static cariboulite_radio_rx_bw_en convertRxBandwidth(double bw_numeric)
{
float fact = BW_SHIFT_FACT;
if (fabs(bw_numeric - (160000*fact)) < 1) return cariboulite_radio_rx_bw_BW160KHZ_IF250KHZ;
if (fabs(bw_numeric - (200000*fact)) < 1) return cariboulite_radio_rx_bw_BW200KHZ_IF250KHZ;
if (fabs(bw_numeric - (250000*fact)) < 1) return cariboulite_radio_rx_bw_BW250KHZ_IF250KHZ;
if (fabs(bw_numeric - (320000*fact)) < 1) return cariboulite_radio_rx_bw_BW320KHZ_IF500KHZ;
if (fabs(bw_numeric - (400000*fact)) < 1) return cariboulite_radio_rx_bw_BW400KHZ_IF500KHZ;
if (fabs(bw_numeric - (500000*fact)) < 1) return cariboulite_radio_rx_bw_BW500KHZ_IF500KHZ;
if (fabs(bw_numeric - (630000*fact)) < 1) return cariboulite_radio_rx_bw_BW630KHZ_IF1000KHZ;
if (fabs(bw_numeric - (800000*fact)) < 1) return cariboulite_radio_rx_bw_BW800KHZ_IF1000KHZ;
if (fabs(bw_numeric - (1000000*fact)) < 1) return cariboulite_radio_rx_bw_BW1000KHZ_IF1000KHZ;
if (fabs(bw_numeric - (1250000*fact)) < 1) return cariboulite_radio_rx_bw_BW1250KHZ_IF2000KHZ;
if (fabs(bw_numeric - (1600000*fact)) < 1) return cariboulite_radio_rx_bw_BW1600KHZ_IF2000KHZ;
if (fabs(bw_numeric - (2000000*fact)) < 1) return cariboulite_radio_rx_bw_BW2000KHZ_IF2000KHZ;
if (fabs(bw_numeric - (160000*fact)) < 1) return cariboulite_radio_rx_bw_200KHz;
if (fabs(bw_numeric - (200000*fact)) < 1) return cariboulite_radio_rx_bw_250KHz;
if (fabs(bw_numeric - (250000*fact)) < 1) return cariboulite_radio_rx_bw_312KHz;
if (fabs(bw_numeric - (320000*fact)) < 1) return cariboulite_radio_rx_bw_400KHz;
if (fabs(bw_numeric - (400000*fact)) < 1) return cariboulite_radio_rx_bw_500KHz;
if (fabs(bw_numeric - (500000*fact)) < 1) return cariboulite_radio_rx_bw_625KHz;
if (fabs(bw_numeric - (630000*fact)) < 1) return cariboulite_radio_rx_bw_787KHz;
if (fabs(bw_numeric - (800000*fact)) < 1) return cariboulite_radio_rx_bw_1000KHz;
if (fabs(bw_numeric - (1000000*fact)) < 1) return cariboulite_radio_rx_bw_1250KHz;
if (fabs(bw_numeric - (1250000*fact)) < 1) return cariboulite_radio_rx_bw_1562KHz;
if (fabs(bw_numeric - (1600000*fact)) < 1) return cariboulite_radio_rx_bw_2000KHz;
if (fabs(bw_numeric - (2000000*fact)) < 1) return cariboulite_radio_rx_bw_2500KHz;
return cariboulite_radio_rx_bw_BW2000KHZ_IF2000KHZ;
return cariboulite_radio_rx_bw_2500KHz;
}
//========================================================
static double convertRxBandwidth(cariboulite_radio_rx_bw_en bw_en)
{
float fact = BW_SHIFT_FACT;
if (cariboulite_radio_rx_bw_BW160KHZ_IF250KHZ == bw_en) return 160000 * fact;
if (cariboulite_radio_rx_bw_BW200KHZ_IF250KHZ == bw_en) return 200000 * fact;
if (cariboulite_radio_rx_bw_BW250KHZ_IF250KHZ == bw_en) return 250000 * fact;
if (cariboulite_radio_rx_bw_BW320KHZ_IF500KHZ == bw_en) return 320000 * fact;
if (cariboulite_radio_rx_bw_BW400KHZ_IF500KHZ == bw_en) return 400000 * fact;
if (cariboulite_radio_rx_bw_BW500KHZ_IF500KHZ == bw_en) return 500000 * fact;
if (cariboulite_radio_rx_bw_BW630KHZ_IF1000KHZ == bw_en) return 630000 * fact;
if (cariboulite_radio_rx_bw_BW800KHZ_IF1000KHZ == bw_en) return 800000 * fact;
if (cariboulite_radio_rx_bw_BW1000KHZ_IF1000KHZ == bw_en) return 1000000 * fact;
if (cariboulite_radio_rx_bw_BW1250KHZ_IF2000KHZ == bw_en) return 1250000 * fact;
if (cariboulite_radio_rx_bw_BW1600KHZ_IF2000KHZ == bw_en) return 1600000 * fact;
if (cariboulite_radio_rx_bw_BW2000KHZ_IF2000KHZ == bw_en) return 2000000 * fact;
if (cariboulite_radio_rx_bw_200KHz == bw_en) return 160000 * fact;
if (cariboulite_radio_rx_bw_250KHz == bw_en) return 200000 * fact;
if (cariboulite_radio_rx_bw_312KHz == bw_en) return 250000 * fact;
if (cariboulite_radio_rx_bw_400KHz == bw_en) return 320000 * fact;
if (cariboulite_radio_rx_bw_500KHz == bw_en) return 400000 * fact;
if (cariboulite_radio_rx_bw_625KHz == bw_en) return 500000 * fact;
if (cariboulite_radio_rx_bw_787KHz == bw_en) return 630000 * fact;
if (cariboulite_radio_rx_bw_1000KHz == bw_en) return 800000 * fact;
if (cariboulite_radio_rx_bw_1250KHz == bw_en) return 1000000 * fact;
if (cariboulite_radio_rx_bw_1562KHz == bw_en) return 1250000 * fact;
if (cariboulite_radio_rx_bw_2000KHz == bw_en) return 1600000 * fact;
if (cariboulite_radio_rx_bw_2500KHz == bw_en) return 2000000 * fact;
return 2000000 * fact;
}