[MERGED] osmo-trx[master]: uhd: Use map container for for device parameter access
Tom Tsou has submitted this change and it was merged. Change subject: uhd: Use map container for for device parameter access .. uhd: Use map container for for device parameter access OsmoTRX is written in C++ so we might as well use built-in container types when applicable. Map access allows removal of significant amounts of special device handling code. Aggregate device rates and timing offsets into a single table with access keyed by device/tx-sps/rx-sps tuples. Change-Id: I8660f75a2b2a13488b913c07637bdd0f5f0f4cf9 Signed-off-by: Tom Tsou--- M Transceiver52M/UHDDevice.cpp 1 file changed, 83 insertions(+), 273 deletions(-) Approvals: Tom Tsou: Looks good to me, approved Jenkins Builder: Verified diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp index ce6d1be..cea68cc 100644 --- a/Transceiver52M/UHDDevice.cpp +++ b/Transceiver52M/UHDDevice.cpp @@ -21,6 +21,7 @@ * See the COPYING file in the main directory for details. */ +#include #include "radioDevice.h" #include "Threads.h" #include "Logger.h" @@ -37,12 +38,6 @@ #include #endif -#define B2XX_CLK_RT 26e6 -#define B2XX_MCBTS_CLK_RT 51.2e6 -#define E1XX_CLK_RT 52e6 -#define LIMESDR_CLK_RT (GSMRATE*32) -#define B100_BASE_RT 40 -#define USRP2_BASE_RT390625 #define USRP_TX_AMPL 0.3 #define UMTRX_TX_AMPL0.7 #define LIMESDR_TX_AMPL 0.3 @@ -73,15 +68,6 @@ X3XX, UMTRX, LIMESDR, - NUM_USRP_TYPES, -}; - -struct uhd_dev_offset { - enum uhd_dev_type type; - size_t tx_sps; - size_t rx_sps; - double offset; - const std::string desc; }; /* @@ -109,76 +95,44 @@ * Notes: * USRP1 with timestamps is not supported by UHD. */ -static struct uhd_dev_offset uhd_offsets[] = { - { USRP1, 1, 1, 0.0, "USRP1 not supported" }, - { USRP1, 4, 1, 0.0, "USRP1 not supported"}, - { USRP2, 1, 1, 1.2184e-4, "N2XX 1 SPS" }, - { USRP2, 4, 1, 7.6547e-5, "N2XX 4/1 SPS" }, - { B100, 1, 1, 1.2104e-4, "B100 1 SPS" }, - { B100, 4, 1, 7.9307e-5, "B100 4 SPS" }, - { B200, 1, 1, B2XX_TIMING_1SPS, "B200 1 SPS" }, - { B200, 4, 1, B2XX_TIMING_4SPS, "B200 4/1 Tx/Rx SPS" }, - { B210, 1, 1, B2XX_TIMING_1SPS, "B210 1 SPS" }, - { B210, 4, 1, B2XX_TIMING_4SPS, "B210 4/1 Tx/Rx SPS" }, - { B2XX_MCBTS, 4, 4, B2XX_TIMING_MCBTS, "B200/B210 4 SPS Multi-ARFCN" }, - { E1XX, 1, 1, 9.5192e-5, "E1XX 1 SPS" }, - { E1XX, 4, 1, 6.5571e-5, "E1XX 4/1 Tx/Rx SPS" }, - { E3XX, 1, 1, 1.84616e-4, "E3XX 1 SPS" }, - { E3XX, 4, 1, 1.29231e-4, "E3XX 4/1 Tx/Rx SPS" }, - { X3XX, 1, 1, 1.5360e-4, "X3XX 1 SPS"}, - { X3XX, 4, 1, 1.1264e-4, "X3XX 4/1 Tx/Rx SPS"}, - { UMTRX, 1, 1, 9.9692e-5, "UmTRX 1 SPS" }, - { UMTRX, 4, 1, 7.3846e-5, "UmTRX 4/1 Tx/Rx SPS" }, - { USRP2, 4, 4, 4.6080e-5, "N2XX 4 SPS" }, - { B200, 4, 4, B2XX_TIMING_4_4SPS, "B200 4 SPS" }, - { B210, 4, 4, B2XX_TIMING_4_4SPS, "B210 4 SPS" }, - { X3XX, 4, 4, 5.6567e-5, "X3XX 4 SPS"}, - { UMTRX, 4, 4, 5.1503e-5, "UmTRX 4 SPS" }, - { LIMESDR, 4, 4, 16.5/GSMRATE, "STREAM/LimeSDR (4 SPS TX/RX)" }, + +/* Device Type, Tx-SPS, Rx-SPS */ +typedef std::tuple dev_key; + +/* Device parameter descriptor */ +struct dev_desc { + unsigned channels; + double mcr; + double rate; + double offset; + std::string str; }; -#define NUM_UHD_OFFSETS (sizeof(uhd_offsets)/sizeof(uhd_offsets[0])) -/* - * Select sample rate based on device type and requested samples-per-symbol. - * The base rate is either GSM symbol rate, 270.833 kHz, or the minimum - * usable channel spacing of 400 kHz. - */ -static double select_rate(uhd_dev_type type, int sps, - RadioDevice::InterfaceType iface) -{ - if ((sps != 4) && (sps != 1)) - return -.99; - - if (iface == RadioDevice::MULTI_ARFCN) { - switch (type) { - case B2XX_MCBTS: - return 4 * MCBTS_SPACING; - default: - LOG(ALERT) << "Invalid device combination"; - return -.99; - } - } - - switch (type) { - case USRP2: - case X3XX: - return USRP2_BASE_RT * sps; - case B100: - return B100_BASE_RT * sps; - case B200: - case B210: - case E1XX: - case E3XX: - case UMTRX: - case LIMESDR: - return GSMRATE * sps; - default: - break; - } - - LOG(ALERT) << "Unknown device type " << type; - return -.99; -} +static const std::map dev_param_map { + { std::make_tuple(USRP2, 1, 1), { 1, 0.0, 390625, 1.2184e-4, "N2XX 1 SPS" } }, + {
osmo-trx[master]: uhd: Use map container for for device parameter access
Patch Set 3: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/2871 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: I8660f75a2b2a13488b913c07637bdd0f5f0f4cf9 Gerrit-PatchSet: 3 Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Owner: Tom TsouGerrit-Reviewer: Harald Welte Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Tom Tsou Gerrit-HasComments: No
osmo-trx[master]: uhd: Use map container for for device parameter access
Patch Set 2: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/2871 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: I8660f75a2b2a13488b913c07637bdd0f5f0f4cf9 Gerrit-PatchSet: 2 Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Owner: Tom TsouGerrit-Reviewer: Harald Welte Gerrit-Reviewer: Jenkins Builder Gerrit-HasComments: No
[PATCH] osmo-trx[master]: uhd: Use map container for for device parameter access
Hello Harald Welte, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/2871 to look at the new patch set (#2). uhd: Use map container for for device parameter access OsmoTRX is written in C++ so we might as well use built-in container types when applicable. Map access allows removal of significant amounts of special device handling code. Aggregate device rates and timing offsets into a single table with access keyed by device/tx-sps/rx-sps tuples. Change-Id: I8660f75a2b2a13488b913c07637bdd0f5f0f4cf9 Signed-off-by: Tom Tsou--- M Transceiver52M/UHDDevice.cpp 1 file changed, 83 insertions(+), 273 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/71/2871/2 diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp index ce6d1be..c58f244 100644 --- a/Transceiver52M/UHDDevice.cpp +++ b/Transceiver52M/UHDDevice.cpp @@ -21,6 +21,7 @@ * See the COPYING file in the main directory for details. */ +#include #include "radioDevice.h" #include "Threads.h" #include "Logger.h" @@ -37,12 +38,6 @@ #include #endif -#define B2XX_CLK_RT 26e6 -#define B2XX_MCBTS_CLK_RT 51.2e6 -#define E1XX_CLK_RT 52e6 -#define LIMESDR_CLK_RT (GSMRATE*32) -#define B100_BASE_RT 40 -#define USRP2_BASE_RT390625 #define USRP_TX_AMPL 0.3 #define UMTRX_TX_AMPL0.7 #define LIMESDR_TX_AMPL 0.3 @@ -73,15 +68,6 @@ X3XX, UMTRX, LIMESDR, - NUM_USRP_TYPES, -}; - -struct uhd_dev_offset { - enum uhd_dev_type type; - size_t tx_sps; - size_t rx_sps; - double offset; - const std::string desc; }; /* @@ -109,76 +95,44 @@ * Notes: * USRP1 with timestamps is not supported by UHD. */ -static struct uhd_dev_offset uhd_offsets[] = { - { USRP1, 1, 1, 0.0, "USRP1 not supported" }, - { USRP1, 4, 1, 0.0, "USRP1 not supported"}, - { USRP2, 1, 1, 1.2184e-4, "N2XX 1 SPS" }, - { USRP2, 4, 1, 7.6547e-5, "N2XX 4/1 SPS" }, - { B100, 1, 1, 1.2104e-4, "B100 1 SPS" }, - { B100, 4, 1, 7.9307e-5, "B100 4 SPS" }, - { B200, 1, 1, B2XX_TIMING_1SPS, "B200 1 SPS" }, - { B200, 4, 1, B2XX_TIMING_4SPS, "B200 4/1 Tx/Rx SPS" }, - { B210, 1, 1, B2XX_TIMING_1SPS, "B210 1 SPS" }, - { B210, 4, 1, B2XX_TIMING_4SPS, "B210 4/1 Tx/Rx SPS" }, - { B2XX_MCBTS, 4, 4, B2XX_TIMING_MCBTS, "B200/B210 4 SPS Multi-ARFCN" }, - { E1XX, 1, 1, 9.5192e-5, "E1XX 1 SPS" }, - { E1XX, 4, 1, 6.5571e-5, "E1XX 4/1 Tx/Rx SPS" }, - { E3XX, 1, 1, 1.84616e-4, "E3XX 1 SPS" }, - { E3XX, 4, 1, 1.29231e-4, "E3XX 4/1 Tx/Rx SPS" }, - { X3XX, 1, 1, 1.5360e-4, "X3XX 1 SPS"}, - { X3XX, 4, 1, 1.1264e-4, "X3XX 4/1 Tx/Rx SPS"}, - { UMTRX, 1, 1, 9.9692e-5, "UmTRX 1 SPS" }, - { UMTRX, 4, 1, 7.3846e-5, "UmTRX 4/1 Tx/Rx SPS" }, - { USRP2, 4, 4, 4.6080e-5, "N2XX 4 SPS" }, - { B200, 4, 4, B2XX_TIMING_4_4SPS, "B200 4 SPS" }, - { B210, 4, 4, B2XX_TIMING_4_4SPS, "B210 4 SPS" }, - { X3XX, 4, 4, 5.6567e-5, "X3XX 4 SPS"}, - { UMTRX, 4, 4, 5.1503e-5, "UmTRX 4 SPS" }, - { LIMESDR, 4, 4, 16.5/GSMRATE, "STREAM/LimeSDR (4 SPS TX/RX)" }, + +/* Device Type, Tx-SPS, Rx-SPS */ +typedef std::tuple dev_key; + +/* Device parameter descriptor */ +struct dev_desc { + unsigned channels; + double mcr; + double rate; + double offset; + std::string str; }; -#define NUM_UHD_OFFSETS (sizeof(uhd_offsets)/sizeof(uhd_offsets[0])) -/* - * Select sample rate based on device type and requested samples-per-symbol. - * The base rate is either GSM symbol rate, 270.833 kHz, or the minimum - * usable channel spacing of 400 kHz. - */ -static double select_rate(uhd_dev_type type, int sps, - RadioDevice::InterfaceType iface) -{ - if ((sps != 4) && (sps != 1)) - return -.99; - - if (iface == RadioDevice::MULTI_ARFCN) { - switch (type) { - case B2XX_MCBTS: - return 4 * MCBTS_SPACING; - default: - LOG(ALERT) << "Invalid device combination"; - return -.99; - } - } - - switch (type) { - case USRP2: - case X3XX: - return USRP2_BASE_RT * sps; - case B100: - return B100_BASE_RT * sps; - case B200: - case B210: - case E1XX: - case E3XX: - case UMTRX: - case LIMESDR: - return GSMRATE * sps; - default: - break; - } - - LOG(ALERT) << "Unknown device type " << type; - return -.99; -} +static const std::map dev_param_map { + { std::make_tuple(USRP2, 1, 1), { 1, 0.0, 390625, 1.2184e-4, "N2XX 1 SPS" } }, + { std::make_tuple(USRP2, 4, 1), { 1, 0.0, 390625,
osmo-trx[master]: uhd: Use map container for for device parameter access
Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/2871 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: I8660f75a2b2a13488b913c07637bdd0f5f0f4cf9 Gerrit-PatchSet: 1 Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Owner: Tom TsouGerrit-Reviewer: Harald Welte Gerrit-Reviewer: Jenkins Builder Gerrit-HasComments: No
[PATCH] osmo-trx[master]: uhd: Use map container for for device parameter access
Review at https://gerrit.osmocom.org/2871 uhd: Use map container for for device parameter access OsmoTRX is written in C++ so we might as well use built-in container types when applicable. Map access allows removal of significant amounts of special device handling code. Aggregate device rates and timing offsets into a single table with access keyed by device/tx-sps/rx-sps tuples. Change-Id: I8660f75a2b2a13488b913c07637bdd0f5f0f4cf9 Signed-off-by: Tom Tsou--- M Transceiver52M/UHDDevice.cpp 1 file changed, 83 insertions(+), 273 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/71/2871/1 diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp index ce6d1be..0436265 100644 --- a/Transceiver52M/UHDDevice.cpp +++ b/Transceiver52M/UHDDevice.cpp @@ -21,6 +21,7 @@ * See the COPYING file in the main directory for details. */ +#include #include "radioDevice.h" #include "Threads.h" #include "Logger.h" @@ -37,12 +38,6 @@ #include #endif -#define B2XX_CLK_RT 26e6 -#define B2XX_MCBTS_CLK_RT 51.2e6 -#define E1XX_CLK_RT 52e6 -#define LIMESDR_CLK_RT (GSMRATE*32) -#define B100_BASE_RT 40 -#define USRP2_BASE_RT390625 #define USRP_TX_AMPL 0.3 #define UMTRX_TX_AMPL0.7 #define LIMESDR_TX_AMPL 0.3 @@ -73,15 +68,6 @@ X3XX, UMTRX, LIMESDR, - NUM_USRP_TYPES, -}; - -struct uhd_dev_offset { - enum uhd_dev_type type; - size_t tx_sps; - size_t rx_sps; - double offset; - const std::string desc; }; /* @@ -109,76 +95,44 @@ * Notes: * USRP1 with timestamps is not supported by UHD. */ -static struct uhd_dev_offset uhd_offsets[] = { - { USRP1, 1, 1, 0.0, "USRP1 not supported" }, - { USRP1, 4, 1, 0.0, "USRP1 not supported"}, - { USRP2, 1, 1, 1.2184e-4, "N2XX 1 SPS" }, - { USRP2, 4, 1, 7.6547e-5, "N2XX 4/1 SPS" }, - { B100, 1, 1, 1.2104e-4, "B100 1 SPS" }, - { B100, 4, 1, 7.9307e-5, "B100 4 SPS" }, - { B200, 1, 1, B2XX_TIMING_1SPS, "B200 1 SPS" }, - { B200, 4, 1, B2XX_TIMING_4SPS, "B200 4/1 Tx/Rx SPS" }, - { B210, 1, 1, B2XX_TIMING_1SPS, "B210 1 SPS" }, - { B210, 4, 1, B2XX_TIMING_4SPS, "B210 4/1 Tx/Rx SPS" }, - { B2XX_MCBTS, 4, 4, B2XX_TIMING_MCBTS, "B200/B210 4 SPS Multi-ARFCN" }, - { E1XX, 1, 1, 9.5192e-5, "E1XX 1 SPS" }, - { E1XX, 4, 1, 6.5571e-5, "E1XX 4/1 Tx/Rx SPS" }, - { E3XX, 1, 1, 1.84616e-4, "E3XX 1 SPS" }, - { E3XX, 4, 1, 1.29231e-4, "E3XX 4/1 Tx/Rx SPS" }, - { X3XX, 1, 1, 1.5360e-4, "X3XX 1 SPS"}, - { X3XX, 4, 1, 1.1264e-4, "X3XX 4/1 Tx/Rx SPS"}, - { UMTRX, 1, 1, 9.9692e-5, "UmTRX 1 SPS" }, - { UMTRX, 4, 1, 7.3846e-5, "UmTRX 4/1 Tx/Rx SPS" }, - { USRP2, 4, 4, 4.6080e-5, "N2XX 4 SPS" }, - { B200, 4, 4, B2XX_TIMING_4_4SPS, "B200 4 SPS" }, - { B210, 4, 4, B2XX_TIMING_4_4SPS, "B210 4 SPS" }, - { X3XX, 4, 4, 5.6567e-5, "X3XX 4 SPS"}, - { UMTRX, 4, 4, 5.1503e-5, "UmTRX 4 SPS" }, - { LIMESDR, 4, 4, 16.5/GSMRATE, "STREAM/LimeSDR (4 SPS TX/RX)" }, + +/* Device Type, Tx-SPS, Rx-SPS */ +typedef std::tuple dev_key; + +/* Device parameter descriptor */ +struct dev_desc { + unsigned channels; + double mcr; + double rate; + double offset; + std::string str; }; -#define NUM_UHD_OFFSETS (sizeof(uhd_offsets)/sizeof(uhd_offsets[0])) -/* - * Select sample rate based on device type and requested samples-per-symbol. - * The base rate is either GSM symbol rate, 270.833 kHz, or the minimum - * usable channel spacing of 400 kHz. - */ -static double select_rate(uhd_dev_type type, int sps, - RadioDevice::InterfaceType iface) -{ - if ((sps != 4) && (sps != 1)) - return -.99; - - if (iface == RadioDevice::MULTI_ARFCN) { - switch (type) { - case B2XX_MCBTS: - return 4 * MCBTS_SPACING; - default: - LOG(ALERT) << "Invalid device combination"; - return -.99; - } - } - - switch (type) { - case USRP2: - case X3XX: - return USRP2_BASE_RT * sps; - case B100: - return B100_BASE_RT * sps; - case B200: - case B210: - case E1XX: - case E3XX: - case UMTRX: - case LIMESDR: - return GSMRATE * sps; - default: - break; - } - - LOG(ALERT) << "Unknown device type " << type; - return -.99; -} +static const std::map dev_param_map { + { std::make_tuple(USRP2, 1, 1), { 1, 0.0, 390625, 1.2184e-4, "N2XX 1 SPS" } }, + { std::make_tuple(USRP2, 4, 1), { 1, 0.0, 390625, 7.6547e-5, "N2XX 4/1 SPS" } }, + { std::make_tuple(USRP2, 4, 4), { 1, 0.0, 390625, 4.6080e-5, "N2XX 4 SPS"