lists.osmocom.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
July
June
May
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
List overview
Download
gerrit-log
May 2023
----- 2025 -----
July 2025
June 2025
May 2025
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
gerrit-log@lists.osmocom.org
1 participants
2583 discussions
Start a n
N
ew thread
[M] Change in osmo-trx[master]: ms: fix startup & shutdown of blade
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32944
) Change subject: ms: fix startup & shutdown of blade ...................................................................... ms: fix startup & shutdown of blade One of the mystery bugs was that the blade ms needed two starts after powercycling the bladerf due to transfer timeouts. This is now fixed. Change-Id: I1cd8790191790f4861a70bc55c8f4c9993fa10c8 --- M Transceiver52M/ms/bladerf_specific.h M Transceiver52M/ms/ms.cpp M Transceiver52M/ms/ms.h M Transceiver52M/ms/ms_upper.cpp M Transceiver52M/ms/ms_upper.h M Transceiver52M/ms/uhd_specific.h 6 files changed, 78 insertions(+), 26 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/44/32944/1 diff --git a/Transceiver52M/ms/bladerf_specific.h b/Transceiver52M/ms/bladerf_specific.h index 78c51ab..85a2ea0 100644 --- a/Transceiver52M/ms/bladerf_specific.h +++ b/Transceiver52M/ms/bladerf_specific.h @@ -293,10 +293,10 @@ setRxGain(rxgain, 0); setTxGain(txgain, 0); usleep(1000); - blade_check(bladerf_enable_module, dev, BLADERF_MODULE_RX, true); - usleep(1000); - blade_check(bladerf_enable_module, dev, BLADERF_MODULE_TX, true); - usleep(1000); + + bladerf_set_stream_timeout(dev, BLADERF_TX, 10); + bladerf_set_stream_timeout(dev, BLADERF_RX, 10); + blade_check(bladerf_init_stream, &rx_stream, dev, getrxcb(rxh), &buf_mgmt.rx_samples, BLADE_NUM_BUFFERS, BLADERF_FORMAT_SC16_Q11_META, BLADE_BUFFER_SIZE, NUM_TRANSFERS, (void *)this); @@ -308,15 +308,16 @@ buf_mgmt.bufptrqueue.spsc_push(&cur_buffer[i]); } - - usleep(1000); - - // bladerf_set_stream_timeout(dev, BLADERF_TX, 4); - // bladerf_set_stream_timeout(dev, BLADERF_RX, 4); - return 0; } + void actually_enable_streams() + { + blade_check(bladerf_enable_module, dev, BLADERF_MODULE_RX, true); + usleep(1000); + blade_check(bladerf_enable_module, dev, BLADERF_MODULE_TX, true); + } + bool tuneTx(double freq, size_t chan = 0) { msleep(15); @@ -418,8 +419,9 @@ auto get_rx_burst_handler_fn(bh_fn_t burst_handler) { auto fn = [this] { - int status; - status = bladerf_stream(rx_stream, BLADERF_RX_X1); + int status = 0; + if (!stop_me_flag) + status = bladerf_stream(rx_stream, BLADERF_RX_X1); if (status < 0) std::cerr << "rx stream error! " << bladerf_strerror(status) << std::endl; @@ -430,8 +432,9 @@ auto get_tx_burst_handler_fn(bh_fn_t burst_handler) { auto fn = [this] { - int status; - status = bladerf_stream(tx_stream, BLADERF_TX_X1); + int status = 0; + if (!stop_me_flag) + status = bladerf_stream(tx_stream, BLADERF_TX_X1); if (status < 0) std::cerr << "rx stream error! " << bladerf_strerror(status) << std::endl; @@ -442,9 +445,15 @@ void submit_burst_ts(blade_sample_type *buffer, int len, uint64_t ts) { - //get empty bufer from list tx_buf_q_type::elem_t rcd; + // exit by submitting a dummy buffer to assure the libbladerf stream mutex is happy (thread!) + if (!buffer) { + bladerf_submit_stream_buffer(tx_stream, (void *)BLADERF_STREAM_SHUTDOWN, 1000); + return; + } + + //get empty bufer from list while (!buf_mgmt.bufptrqueue.spsc_pop(&rcd)) buf_mgmt.bufptrqueue.spsc_prep_pop(); assert(rcd != nullptr); diff --git a/Transceiver52M/ms/ms.cpp b/Transceiver52M/ms/ms.cpp index 1dc2587..f338225 100644 --- a/Transceiver52M/ms/ms.cpp +++ b/Transceiver52M/ms/ms.cpp @@ -276,6 +276,8 @@ void ms_trx::start() { + if (stop_me_flag) + return; auto fn = get_rx_burst_handler_fn(rx_bh()); rx_task = std::thread(fn); set_name_aff_sched(rx_task.native_handle(), sched_params::thread_names::RXRUN); @@ -285,6 +287,7 @@ tx_task = std::thread(fn2); set_name_aff_sched(tx_task.native_handle(), sched_params::thread_names::TXRUN); + actually_enable_streams(); } void ms_trx::set_upper_ready(bool is_ready) @@ -294,11 +297,14 @@ void ms_trx::stop_threads() { - std::cerr << "killing threads...\r\n" << std::endl; + std::cerr << "killing threads..." << std::endl; stop_me_flag = true; close_device(); + std::cerr << "dev closed..." << std::endl; rx_task.join(); + std::cerr << "L rx dead..." << std::endl; tx_task.join(); + std::cerr << "L tx dead..." << std::endl; } void ms_trx::submit_burst(blade_sample_type *buffer, int len, GSM::Time target) diff --git a/Transceiver52M/ms/ms.h b/Transceiver52M/ms/ms.h index 6f8d54f..dbf2e9a 100644 --- a/Transceiver52M/ms/ms.h +++ b/Transceiver52M/ms/ms.h @@ -331,16 +331,14 @@ CPU_ZERO(&cpuset); CPU_SET(cpunum, &cpuset); - auto rv = pthread_setaffinity_np(h, sizeof(cpuset), &cpuset); - if (rv < 0) { + if (pthread_setaffinity_np(h, sizeof(cpuset), &cpuset) < 0) { std::cerr << name << " affinity: errreur! " << std::strerror(errno); return exit(0); } sched_param sch_params; sch_params.sched_priority = prio; - rv = pthread_setschedparam(h, schedtype, &sch_params); - if (rv < 0) { + if (pthread_setschedparam(h, schedtype, &sch_params) < 0) { std::cerr << name << " sched: errreur! " << std::strerror(errno); return exit(0); } diff --git a/Transceiver52M/ms/ms_upper.cpp b/Transceiver52M/ms/ms_upper.cpp index 3cb27e3..5b213f7 100644 --- a/Transceiver52M/ms/ms_upper.cpp +++ b/Transceiver52M/ms/ms_upper.cpp @@ -94,6 +94,17 @@ std::atomic<bool> g_exit_flag; +void upper_trx::stop_upper_threads() +{ + g_exit_flag = true; + + if (thr_control.joinable()) + thr_control.join(); + if (thr_rx.joinable()) + thr_rx.join(); + if (thr_tx.joinable()) + thr_tx.join(); +} void upper_trx::start_threads() { thr_control = std::thread([this] { @@ -101,6 +112,7 @@ while (!g_exit_flag) { driveControl(); } + std::cerr << "exit control!" << std::endl; }); msleep(1); thr_tx = std::thread([this] { @@ -108,6 +120,7 @@ while (!g_exit_flag) { driveTx(); } + std::cerr << "exit tx U!" << std::endl; }); // atomic ensures data is not written to q until loop reads @@ -115,7 +128,8 @@ set_name_aff_sched(sched_params::thread_names::U_RX); while (!g_exit_flag) { - // set_upper_ready(true); + // set_upper_ready(true) needs to happen during cmd handling: + // the main loop is driven by rx, so unless rx is on AND transceiver is on we get stuck.. driveReceiveFIFO(); trxcon::osmo_select_main(1); @@ -125,6 +139,9 @@ trxcon_phyif_handle_rsp(trxcon::g_trxcon, &r); } } + set_upper_ready(false); + std::cerr << "exit rx U!" << std::endl; + mOn = false; #ifdef LSANDEBUG std::thread([this] { @@ -267,8 +284,7 @@ // ensure our tx cb is tickled and can exit if (g_exit_flag) { - blade_sample_type dummy[10] = {}; - submit_burst_ts(dummy, 10, 1); + submit_burst_ts(0, 1337, 1); return; } @@ -360,10 +376,9 @@ set_ta(0); break; case trxcon::TRXCON_PHYIF_CMDT_POWERON: - if (!mOn) { - set_upper_ready(true); mOn = true; + set_upper_ready(true); } break; case trxcon::TRXCON_PHYIF_CMDT_POWEROFF: @@ -444,7 +459,7 @@ void sighandler(int sigset) { // we might get a sigpipe in case the l1ctl ud socket disconnects because mobile quits - if (sigset == SIGPIPE) { + if (sigset == SIGPIPE || sigset == SIGINT) { g_exit_flag = true; // we know the flag is atomic and it prevents the trxcon cb handlers from writing @@ -453,6 +468,7 @@ trxcon::internal_q_tx_buf b = {}; trxcon::txq.spsc_push(&b); trxcon::cmdq_to_phy.spsc_push(&cmd); + msleep(200); return; } @@ -462,6 +478,7 @@ { auto tall_trxcon_ctx = talloc_init("trxcon context"); signal(SIGPIPE, sighandler); + signal(SIGINT, sighandler); trxcon::msgb_talloc_ctx_init(tall_trxcon_ctx, 0); trxc_log_init(tall_trxcon_ctx); @@ -492,8 +509,11 @@ return -1; } + // blocking, will return when global exit is requested trx->start_threads(); + trx->stop_threads(); + trx->stop_upper_threads(); return status; } diff --git a/Transceiver52M/ms/ms_upper.h b/Transceiver52M/ms/ms_upper.h index 49516e6..fe20f6d 100644 --- a/Transceiver52M/ms/ms_upper.h +++ b/Transceiver52M/ms/ms_upper.h @@ -43,6 +43,7 @@ public: void start_threads(); void start_lower_ms(); + void stop_upper_threads(); upper_trx(){}; }; diff --git a/Transceiver52M/ms/uhd_specific.h b/Transceiver52M/ms/uhd_specific.h index 726bb95..07fc449 100644 --- a/Transceiver52M/ms/uhd_specific.h +++ b/Transceiver52M/ms/uhd_specific.h @@ -185,6 +185,11 @@ return 0; } + void actually_enable_streams() + { + // nop: stream cmd in handler + } + void *rx_cb(bh_fn_t burst_handler) { void *ret = nullptr; -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32944
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: I1cd8790191790f4861a70bc55c8f4c9993fa10c8 Gerrit-Change-Number: 32944 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
[M] Change in osmo-trx[master]: ms: use single thread pool
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32946
) Change subject: ms: use single thread pool ...................................................................... ms: use single thread pool ...so we don't spawn threads all the time. Used for gain avg/setting. Change-Id: Id675550f55e8ccbbbe6b0d91fbffd01b6ede15f7 --- M Transceiver52M/ms/ms.h M Transceiver52M/ms/ms_rx_lower.cpp A Transceiver52M/ms/threadpool.h 3 files changed, 133 insertions(+), 18 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/46/32946/1 diff --git a/Transceiver52M/ms/ms.h b/Transceiver52M/ms/ms.h index 7381397..d92f4b7 100644 --- a/Transceiver52M/ms/ms.h +++ b/Transceiver52M/ms/ms.h @@ -41,6 +41,7 @@ #include "Complex.h" #include "GSMCommon.h" #include "itrq.h" +#include "threadpool.h" const unsigned int ONE_TS_BURST_LEN = (3 + 58 + 26 + 58 + 3 + 8.25) * 4 /*sps*/; const unsigned int NUM_RXQ_FRAMES = 1; // rx thread <-> upper rx queue @@ -266,6 +267,7 @@ time_keeper timekeeper; int hw_cpus; sched_params::target hw_target; + single_thread_pool worker_thread; void start(); std::atomic<bool> upper_is_ready; @@ -291,6 +293,7 @@ hw_target(hw_cpus > 4 ? sched_params::target::ODROID : sched_params::target::PI4) { std::cerr << "scheduling for: " << (hw_cpus > 4 ? "odroid" : "pi4") << std::endl; + set_name_aff_sched(worker_thread.get_handle(), sched_params::thread_names::SCH_SEARCH); } virtual ~ms_trx() diff --git a/Transceiver52M/ms/ms_rx_lower.cpp b/Transceiver52M/ms/ms_rx_lower.cpp index e8d8e0e..dc0d56d 100644 --- a/Transceiver52M/ms/ms_rx_lower.cpp +++ b/Transceiver52M/ms/ms_rx_lower.cpp @@ -30,6 +30,8 @@ #include "ms.h" #include "grgsm_vitac/grgsm_vitac.h" +#include "threadpool.h" + extern "C" { #include "sch.h" } @@ -126,8 +128,11 @@ gainoffset = runmean < (rxFullScale / 2 ? 2 : 1); float newgain = runmean < rx_max_cutoff ? rxgain + gainoffset : rxgain - gainoffset; // FIXME: gian cutoff - if (newgain != rxgain && newgain <= 60) - std::thread([this, newgain] { setRxGain(newgain); }).detach(); + if (newgain != rxgain && newgain <= 60) { + auto gain_fun = [this, newgain] { setRxGain(newgain); }; + worker_thread.add_task(gain_fun); + } + runmean = 0; } gain_check = (gain_check + 1) % avgburst_num; @@ -217,26 +222,36 @@ return false; } +/* +accumulates a full big buffer consisting of 8*12 timeslots, then: +either +1) adjusts gain if necessary and starts over +2) searches and finds SCH and is done +*/ SCH_STATE ms_trx::search_for_sch(dev_buf_t *rcd) { static unsigned int sch_pos = 0; + auto to_copy = SCH_LEN_SPS - sch_pos; + if (sch_thread_done) return SCH_STATE::FOUND; if (rcv_done) return SCH_STATE::SEARCHING; - auto to_copy = SCH_LEN_SPS - sch_pos; - - if (SCH_LEN_SPS == to_copy) // first time + if (sch_pos == 0) // keep first ts for time delta calc first_sch_buf_rcv_ts = rcd->get_first_ts(); - if (!to_copy) { + if (to_copy) { + auto spsmax = rcd->actual_samples_per_buffer(); + if (to_copy > (unsigned int)spsmax) + sch_pos += rcd->readall(first_sch_buf + sch_pos); + else + sch_pos += rcd->read_n(first_sch_buf + sch_pos, 0, to_copy); + } else { // (!to_copy) sch_pos = 0; rcv_done = true; - std::thread([this] { - set_name_aff_sched(sched_params::thread_names::SCH_SEARCH); - + auto sch_search_fun = [this] { auto ptr = reinterpret_cast<const int16_t *>(first_sch_buf); const auto target_val = rxFullScale / 8; float sum = 0; @@ -255,16 +270,9 @@ if (!sch_thread_done) rcv_done = false; // retry! - return (bool)sch_thread_done; - }).detach(); + }; + worker_thread.add_task(sch_search_fun); } - - auto spsmax = rcd->actual_samples_per_buffer(); - if (to_copy > (unsigned int)spsmax) - sch_pos += rcd->readall(first_sch_buf + sch_pos); - else - sch_pos += rcd->read_n(first_sch_buf + sch_pos, 0, to_copy); - return SCH_STATE::SEARCHING; } diff --git a/Transceiver52M/ms/threadpool.h b/Transceiver52M/ms/threadpool.h new file mode 100644 index 0000000..a5dec97 --- /dev/null +++ b/Transceiver52M/ms/threadpool.h @@ -0,0 +1,92 @@ +#pragma once +/* + * (C) 2023 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved + * + * Author: Eric Wild <ewild(a)sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <
http://www.gnu.org/licenses/
>. + * + */ + +#include <functional> +#include <thread> +#include <atomic> +#include <vector> +#include <future> +#include <mutex> +#include <queue> + +struct single_thread_pool { + std::mutex m; + std::condition_variable cv; + std::atomic<bool> stop_flag; + std::atomic<bool> is_ready; + std::deque<std::function<void()>> wq; + std::thread worker_thread; + + template <class F> + void add_task(F &&f) + { + std::unique_lock<std::mutex> l(m); + wq.emplace_back(std::forward<F>(f)); + cv.notify_one(); + return; + } + + single_thread_pool() : worker_thread(std::thread([this] { thread_loop(); })) + { + } + ~single_thread_pool() + { + stop(); + } + + std::thread::native_handle_type get_handle() + { + return worker_thread.native_handle(); + } + + private: + void stop() + { + { + std::unique_lock<std::mutex> l(m); + wq.clear(); + stop_flag = true; + cv.notify_one(); + } + worker_thread.join(); + } + + void thread_loop() + { + while (true) { + is_ready = true; + std::function<void()> f; + { + std::unique_lock<std::mutex> l(m); + if (wq.empty()) { + cv.wait(l, [&] { return !wq.empty() || stop_flag; }); + } + if (stop_flag) + return; + is_ready = false; + f = std::move(wq.front()); + wq.pop_front(); + } + f(); + } + } +}; \ No newline at end of file -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32946
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: Id675550f55e8ccbbbe6b0d91fbffd01b6ede15f7 Gerrit-Change-Number: 32946 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
[S] Change in osmo-trx[master]: ms: block burst q to upper layer
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32945
) Change subject: ms: block burst q to upper layer ...................................................................... ms: block burst q to upper layer Change-Id: Id0aad606a296b2885617013ce6637204357b13d7 --- M Transceiver52M/ms/ms.h 1 file changed, 10 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/45/32945/1 diff --git a/Transceiver52M/ms/ms.h b/Transceiver52M/ms/ms.h index dbf2e9a..7381397 100644 --- a/Transceiver52M/ms/ms.h +++ b/Transceiver52M/ms/ms.h @@ -116,7 +116,7 @@ }; }; -using rx_queue_t = spsc_cond<8 * NUM_RXQ_FRAMES, one_burst, true, true>; +using rx_queue_t = spsc_cond<8 * NUM_RXQ_FRAMES, one_burst, true, false>; enum class SCH_STATE { SEARCHING, FOUND }; -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32945
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: Id0aad606a296b2885617013ce6637204357b13d7 Gerrit-Change-Number: 32945 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
[S] Change in osmo-trx[master]: ms : rename var
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32947
) Change subject: ms : rename var ...................................................................... ms : rename var Change-Id: I44e5d1770b248f107abce5683d5f7641655da764 --- M Transceiver52M/ms/bladerf_specific.h M Transceiver52M/ms/ms.cpp M Transceiver52M/ms/uhd_specific.h 3 files changed, 19 insertions(+), 10 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/47/32947/1 diff --git a/Transceiver52M/ms/bladerf_specific.h b/Transceiver52M/ms/bladerf_specific.h index 85a2ea0..ba5c7f1 100644 --- a/Transceiver52M/ms/bladerf_specific.h +++ b/Transceiver52M/ms/bladerf_specific.h @@ -197,7 +197,7 @@ const int rxtxdelay; float rxgain, txgain; - static std::atomic<bool> stop_me_flag; + static std::atomic<bool> stop_lower_threads_flag; struct ms_trx_config { int tx_freq; @@ -384,7 +384,7 @@ static int to_skip = 0; dev_buf_t *rcd = (dev_buf_t *)samples; - if (stop_me_flag) + if (stop_lower_threads_flag) return BLADERF_STREAM_SHUTDOWN; if (to_skip < 120) // prevents weird overflows on startup @@ -409,7 +409,7 @@ if (samples) // put buffer address back into queue, ready to be reused trx->buf_mgmt.bufptrqueue.spsc_push(&ptr); - if (stop_me_flag) + if (stop_lower_threads_flag) return BLADERF_STREAM_SHUTDOWN; return BLADERF_STREAM_NO_DATA; @@ -420,7 +420,7 @@ { auto fn = [this] { int status = 0; - if (!stop_me_flag) + if (!stop_lower_threads_flag) status = bladerf_stream(rx_stream, BLADERF_RX_X1); if (status < 0) std::cerr << "rx stream error! " << bladerf_strerror(status) << std::endl; @@ -433,7 +433,7 @@ { auto fn = [this] { int status = 0; - if (!stop_me_flag) + if (!stop_lower_threads_flag) status = bladerf_stream(tx_stream, BLADERF_TX_X1); if (status < 0) std::cerr << "rx stream error! " << bladerf_strerror(status) << std::endl; diff --git a/Transceiver52M/ms/ms.cpp b/Transceiver52M/ms/ms.cpp index f338225..ff0ce59 100644 --- a/Transceiver52M/ms/ms.cpp +++ b/Transceiver52M/ms/ms.cpp @@ -50,7 +50,7 @@ #endif template <> -std::atomic<bool> ms_trx::base::stop_me_flag(false); +std::atomic<bool> ms_trx::base::stop_lower_threads_flag(false); void tx_test(ms_trx *t, ts_hitter_q_t *q, unsigned int *tsc) { @@ -276,7 +276,7 @@ void ms_trx::start() { - if (stop_me_flag) + if (stop_lower_threads_flag) return; auto fn = get_rx_burst_handler_fn(rx_bh()); rx_task = std::thread(fn); @@ -298,7 +298,7 @@ void ms_trx::stop_threads() { std::cerr << "killing threads..." << std::endl; - stop_me_flag = true; + stop_lower_threads_flag = true; close_device(); std::cerr << "dev closed..." << std::endl; rx_task.join(); diff --git a/Transceiver52M/ms/uhd_specific.h b/Transceiver52M/ms/uhd_specific.h index 07fc449..c8361e9 100644 --- a/Transceiver52M/ms/uhd_specific.h +++ b/Transceiver52M/ms/uhd_specific.h @@ -77,7 +77,7 @@ const unsigned int rxFullScale, txFullScale; const int rxtxdelay; float rxgain, txgain; - static std::atomic<bool> stop_me_flag; + static std::atomic<bool> stop_lower_threads_flag; virtual ~uhd_hw() { @@ -232,7 +232,7 @@ stream_cmd.time_spec = uhd::time_spec_t(); rx_stream->issue_stream_cmd(stream_cmd); - while (!stop_me_flag) { + while (!stop_lower_threads_flag) { rx_cb(burst_handler); } }; -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32947
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: I44e5d1770b248f107abce5683d5f7641655da764 Gerrit-Change-Number: 32947 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
[S] Change in osmo-trx[master]: ms: cache frequency
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32949
) Change subject: ms: cache frequency ...................................................................... ms: cache frequency Don't waste time setting the same frequency again. Change-Id: Ide9f45130955e1cc66610a50d6fc1cd79f30aca9 --- M Transceiver52M/ms/bladerf_specific.h M Transceiver52M/ms/uhd_specific.h 2 files changed, 29 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/49/32949/1 diff --git a/Transceiver52M/ms/bladerf_specific.h b/Transceiver52M/ms/bladerf_specific.h index ba5c7f1..3dc4777 100644 --- a/Transceiver52M/ms/bladerf_specific.h +++ b/Transceiver52M/ms/bladerf_specific.h @@ -198,6 +198,7 @@ float rxgain, txgain; static std::atomic<bool> stop_lower_threads_flag; + double rxfreq_cache, txfreq_cache; struct ms_trx_config { int tx_freq; @@ -222,7 +223,9 @@ { close_device(); } - blade_hw() : rxFullScale(2047), txFullScale(2047), rxtxdelay(-60), rxgain(30), txgain(30) + blade_hw() + : rxFullScale(2047), txFullScale(2047), rxtxdelay(-60), rxgain(30), txgain(30), rxfreq_cache(0), + txfreq_cache(0) { } @@ -320,15 +323,21 @@ bool tuneTx(double freq, size_t chan = 0) { + if (txfreq_cache == freq) + return true; msleep(15); blade_check(bladerf_set_frequency, dev, BLADERF_CHANNEL_TX(0), (bladerf_frequency)freq); + txfreq_cache = freq; msleep(15); return true; }; bool tuneRx(double freq, size_t chan = 0) { + if (rxfreq_cache == freq) + return true; msleep(15); blade_check(bladerf_set_frequency, dev, BLADERF_CHANNEL_RX(0), (bladerf_frequency)freq); + rxfreq_cache = freq; msleep(15); return true; }; diff --git a/Transceiver52M/ms/uhd_specific.h b/Transceiver52M/ms/uhd_specific.h index c8361e9..5723fd4 100644 --- a/Transceiver52M/ms/uhd_specific.h +++ b/Transceiver52M/ms/uhd_specific.h @@ -78,12 +78,13 @@ const int rxtxdelay; float rxgain, txgain; static std::atomic<bool> stop_lower_threads_flag; + double rxfreq_cache, txfreq_cache; virtual ~uhd_hw() { delete[] one_pkt_buf; } - uhd_hw() : rxFullScale(32767), txFullScale(32767 * 0.3), rxtxdelay(-67) + uhd_hw() : rxFullScale(32767), txFullScale(32767 * 0.3), rxtxdelay(-67), rxfreq_cache(0), txfreq_cache(0) { } @@ -93,15 +94,21 @@ bool tuneTx(double freq, size_t chan = 0) { + if (txfreq_cache == freq) + return true; msleep(25); dev->set_tx_freq(freq, chan); + txfreq_cache = freq; msleep(25); return true; }; bool tuneRx(double freq, size_t chan = 0) { + if (rxfreq_cache == freq) + return true; msleep(25); dev->set_rx_freq(freq, chan); + rxfreq_cache = freq; msleep(25); return true; }; -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32949
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: Ide9f45130955e1cc66610a50d6fc1cd79f30aca9 Gerrit-Change-Number: 32949 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
[S] Change in osmo-trx[master]: ms : rename var
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32948
) Change subject: ms : rename var ...................................................................... ms : rename var Change-Id: Ia90a9f73fdb1f96fa5bd7f27b3c191ce0ba6c65d --- M Transceiver52M/ms/ms.cpp M Transceiver52M/ms/ms.h 2 files changed, 17 insertions(+), 8 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/48/32948/1 diff --git a/Transceiver52M/ms/ms.cpp b/Transceiver52M/ms/ms.cpp index ff0ce59..ca3339b 100644 --- a/Transceiver52M/ms/ms.cpp +++ b/Transceiver52M/ms/ms.cpp @@ -279,13 +279,13 @@ if (stop_lower_threads_flag) return; auto fn = get_rx_burst_handler_fn(rx_bh()); - rx_task = std::thread(fn); - set_name_aff_sched(rx_task.native_handle(), sched_params::thread_names::RXRUN); + lower_rx_task = std::thread(fn); + set_name_aff_sched(lower_rx_task.native_handle(), sched_params::thread_names::RXRUN); usleep(1000); auto fn2 = get_tx_burst_handler_fn(tx_bh()); - tx_task = std::thread(fn2); - set_name_aff_sched(tx_task.native_handle(), sched_params::thread_names::TXRUN); + lower_tx_task = std::thread(fn2); + set_name_aff_sched(lower_tx_task.native_handle(), sched_params::thread_names::TXRUN); actually_enable_streams(); } @@ -301,9 +301,9 @@ stop_lower_threads_flag = true; close_device(); std::cerr << "dev closed..." << std::endl; - rx_task.join(); + lower_rx_task.join(); std::cerr << "L rx dead..." << std::endl; - tx_task.join(); + lower_tx_task.join(); std::cerr << "L tx dead..." << std::endl; } diff --git a/Transceiver52M/ms/ms.h b/Transceiver52M/ms/ms.h index d92f4b7..3b97d1b 100644 --- a/Transceiver52M/ms/ms.h +++ b/Transceiver52M/ms/ms.h @@ -245,8 +245,8 @@ int timing_advance; bool do_auto_gain; - std::thread rx_task; - std::thread tx_task; + std::thread lower_rx_task; + std::thread lower_tx_task; std::thread *calcrval_task; // provides bursts to upper rx thread -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32948
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: Ia90a9f73fdb1f96fa5bd7f27b3c191ce0ba6c65d Gerrit-Change-Number: 32948 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
[S] Change in osmo-trx[master]: ms: pretty tx buf class
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32950
) Change subject: ms: pretty tx buf class ...................................................................... ms: pretty tx buf class Change-Id: I96c5dd79426a52e7fff2df27bdaa3fae0c69491a --- M Transceiver52M/ms/ms_upper.cpp 1 file changed, 17 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/50/32950/1 diff --git a/Transceiver52M/ms/ms_upper.cpp b/Transceiver52M/ms/ms_upper.cpp index 5b213f7..cae1893 100644 --- a/Transceiver52M/ms/ms_upper.cpp +++ b/Transceiver52M/ms/ms_upper.cpp @@ -72,6 +72,13 @@ struct internal_q_tx_buf { trxcon_phyif_burst_req r; uint8_t buf[148]; + internal_q_tx_buf() = default; + internal_q_tx_buf(const internal_q_tx_buf &) = delete; + internal_q_tx_buf &operator=(const internal_q_tx_buf &) = default; + internal_q_tx_buf(const struct trxcon::trxcon_phyif_burst_req *br) : r(*br) + { + memcpy(buf, (void *)br->burst, br->burst_len); + } }; using tx_queue_t = spsc_cond<8 * 1, internal_q_tx_buf, true, false>; using cmd_queue_t = spsc_cond<8 * 1, trxcon_phyif_cmd, true, false>; @@ -415,10 +422,7 @@ return 0; OSMO_ASSERT(br->burst != 0); - trxcon::internal_q_tx_buf b; - b.r = *br; - memcpy(b.buf, (void *)br->burst, br->burst_len); - + trxcon::internal_q_tx_buf b(br); if (!g_exit_flag) trxcon::txq.spsc_push(&b); return 0; -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32950
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: I96c5dd79426a52e7fff2df27bdaa3fae0c69491a Gerrit-Change-Number: 32950 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
[L] Change in osmo-trx[master]: ms: remove syncthing tool
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32952
) Change subject: ms: remove syncthing tool ...................................................................... ms: remove syncthing tool Only used for testing during the first stages of development. Change-Id: Ie97069a109324b6e96c66a4b24d03f9745b6a52e --- M Transceiver52M/Makefile.am M Transceiver52M/ms/ms.cpp M Transceiver52M/ms/ms.h D Transceiver52M/ms/ms_rx_burst.h D Transceiver52M/ms/ms_rx_burst_test.cpp M Transceiver52M/ms/ms_rx_lower.cpp 6 files changed, 15 insertions(+), 467 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/52/32952/1 diff --git a/Transceiver52M/Makefile.am b/Transceiver52M/Makefile.am index d657536..0cfe0e6 100644 --- a/Transceiver52M/Makefile.am +++ b/Transceiver52M/Makefile.am @@ -100,7 +100,6 @@ ms/ms.h \ ms/bladerf_specific.h \ ms/uhd_specific.h \ - ms/ms_rx_burst.h \ ms/ms_upper.h \ ms/ms_trxcon_if.h \ ms/itrq.h \ @@ -131,15 +130,6 @@ $(UHD_LIBS) \ $(TRXCON_LDADD) osmo_trx_ms_uhd_CPPFLAGS = $(AM_CPPFLAGS) $(UHD_CFLAGS) -DBUILDUHD - -bin_PROGRAMS += osmo-trx-syncthing-uhd -osmo_trx_syncthing_uhd_SOURCES = $(MS_LOWER_SRC) ms/ms_rx_burst_test.cpp -osmo_trx_syncthing_uhd_LDADD = \ - $(builddir)/device/uhd/libdevice.la \ - $(COMMON_LDADD) \ - $(UHD_LIBS) \ - $(TRXCON_LDADD) -osmo_trx_syncthing_uhd_CPPFLAGS = $(AM_CPPFLAGS) $(UHD_CFLAGS) -DSYNCTHINGONLY -DBUILDUHD endif endif @@ -181,15 +171,6 @@ $(BLADE_LIBS) \ $(TRXCON_LDADD) osmo_trx_ms_blade_CPPFLAGS = $(AM_CPPFLAGS) $(BLADE_CFLAGS) -DBUILDBLADE - -bin_PROGRAMS += osmo-trx-syncthing-blade -osmo_trx_syncthing_blade_SOURCES = $(MS_LOWER_SRC) ms/ms_rx_burst_test.cpp -osmo_trx_syncthing_blade_LDADD = \ - $(builddir)/device/bladerf/libdevice.la \ - $(COMMON_LDADD) \ - $(BLADE_LIBS) \ - $(TRXCON_LDADD) -osmo_trx_syncthing_blade_CPPFLAGS = $(AM_CPPFLAGS) $(BLADE_CFLAGS) -DSYNCTHINGONLY -DBUILDBLADE -I../device/ipc endif endif diff --git a/Transceiver52M/ms/ms.cpp b/Transceiver52M/ms/ms.cpp index ca3339b..2e91cae 100644 --- a/Transceiver52M/ms/ms.cpp +++ b/Transceiver52M/ms/ms.cpp @@ -29,16 +29,10 @@ #include <thread> #include <fstream> -#include "sigProcLib.h" - #include "ms.h" -#include "ms_rx_burst.h" -#include "grgsm_vitac/grgsm_vitac.h" extern "C" { #include "sch.h" -#include "convolve.h" -#include "convert.h" } dummylog ms_trx::dummy_log; @@ -52,196 +46,6 @@ template <> std::atomic<bool> ms_trx::base::stop_lower_threads_flag(false); -void tx_test(ms_trx *t, ts_hitter_q_t *q, unsigned int *tsc) -{ - sched_param sch_params; - sch_params.sched_priority = sched_get_priority_max(SCHED_FIFO); - pthread_setschedparam(pthread_self(), SCHED_FIFO, &sch_params); - - auto burst = genRandAccessBurst(0, 4, 0); - scaleVector(*burst, t->txFullScale); - - // float -> int16 - blade_sample_type burst_buf[burst->size()]; - convert_and_scale(burst_buf, burst->begin(), burst->size() * 2, 1); - - while (1) { - GSM::Time target; - while (!q->spsc_pop(&target)) { - q->spsc_prep_pop(); - } - - std::cerr << std::endl << "\x1B[32m hitting " << target.FN() << "\033[0m" << std::endl; - - int timing_advance = 0; - int64_t now_ts; - GSM::Time now_time; - target.incTN(3); // ul dl offset - int target_fn = target.FN(); - int target_tn = target.TN(); - t->timekeeper.get_both(&now_time, &now_ts); - - auto diff_fn = GSM::FNDelta(target_fn, now_time.FN()); - int diff_tn = (target_tn - (int)now_time.TN()) % 8; - auto tosend = GSM::Time(diff_fn, 0); - - if (diff_tn > 0) - tosend.incTN(diff_tn); - else if (diff_tn < 0) - tosend.decTN(-diff_tn); - - // in thory fn equal and tn+3 equal is also a problem... - if (diff_fn < 0 || (diff_fn == 0 && (now_time.TN() - target_tn < 1))) { - std::cerr << "## TX too late?! fn DIFF:" << diff_fn << " tn LOCAL: " << now_time.TN() - << " tn OTHER: " << target_tn << std::endl; - return; - } - - auto check = now_time + tosend; - int64_t send_ts = - now_ts + tosend.FN() * 8 * ONE_TS_BURST_LEN + tosend.TN() * ONE_TS_BURST_LEN - timing_advance; - -#ifdef DBGXX - std::cerr << "## fn DIFF: " << diff_fn << " ## tn DIFF: " << diff_tn << " tn LOCAL: " << now_time.TN() - << " tn OTHER: " << target_tn << " tndiff" << diff_tn << " tosend:" << tosend.FN() << ":" - << tosend.TN() << " calc: " << check.FN() << ":" << check.TN() << " target: " << target.FN() - << ":" << target.TN() << " ts now: " << now_ts << " target ts:" << send_ts << std::endl; -#endif - - unsigned int pad = 4 * 25; - blade_sample_type buf2[burst->size() + pad]; - std::fill(buf2, buf2 + pad, 0); - - memcpy(&buf2[pad], burst_buf, burst->size() * sizeof(blade_sample_type)); - - assert(target.FN() == check.FN()); - assert(target.TN() == check.TN()); - assert(target.FN() % 51 == 21); -#ifdef DBGXX - auto this_offset = offset_start + (offset_ctr++ % offsetrange); - std::cerr << "-- O " << this_offset << std::endl; - send_ts = now_ts - timing_advance + - ((target.FN() * 8 + (int)target.TN()) - (now_time.FN() * 8 + (int)now_time.TN())) * - ONE_TS_BURST_LEN; -#endif - t->submit_burst_ts(buf2, burst->size() + pad, send_ts - pad); -#ifdef DBGXX - signalVector test(burst->size() + pad); - convert_and_scale(test.begin(), buf2, burst->size() * 2 + pad, 1.f / float(scale)); - estim_burst_params ebp; - auto det = detectAnyBurst(test, 0, 4, 4, CorrType::RACH, 40, &ebp); - if (det > 0) - std::cerr << "## Y " << ebp.toa << std::endl; - else - std::cerr << "## NOOOOOOOOO " << ebp.toa << std::endl; -#endif - } -} -#ifdef SYNCTHINGONLY -template <typename A> -auto parsec(std::vector<std::string> &v, A &itr, std::string arg, bool *rv) -{ - if (*itr == arg) { - *rv = true; - return true; - } - return false; -} - -template <typename A, typename B, typename C> -bool parsec(std::vector<std::string> &v, A &itr, std::string arg, B f, C *rv) -{ - if (*itr == arg) { - itr++; - if (itr != v.end()) { - *rv = f(itr->c_str()); - return true; - } - } - return false; -} -template <typename A> -bool parsec(std::vector<std::string> &v, A &itr, std::string arg, int scale, int *rv) -{ - return parsec( - v, itr, arg, [scale](const char *v) -> auto { return atoi(v) * scale; }, rv); -} -template <typename A> -bool parsec(std::vector<std::string> &v, A &itr, std::string arg, int scale, unsigned int *rv) -{ - return parsec( - v, itr, arg, [scale](const char *v) -> auto { return atoi(v) * scale; }, rv); -} - -int main(int argc, char *argv[]) -{ - cpu_set_t cpuset; - - CPU_ZERO(&cpuset); - CPU_SET(2, &cpuset); - - auto rv = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); - if (rv < 0) { - std::cerr << "affinity: errreur! " << std::strerror(errno); - return 0; - } - - unsigned int default_tx_freq(881000 * 1000), default_rx_freq(926000 * 1000); - unsigned int grx = 20, gtx = 20; - bool tx_flag = false; - pthread_setname_np(pthread_self(), "main"); - convolve_init(); - convert_init(); - sigProcLibSetup(); - initvita(); - - int status = 0; - auto trx = new ms_trx(); - trx->do_auto_gain = true; - - std::vector<std::string> args(argv + 1, argv + argc); - for (auto i = args.begin(); i != args.end(); ++i) { - parsec(args, i, "-r", 1000, &default_rx_freq); - parsec(args, i, "-t", 1000, &default_tx_freq); - parsec(args, i, "-gr", 1, &grx); - parsec(args, i, "-gt", 1, >x); - parsec(args, i, "-tx", &tx_flag); - } - - std::cerr << "usage: " << argv[0] << " <rxfreq in khz, i.e. 926000> [txfreq in khz, i.e. 881000] [TX]" - << std::endl - << "rx" << (argc == 1 ? " (default) " : " ") << default_rx_freq << "hz, tx " << default_tx_freq - << "hz" << std::endl - << "gain rx " << grx << " gain tx " << gtx << std::endl - << (tx_flag ? "##!!## RACH TX ACTIVE ##!!##" : "-- no rach tx --") << std::endl; - - status = trx->init_dev_and_streams(); - if (status < 0) - return status; - trx->tuneRx(default_rx_freq); - trx->tuneTx(default_tx_freq); - trx->setRxGain(grx); - trx->setTxGain(gtx); - - if (status == 0) { - // FIXME: hacks! needs exit flag for detached threads! - - std::thread(rcv_bursts_test, &trx->rxqueue, &trx->mTSC, trx->rxFullScale).detach(); - if (tx_flag) - std::thread(tx_test, trx, &trx->ts_hitter_q, &trx->mTSC).detach(); - trx->start(); - do { - sleep(1); - } while (1); - - trx->stop_threads(); - } - delete trx; - - return status; -} -#endif - int ms_trx::init_dev_and_streams() { int status = 0; diff --git a/Transceiver52M/ms/ms.h b/Transceiver52M/ms/ms.h index 3b97d1b..efccffc 100644 --- a/Transceiver52M/ms/ms.h +++ b/Transceiver52M/ms/ms.h @@ -251,9 +251,7 @@ // provides bursts to upper rx thread rx_queue_t rxqueue; -#ifdef SYNCTHINGONLY - ts_hitter_q_t ts_hitter_q; -#endif + blade_sample_type *first_sch_buf; blade_sample_type *burst_copy_buffer; diff --git a/Transceiver52M/ms/ms_rx_burst.h b/Transceiver52M/ms/ms_rx_burst.h deleted file mode 100644 index 764a69e..0000000 --- a/Transceiver52M/ms/ms_rx_burst.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -/* - * (C) 2022 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de> - * All Rights Reserved - * - * Author: Eric Wild <ewild(a)sysmocom.de> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <
http://www.gnu.org/licenses/
>. - * - */ - -#include "ms.h" - -void rcv_bursts_test(rx_queue_t *q, unsigned int *tsc, int scale); \ No newline at end of file diff --git a/Transceiver52M/ms/ms_rx_burst_test.cpp b/Transceiver52M/ms/ms_rx_burst_test.cpp deleted file mode 100644 index c3ba4ee..0000000 --- a/Transceiver52M/ms/ms_rx_burst_test.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - * (C) 2022 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de> - * All Rights Reserved - * - * Author: Eric Wild <ewild(a)sysmocom.de> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <
http://www.gnu.org/licenses/
>. - * - */ -#include "ms.h" -#include "sigProcLib.h" -#include "signalVector.h" -#include "grgsm_vitac/grgsm_vitac.h" -extern "C" { -#include "sch.h" -} - -#if !defined(SYNCTHINGONLY) || !defined(NODAMNLOG) -#define DBGLG(...) ms_trx::dummy_log() -#else -#define DBGLG(...) std::cerr -#endif - -#if !defined(SYNCTHINGONLY) -#define DBGLG2(...) ms_trx::dummy_log() -#else -#define DBGLG2(...) std::cerr -#endif - -static bool decode_sch(float *bits, bool update_global_clock) -{ - struct sch_info sch; - ubit_t info[GSM_SCH_INFO_LEN]; - sbit_t data[GSM_SCH_CODED_LEN]; - - float_to_sbit(&bits[3], &data[0], 62, 39); - float_to_sbit(&bits[106], &data[39], 62, 39); - - if (!gsm_sch_decode(info, data)) { - gsm_sch_parse(info, &sch); - - DBGLG() << "SCH : Decoded values" << std::endl; - DBGLG() << " BSIC: " << sch.bsic << std::endl; - DBGLG() << " TSC: " << (sch.bsic & 0x7) << std::endl; - DBGLG() << " T1 : " << sch.t1 << std::endl; - DBGLG() << " T2 : " << sch.t2 << std::endl; - DBGLG() << " T3p : " << sch.t3p << std::endl; - DBGLG() << " FN : " << gsm_sch_to_fn(&sch) << std::endl; - return true; - } - return false; -} - -static void check_rcv_fn(GSM::Time t, bool first, unsigned int &lastfn, unsigned int &fnbm) -{ - if (first && t.TN() == 0) { - lastfn = t.FN(); - fnbm = 1 << 0; - first = false; - } - if (!first && t.FN() != (int)lastfn) { - if (fnbm != 255) - std::cerr << "rx " << lastfn << ":" << fnbm << " " << __builtin_popcount(fnbm) << std::endl; - lastfn = t.FN(); - fnbm = 1 << t.TN(); - } - - fnbm |= 1 << t.TN(); -} - -static void handle_it(one_burst &e, signalVector &burst, unsigned int tsc, int scale) -{ - std::fill(burst.begin(), burst.begin() + burst.size(), 0.0); - const auto is_sch = gsm_sch_check_ts(e.gsmts.TN(), e.gsmts.FN()); - const auto is_fcch = gsm_fcch_check_ts(e.gsmts.TN(), e.gsmts.FN()); - - if (is_fcch) - return; - - if (is_sch) { - char outbin[148]; - convert_and_scale(burst.begin(), e.burst, ONE_TS_BURST_LEN * 2, SAMPLE_SCALE_FACTOR); - std::stringstream dbgout; -#if 0 - { - struct estim_burst_params ebp; - auto rv2 = detectSCHBurst(burst, 4, 4, sch_detect_type::SCH_DETECT_FULL, &ebp); - auto bits = demodAnyBurst(burst, SCH, 4, &ebp); - // clamp_array(bits->begin(), 148, 1.5f); - for (auto &i : *bits) - i = (i > 0 ? 1 : -1); - - auto rv = decode_sch(bits->begin(), false); - dbgout << "U DET@" << (rv2 ? "yes " : " ") << "Timing offset " << ebp.toa - << " symbols, DECODE: " << (rv ? "yes" : "---") << " "; - - delete bits; - } -#endif - { - convert_and_scale(burst.begin(), burst.begin(), ONE_TS_BURST_LEN * 2, 1.f / float(scale)); - - std::complex<float> channel_imp_resp[CHAN_IMP_RESP_LENGTH * d_OSR]; - auto ss = reinterpret_cast<std::complex<float> *>(burst.begin()); - int d_c0_burst_start = get_sch_chan_imp_resp(ss, &channel_imp_resp[0]); - detect_burst(ss, &channel_imp_resp[0], d_c0_burst_start, outbin); - - SoftVector bits; - bits.resize(148); - for (int i = 0; i < 148; i++) { - bits[i] = (!outbin[i]); // < 1 ? -1 : 1; - } - - auto rv = decode_sch(bits.begin(), false); - dbgout << "U SCH@" - << " " << e.gsmts.FN() << ":" << e.gsmts.TN() << " " << d_c0_burst_start - << " DECODE:" << (rv ? "yes" : "---") << std::endl; - } - - DBGLG() << dbgout.str(); - return; - } -#if 1 - convert_and_scale(burst.begin(), e.burst, ONE_TS_BURST_LEN * 2, 1.f / float(scale)); - // std::cerr << "@" << tsc << " " << e.gsmts.FN() << ":" << e.gsmts.TN() << " " << ebp.toa << " " - // << std::endl; - - char outbin[148]; - auto ss = reinterpret_cast<std::complex<float> *>(burst.begin()); - float ncmax, dcmax; - std::complex<float> chan_imp_resp[CHAN_IMP_RESP_LENGTH * d_OSR], chan_imp_resp2[CHAN_IMP_RESP_LENGTH * d_OSR]; - auto normal_burst_start = get_norm_chan_imp_resp(ss, &chan_imp_resp[0], &ncmax, tsc); - auto dummy_burst_start = get_norm_chan_imp_resp(ss, &chan_imp_resp2[0], &dcmax, TS_DUMMY); - auto is_nb = ncmax > dcmax; - - DBGLG() << " U " << (is_nb ? "NB" : "DB") << "@ o nb: " << normal_burst_start << " o db: " << dummy_burst_start - << std::endl; - - if (is_nb) - detect_burst(ss, &chan_imp_resp[0], normal_burst_start, outbin); - else - detect_burst(ss, &chan_imp_resp2[0], dummy_burst_start, outbin); - ; -#ifdef DBGXX - // auto bits = SoftVector(148); - // for (int i = 0; i < 148; i++) - // (bits)[i] = outbin[i] < 1 ? -1 : 1; -#endif -#endif -} - -void rcv_bursts_test(rx_queue_t *q, unsigned int *tsc, int scale) -{ - static bool first = true; - unsigned int lastfn = 0; - unsigned int fnbm = 0; - signalVector burst(ONE_TS_BURST_LEN, 100, 100); - - cpu_set_t cpuset; - - CPU_ZERO(&cpuset); - CPU_SET(1, &cpuset); - - auto rv = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); - if (rv < 0) { - std::cerr << "affinity: errreur! " << std::strerror(errno); - exit(0); - } - - int prio = sched_get_priority_max(SCHED_RR); - struct sched_param param; - param.sched_priority = prio; - rv = sched_setscheduler(0, SCHED_RR, ¶m); - if (rv < 0) { - std::cerr << "scheduler: errreur! " << std::strerror(errno); - exit(0); - } - - while (1) { - one_burst e; - while (!q->spsc_pop(&e)) { - q->spsc_prep_pop(); - } - - check_rcv_fn(e.gsmts, first, lastfn, fnbm); - - handle_it(e, burst, *tsc, scale); -#ifdef DBGXX - rv = detectSCHBurst(*burst, 4, 4, sch_detect_type::SCH_DETECT_FULL, &ebp); - if (rv > 0) - std::cerr << "#" << e.gsmts.FN() << ":" << e.gsmts.TN() << " " << ebp.toa << std::endl; - sched_yield(); -#endif - } -} \ No newline at end of file diff --git a/Transceiver52M/ms/ms_rx_lower.cpp b/Transceiver52M/ms/ms_rx_lower.cpp index 3a7e6ec..992591e 100644 --- a/Transceiver52M/ms/ms_rx_lower.cpp +++ b/Transceiver52M/ms/ms_rx_lower.cpp @@ -38,13 +38,13 @@ #undef LOG #endif -#if !defined(SYNCTHINGONLY) //|| !defined(NODAMNLOG) +#if !defined(NODAMNLOG) #define DBGLG(...) ms_trx::dummy_log() #else #define DBGLG(...) std::cerr #endif -#if !defined(SYNCTHINGONLY) || !defined(NODAMNLOG) +#if !defined(NODAMNLOG) #define DBGLG2(...) ms_trx::dummy_log() #else #define DBGLG2(...) std::cerr @@ -87,18 +87,6 @@ // global_time_keeper.FN(fn); // global_time_keeper.TN(0); } -#ifdef SYNCTHINGONLY - else { - int t3 = sch.t3p * 10 + 1; - if (t3 == 11) { - // timeslot hitter attempt @ fn 21 in mf - DBGLG2() << "sch @ " << t3 << std::endl; - auto e = GSM::Time(fn, 0); - e += 10; - ts_hitter_q.spsc_push(&e); - } - } -#endif return true; } @@ -153,14 +141,11 @@ handle_sch(false); memcpy(brst.sch_bits, sch_demod_bits, sizeof(sch_demod_bits)); } -#ifndef SYNCTHINGONLY + if (upper_is_ready) { // this is blocking, so only submit if there is a reader - only if upper exists! -#endif while (!rxqueue.spsc_push(&brst)) ; -#ifndef SYNCTHINGONLY } -#endif if (do_auto_gain) maybe_update_gain(brst); -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32952
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: Ie97069a109324b6e96c66a4b24d03f9745b6a52e Gerrit-Change-Number: 32952 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
[L] Change in osmo-trx[master]: ms: rearrange internal trxcon<->phy if
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32951
) Change subject: ms: rearrange internal trxcon<->phy if ...................................................................... ms: rearrange internal trxcon<->phy if Change-Id: I20aef3844f7699e164fe089358aa7e2325608c85 --- M Transceiver52M/Makefile.am M Transceiver52M/ms/l1ctl_server_cb.cpp M Transceiver52M/ms/ms_rx_lower.cpp A Transceiver52M/ms/ms_trxcon_if.cpp A Transceiver52M/ms/ms_trxcon_if.h M Transceiver52M/ms/ms_upper.cpp M Transceiver52M/ms/ms_upper.h 7 files changed, 213 insertions(+), 172 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/51/32951/1 diff --git a/Transceiver52M/Makefile.am b/Transceiver52M/Makefile.am index 875e9a1..d657536 100644 --- a/Transceiver52M/Makefile.am +++ b/Transceiver52M/Makefile.am @@ -82,19 +82,27 @@ $(top_builddir)/osmocom-bb/src/host/trxcon/src/.libs/libl1sched.a \ $(LIBOSMOCODING_LIBS) -MS_SOURCES = \ +MS_LOWER_SRC = \ ms/sch.c \ ms/ms.cpp \ ms/ms_rx_lower.cpp \ grgsm_vitac/grgsm_vitac.cpp \ grgsm_vitac/viterbi_detector.cc +MS_UPPER_SRC = \ + ms/ms_upper.cpp \ + ms/l1ctl_server.c \ + ms/logging.c \ + ms/l1ctl_server_cb.cpp \ + ms/ms_trxcon_if.cpp + noinst_HEADERS += \ ms/ms.h \ ms/bladerf_specific.h \ ms/uhd_specific.h \ ms/ms_rx_burst.h \ ms/ms_upper.h \ + ms/ms_trxcon_if.h \ ms/itrq.h \ ms/sch.h \ grgsm_vitac/viterbi_detector.h \ @@ -116,7 +124,7 @@ if ENABLE_MS_TRX bin_PROGRAMS += osmo-trx-ms-uhd -osmo_trx_ms_uhd_SOURCES = $(MS_SOURCES) ms/ms_upper.cpp ms/l1ctl_server.c ms/logging.c ms/l1ctl_server_cb.cpp +osmo_trx_ms_uhd_SOURCES = $(MS_LOWER_SRC) $(MS_UPPER_SRC) osmo_trx_ms_uhd_LDADD = \ $(builddir)/device/uhd/libdevice.la \ $(COMMON_LDADD) \ @@ -125,7 +133,7 @@ osmo_trx_ms_uhd_CPPFLAGS = $(AM_CPPFLAGS) $(UHD_CFLAGS) -DBUILDUHD bin_PROGRAMS += osmo-trx-syncthing-uhd -osmo_trx_syncthing_uhd_SOURCES = $(MS_SOURCES) ms/ms_rx_burst_test.cpp +osmo_trx_syncthing_uhd_SOURCES = $(MS_LOWER_SRC) ms/ms_rx_burst_test.cpp osmo_trx_syncthing_uhd_LDADD = \ $(builddir)/device/uhd/libdevice.la \ $(COMMON_LDADD) \ @@ -166,7 +174,7 @@ if ENABLE_MS_TRX bin_PROGRAMS += osmo-trx-ms-blade -osmo_trx_ms_blade_SOURCES = $(MS_SOURCES) ms/ms_upper.cpp ms/l1ctl_server.c ms/logging.c ms/l1ctl_server_cb.cpp +osmo_trx_ms_blade_SOURCES = $(MS_LOWER_SRC) $(MS_UPPER_SRC) osmo_trx_ms_blade_LDADD = \ $(builddir)/device/bladerf/libdevice.la \ $(COMMON_LDADD) \ @@ -175,7 +183,7 @@ osmo_trx_ms_blade_CPPFLAGS = $(AM_CPPFLAGS) $(BLADE_CFLAGS) -DBUILDBLADE bin_PROGRAMS += osmo-trx-syncthing-blade -osmo_trx_syncthing_blade_SOURCES = $(MS_SOURCES) ms/ms_rx_burst_test.cpp +osmo_trx_syncthing_blade_SOURCES = $(MS_LOWER_SRC) ms/ms_rx_burst_test.cpp osmo_trx_syncthing_blade_LDADD = \ $(builddir)/device/bladerf/libdevice.la \ $(COMMON_LDADD) \ diff --git a/Transceiver52M/ms/l1ctl_server_cb.cpp b/Transceiver52M/ms/l1ctl_server_cb.cpp index 4121451..42f64ac 100644 --- a/Transceiver52M/ms/l1ctl_server_cb.cpp +++ b/Transceiver52M/ms/l1ctl_server_cb.cpp @@ -24,13 +24,10 @@ #include <osmocom/bb/trxcon/trxcon_fsm.h> #include <osmocom/bb/trxcon/l1ctl_server.h> } +#include "ms_trxcon_if.h" static struct l1ctl_server_cfg server_cfg; static struct l1ctl_server *server = NULL; -namespace trxcon -{ -extern struct trxcon_inst *g_trxcon; -} static int l1ctl_rx_cb(struct l1ctl_client *l1c, struct msgb *msg) { @@ -41,9 +38,9 @@ static void l1ctl_conn_accept_cb(struct l1ctl_client *l1c) { - l1c->log_prefix = talloc_strdup(l1c, trxcon::g_trxcon->log_prefix); - l1c->priv = trxcon::g_trxcon; - trxcon::g_trxcon->l2if = l1c; + l1c->log_prefix = talloc_strdup(l1c, g_trxcon->log_prefix); + l1c->priv = g_trxcon; + g_trxcon->l2if = l1c; } static void l1ctl_conn_close_cb(struct l1ctl_client *l1c) @@ -56,17 +53,13 @@ osmo_fsm_inst_dispatch(trxcon->fi, TRXCON_EV_L2IF_FAILURE, NULL); } -namespace trxcon -{ bool trxc_l1ctl_init(void *tallctx) { /* Start the L1CTL server */ server_cfg = (struct l1ctl_server_cfg){ /* TODO: make path configurable */ - .sock_path = "/tmp/osmocom_l2", - .num_clients_max = 1, - .conn_read_cb = &l1ctl_rx_cb, - .conn_accept_cb = &l1ctl_conn_accept_cb, + .sock_path = "/tmp/osmocom_l2", .num_clients_max = 1, + .conn_read_cb = &l1ctl_rx_cb, .conn_accept_cb = &l1ctl_conn_accept_cb, .conn_close_cb = &l1ctl_conn_close_cb, }; @@ -76,4 +69,3 @@ } return true; } -} // namespace trxcon \ No newline at end of file diff --git a/Transceiver52M/ms/ms_rx_lower.cpp b/Transceiver52M/ms/ms_rx_lower.cpp index dc0d56d..3a7e6ec 100644 --- a/Transceiver52M/ms/ms_rx_lower.cpp +++ b/Transceiver52M/ms/ms_rx_lower.cpp @@ -19,8 +19,6 @@ * */ -#include "sigProcLib.h" -#include "signalVector.h" #include <atomic> #include <cassert> #include <complex> diff --git a/Transceiver52M/ms/ms_trxcon_if.cpp b/Transceiver52M/ms/ms_trxcon_if.cpp new file mode 100644 index 0000000..7de9710 --- /dev/null +++ b/Transceiver52M/ms/ms_trxcon_if.cpp @@ -0,0 +1,78 @@ +/* + * (C) 2023 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved + * + * Author: Eric Wild <ewild(a)sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <
http://www.gnu.org/licenses/
>. + * + */ + +#include <atomic> +#include "ms_trxcon_if.h" +extern "C" { +#include <osmocom/bb/trxcon/trxcon.h> +#include <osmocom/bb/trxcon/l1ctl_server.h> +#include <osmocom/core/panic.h> +} + +extern tx_queue_t txq; +extern cmd_queue_t cmdq_to_phy; +extern cmdr_queue_t cmdq_from_phy; +extern std::atomic<bool> g_exit_flag; +// trxcon C call(back) if +extern "C" { +int trxcon_phyif_handle_burst_req(void *phyif, const struct trxcon_phyif_burst_req *br) +{ + if (br->burst_len == 0) // dummy/nope + return 0; + OSMO_ASSERT(br->burst != 0); + + internal_q_tx_buf b(br); + if (!g_exit_flag) + txq.spsc_push(&b); + return 0; +} + +int trxcon_phyif_handle_cmd(void *phyif, const struct trxcon_phyif_cmd *cmd) +{ +#ifdef TXDEBUG + DBGLG() << "TOP C: " << cmd2str(cmd->type) << std::endl; +#endif + if (!g_exit_flag) + cmdq_to_phy.spsc_push(cmd); + // q for resp polling happens in main loop + return 0; +} + +void trxcon_phyif_close(void *phyif) +{ +} + +void trxcon_l1ctl_close(struct trxcon_inst *trxcon) +{ + /* Avoid use-after-free: both *fi and *trxcon are children of + * the L2IF (L1CTL connection), so we need to re-parent *fi + * to NULL before calling l1ctl_client_conn_close(). */ + talloc_steal(NULL, trxcon->fi); + l1ctl_client_conn_close((struct l1ctl_client *)trxcon->l2if); +} + +int trxcon_l1ctl_send(struct trxcon_inst *trxcon, struct msgb *msg) +{ + struct l1ctl_client *l1c = (struct l1ctl_client *)trxcon->l2if; + + return l1ctl_client_send(l1c, msg); +} +} diff --git a/Transceiver52M/ms/ms_trxcon_if.h b/Transceiver52M/ms/ms_trxcon_if.h new file mode 100644 index 0000000..9879d1a --- /dev/null +++ b/Transceiver52M/ms/ms_trxcon_if.h @@ -0,0 +1,42 @@ +#pragma once +/* + * (C) 2023 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved + * + * Author: Eric Wild <ewild(a)sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <
http://www.gnu.org/licenses/
>. + * + */ + +#include "ms.h" +extern "C" { +#include <osmocom/bb/trxcon/phyif.h> +} + +extern struct trxcon_inst *g_trxcon; +struct internal_q_tx_buf { + trxcon_phyif_burst_req r; + uint8_t buf[148]; + internal_q_tx_buf() = default; + internal_q_tx_buf(const internal_q_tx_buf &) = delete; + internal_q_tx_buf &operator=(const internal_q_tx_buf &) = default; + internal_q_tx_buf(const struct trxcon_phyif_burst_req *br) : r(*br) + { + memcpy(buf, (void *)br->burst, br->burst_len); + } +}; +using tx_queue_t = spsc_cond<8 * 1, internal_q_tx_buf, true, false>; +using cmd_queue_t = spsc_cond<8 * 1, trxcon_phyif_cmd, true, false>; +using cmdr_queue_t = spsc_cond<8 * 1, trxcon_phyif_rsp, false, false>; diff --git a/Transceiver52M/ms/ms_upper.cpp b/Transceiver52M/ms/ms_upper.cpp index cae1893..a10d542 100644 --- a/Transceiver52M/ms/ms_upper.cpp +++ b/Transceiver52M/ms/ms_upper.cpp @@ -19,6 +19,7 @@ * */ +#include <csignal> #include "sigProcLib.h" #include "ms.h" #include <signalVector.h> @@ -27,70 +28,30 @@ #include <grgsm_vitac/grgsm_vitac.h> extern "C" { -#include <stdio.h> -#include <stdlib.h> -#include <stdint.h> -#include <string.h> -#include <getopt.h> -#include <unistd.h> -#include <signal.h> -#include <errno.h> -#include <time.h> -#include <fenv.h> #include "sch.h" #include "convolve.h" #include "convert.h" +#include <osmocom/gsm/gsm_utils.h> +#include <osmocom/bb/trxcon/trxcon.h> +#include <osmocom/bb/trxcon/trxcon_fsm.h> +#include <osmocom/bb/trxcon/l1ctl_server.h> + +extern void trxc_log_init(void *tallctx); #ifdef LSANDEBUG void __lsan_do_recoverable_leak_check(); #endif } +#include "ms_trxcon_if.h" #include "ms_upper.h" -namespace trxcon -{ -extern "C" { -#include <osmocom/core/fsm.h> -#include <osmocom/core/msgb.h> -#include <osmocom/core/talloc.h> -#include <osmocom/core/signal.h> -#include <osmocom/core/select.h> -#include <osmocom/gsm/gsm_utils.h> - -#include <osmocom/core/logging.h> -#include <osmocom/bb/trxcon/logging.h> - -#include <osmocom/bb/trxcon/trxcon.h> -#include <osmocom/bb/trxcon/trxcon_fsm.h> -#include <osmocom/bb/trxcon/phyif.h> -#include <osmocom/bb/trxcon/l1ctl_server.h> -} -struct trxcon_inst *g_trxcon; -// trx_instance *trxcon_instance; // local handle -struct internal_q_tx_buf { - trxcon_phyif_burst_req r; - uint8_t buf[148]; - internal_q_tx_buf() = default; - internal_q_tx_buf(const internal_q_tx_buf &) = delete; - internal_q_tx_buf &operator=(const internal_q_tx_buf &) = default; - internal_q_tx_buf(const struct trxcon::trxcon_phyif_burst_req *br) : r(*br) - { - memcpy(buf, (void *)br->burst, br->burst_len); - } -}; -using tx_queue_t = spsc_cond<8 * 1, internal_q_tx_buf, true, false>; -using cmd_queue_t = spsc_cond<8 * 1, trxcon_phyif_cmd, true, false>; -using cmdr_queue_t = spsc_cond<8 * 1, trxcon_phyif_rsp, false, false>; -static tx_queue_t txq; -static cmd_queue_t cmdq_to_phy; -static cmdr_queue_t cmdq_from_phy; - extern bool trxc_l1ctl_init(void *tallctx); - -} // namespace trxcon -extern "C" void trxc_log_init(void *tallctx); +struct trxcon_inst *g_trxcon; +tx_queue_t txq; +cmd_queue_t cmdq_to_phy; +cmdr_queue_t cmdq_from_phy; #ifdef LOG #undef LOG @@ -138,12 +99,12 @@ // set_upper_ready(true) needs to happen during cmd handling: // the main loop is driven by rx, so unless rx is on AND transceiver is on we get stuck.. driveReceiveFIFO(); - trxcon::osmo_select_main(1); + osmo_select_main(1); - trxcon::trxcon_phyif_rsp r; - if (trxcon::cmdq_from_phy.spsc_pop(&r)) { + trxcon_phyif_rsp r; + if (cmdq_from_phy.spsc_pop(&r)) { DBGLG() << "HAVE RESP:" << r.type << std::endl; - trxcon_phyif_handle_rsp(trxcon::g_trxcon, &r); + trxcon_phyif_handle_rsp(g_trxcon, &r); } } set_upper_ready(false); @@ -196,9 +157,9 @@ const auto is_sch = gsm_sch_check_ts(wTime.TN(), wTime.FN()); const auto is_fcch = gsm_fcch_check_ts(wTime.TN(), wTime.FN()); - trxcon::trxcon_phyif_rtr_ind i = { static_cast<uint32_t>(wTime.FN()), static_cast<uint8_t>(wTime.TN()) }; - trxcon::trxcon_phyif_rtr_rsp r = {}; - trxcon_phyif_handle_rtr_ind(trxcon::g_trxcon, &i, &r); + trxcon_phyif_rtr_ind i = { static_cast<uint32_t>(wTime.FN()), static_cast<uint8_t>(wTime.TN()) }; + trxcon_phyif_rtr_rsp r = {}; + trxcon_phyif_handle_rtr_ind(g_trxcon, &i, &r); if (!(r.flags & TRXCON_PHYIF_RTR_F_ACTIVE)) return false; @@ -265,28 +226,28 @@ return; if (pullRadioVector(burstTime, RSSI, TOA)) { - trxcon::trxcon_phyif_burst_ind bi; + trxcon_phyif_burst_ind bi; bi.fn = burstTime.FN(); bi.tn = burstTime.TN(); bi.rssi = RSSI; bi.toa256 = TOA; bi.burst = (sbit_t *)demodded_softbits; bi.burst_len = sizeof(demodded_softbits); - trxcon_phyif_handle_burst_ind(trxcon::g_trxcon, &bi); + trxcon_phyif_handle_burst_ind(g_trxcon, &bi); } - struct trxcon::trxcon_phyif_rts_ind rts { + struct trxcon_phyif_rts_ind rts { static_cast<uint32_t>(burstTime.FN()), static_cast<uint8_t>(burstTime.TN()) }; - trxcon_phyif_handle_rts_ind(trxcon::g_trxcon, &rts); + trxcon_phyif_handle_rts_ind(g_trxcon, &rts); } void upper_trx::driveTx() { - trxcon::internal_q_tx_buf e; + internal_q_tx_buf e; static BitVector newBurst(sizeof(e.buf)); - while (!trxcon::txq.spsc_pop(&e)) { - trxcon::txq.spsc_prep_pop(); + while (!txq.spsc_pop(&e)) { + txq.spsc_prep_pop(); } // ensure our tx cb is tickled and can exit @@ -295,7 +256,7 @@ return; } - trxcon::internal_q_tx_buf *burst = &e; + internal_q_tx_buf *burst = &e; #ifdef TXDEBUG DBGLG() << "got burst!" << burst->r.fn << ":" << burst->ts << " current: " << timekeeper.gsmtime().FN() @@ -333,31 +294,31 @@ } #ifdef TXDEBUG -static const char *cmd2str(trxcon::trxcon_phyif_cmd_type c) +static const char *cmd2str(trxcon_phyif_cmd_type c) { switch (c) { - case trxcon::TRXCON_PHYIF_CMDT_RESET: + case TRXCON_PHYIF_CMDT_RESET: return "TRXCON_PHYIF_CMDT_RESET"; - case trxcon::TRXCON_PHYIF_CMDT_POWERON: + case TRXCON_PHYIF_CMDT_POWERON: return "TRXCON_PHYIF_CMDT_POWERON"; - case trxcon::TRXCON_PHYIF_CMDT_POWEROFF: + case TRXCON_PHYIF_CMDT_POWEROFF: return "TRXCON_PHYIF_CMDT_POWEROFF"; - case trxcon::TRXCON_PHYIF_CMDT_MEASURE: + case TRXCON_PHYIF_CMDT_MEASURE: return "TRXCON_PHYIF_CMDT_MEASURE"; - case trxcon::TRXCON_PHYIF_CMDT_SETFREQ_H0: + case TRXCON_PHYIF_CMDT_SETFREQ_H0: return "TRXCON_PHYIF_CMDT_SETFREQ_H0"; - case trxcon::TRXCON_PHYIF_CMDT_SETFREQ_H1: + case TRXCON_PHYIF_CMDT_SETFREQ_H1: return "TRXCON_PHYIF_CMDT_SETFREQ_H1"; - case trxcon::TRXCON_PHYIF_CMDT_SETSLOT: + case TRXCON_PHYIF_CMDT_SETSLOT: return "TRXCON_PHYIF_CMDT_SETSLOT"; - case trxcon::TRXCON_PHYIF_CMDT_SETTA: + case TRXCON_PHYIF_CMDT_SETTA: return "TRXCON_PHYIF_CMDT_SETTA"; default: return "UNKNOWN COMMAND!"; } } -static void print_cmd(trxcon::trxcon_phyif_cmd_type c) +static void print_cmd(trxcon_phyif_cmd_type c) { DBGLG() << cmd2str(c) << std::endl; } @@ -365,10 +326,10 @@ bool upper_trx::driveControl() { - trxcon::trxcon_phyif_rsp r; - trxcon::trxcon_phyif_cmd cmd; - while (!trxcon::cmdq_to_phy.spsc_pop(&cmd)) { - trxcon::cmdq_to_phy.spsc_prep_pop(); + trxcon_phyif_rsp r; + trxcon_phyif_cmd cmd; + while (!cmdq_to_phy.spsc_pop(&cmd)) { + cmdq_to_phy.spsc_prep_pop(); } if (g_exit_flag) @@ -379,87 +340,41 @@ #endif switch (cmd.type) { - case trxcon::TRXCON_PHYIF_CMDT_RESET: + case TRXCON_PHYIF_CMDT_RESET: set_ta(0); break; - case trxcon::TRXCON_PHYIF_CMDT_POWERON: + case TRXCON_PHYIF_CMDT_POWERON: if (!mOn) { mOn = true; set_upper_ready(true); } break; - case trxcon::TRXCON_PHYIF_CMDT_POWEROFF: + case TRXCON_PHYIF_CMDT_POWEROFF: break; - case trxcon::TRXCON_PHYIF_CMDT_MEASURE: - r.type = trxcon::trxcon_phyif_cmd_type::TRXCON_PHYIF_CMDT_MEASURE; + case TRXCON_PHYIF_CMDT_MEASURE: + r.type = trxcon_phyif_cmd_type::TRXCON_PHYIF_CMDT_MEASURE; r.param.measure.band_arfcn = cmd.param.measure.band_arfcn; // FIXME: do we want to measure anything, considering the transceiver just syncs by.. syncing? r.param.measure.dbm = -80; - tuneRx(trxcon::gsm_arfcn2freq10(cmd.param.measure.band_arfcn, 0) * 1000 * 100); - tuneTx(trxcon::gsm_arfcn2freq10(cmd.param.measure.band_arfcn, 1) * 1000 * 100); - trxcon::cmdq_from_phy.spsc_push(&r); + tuneRx(gsm_arfcn2freq10(cmd.param.measure.band_arfcn, 0) * 1000 * 100); + tuneTx(gsm_arfcn2freq10(cmd.param.measure.band_arfcn, 1) * 1000 * 100); + cmdq_from_phy.spsc_push(&r); break; - case trxcon::TRXCON_PHYIF_CMDT_SETFREQ_H0: - tuneRx(trxcon::gsm_arfcn2freq10(cmd.param.setfreq_h0.band_arfcn, 0) * 1000 * 100); - tuneTx(trxcon::gsm_arfcn2freq10(cmd.param.setfreq_h0.band_arfcn, 1) * 1000 * 100); + case TRXCON_PHYIF_CMDT_SETFREQ_H0: + tuneRx(gsm_arfcn2freq10(cmd.param.setfreq_h0.band_arfcn, 0) * 1000 * 100); + tuneTx(gsm_arfcn2freq10(cmd.param.setfreq_h0.band_arfcn, 1) * 1000 * 100); break; - case trxcon::TRXCON_PHYIF_CMDT_SETFREQ_H1: + case TRXCON_PHYIF_CMDT_SETFREQ_H1: break; - case trxcon::TRXCON_PHYIF_CMDT_SETSLOT: + case TRXCON_PHYIF_CMDT_SETSLOT: break; - case trxcon::TRXCON_PHYIF_CMDT_SETTA: + case TRXCON_PHYIF_CMDT_SETTA: set_ta(cmd.param.setta.ta); break; } return false; } -// trxcon C call(back) if -extern "C" { -int trxcon_phyif_handle_burst_req(void *phyif, const struct trxcon::trxcon_phyif_burst_req *br) -{ - if (br->burst_len == 0) // dummy/nope - return 0; - OSMO_ASSERT(br->burst != 0); - - trxcon::internal_q_tx_buf b(br); - if (!g_exit_flag) - trxcon::txq.spsc_push(&b); - return 0; -} - -int trxcon_phyif_handle_cmd(void *phyif, const struct trxcon::trxcon_phyif_cmd *cmd) -{ -#ifdef TXDEBUG - DBGLG() << "TOP C: " << cmd2str(cmd->type) << std::endl; -#endif - if (!g_exit_flag) - trxcon::cmdq_to_phy.spsc_push(cmd); - // q for resp polling happens in main loop - return 0; -} - -void trxcon_phyif_close(void *phyif) -{ -} - -void trxcon_l1ctl_close(struct trxcon::trxcon_inst *trxcon) -{ - /* Avoid use-after-free: both *fi and *trxcon are children of - * the L2IF (L1CTL connection), so we need to re-parent *fi - * to NULL before calling l1ctl_client_conn_close(). */ - talloc_steal(NULL, trxcon->fi); - trxcon::l1ctl_client_conn_close((struct trxcon::l1ctl_client *)trxcon->l2if); -} - -int trxcon_l1ctl_send(struct trxcon::trxcon_inst *trxcon, struct trxcon::msgb *msg) -{ - struct trxcon::l1ctl_client *l1c = (struct trxcon::l1ctl_client *)trxcon->l2if; - - return trxcon::l1ctl_client_send(l1c, msg); -} -} - void sighandler(int sigset) { // we might get a sigpipe in case the l1ctl ud socket disconnects because mobile quits @@ -468,10 +383,10 @@ // we know the flag is atomic and it prevents the trxcon cb handlers from writing // to the queues, so submit some trash to unblock the threads & exit - trxcon::trxcon_phyif_cmd cmd = {}; - trxcon::internal_q_tx_buf b = {}; - trxcon::txq.spsc_push(&b); - trxcon::cmdq_to_phy.spsc_push(&cmd); + trxcon_phyif_cmd cmd = {}; + internal_q_tx_buf b = {}; + txq.spsc_push(&b); + cmdq_to_phy.spsc_push(&cmd); msleep(200); return; @@ -484,13 +399,13 @@ signal(SIGPIPE, sighandler); signal(SIGINT, sighandler); - trxcon::msgb_talloc_ctx_init(tall_trxcon_ctx, 0); + msgb_talloc_ctx_init(tall_trxcon_ctx, 0); trxc_log_init(tall_trxcon_ctx); - trxcon::g_trxcon = trxcon::trxcon_inst_alloc(tall_trxcon_ctx, 0, 0); - trxcon::g_trxcon->gsmtap = nullptr; - trxcon::g_trxcon->phyif = nullptr; - trxcon::g_trxcon->phy_quirks.fbsb_extend_fns = 866; // 4 seconds, known to work. + g_trxcon = trxcon_inst_alloc(tall_trxcon_ctx, 0, 0); + g_trxcon->gsmtap = nullptr; + g_trxcon->phyif = nullptr; + g_trxcon->phy_quirks.fbsb_extend_fns = 866; // 4 seconds, known to work. convolve_init(); convert_init(); @@ -508,7 +423,7 @@ } trx->set_name_aff_sched(sched_params::thread_names::MAIN); - if (!trxcon::trxc_l1ctl_init(tall_trxcon_ctx)) { + if (!trxc_l1ctl_init(tall_trxcon_ctx)) { std::cerr << "Error initializing l1ctl, quitting.." << std::endl; return -1; } diff --git a/Transceiver52M/ms/ms_upper.h b/Transceiver52M/ms/ms_upper.h index fe20f6d..bc9bd14 100644 --- a/Transceiver52M/ms/ms_upper.h +++ b/Transceiver52M/ms/ms_upper.h @@ -24,7 +24,6 @@ #include <arpa/inet.h> #include "GSMCommon.h" -#include "radioClock.h" #include "ms.h" class upper_trx : public ms_trx { -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32951
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: I20aef3844f7699e164fe089358aa7e2325608c85 Gerrit-Change-Number: 32951 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
[S] Change in osmo-trx[master]: ms: prune common sch acq code
by Hoernchen
Hoernchen has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/32953
) Change subject: ms: prune common sch acq code ...................................................................... ms: prune common sch acq code Change-Id: Ife639a78a4463f992247c19e0177f683db2ae0b7 --- M Transceiver52M/ms/ms_rx_lower.cpp 1 file changed, 11 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/53/32953/1 diff --git a/Transceiver52M/ms/ms_rx_lower.cpp b/Transceiver52M/ms/ms_rx_lower.cpp index 992591e..4d6ce18 100644 --- a/Transceiver52M/ms/ms_rx_lower.cpp +++ b/Transceiver52M/ms/ms_rx_lower.cpp @@ -166,18 +166,16 @@ int start; memset((void *)&sch_acq_buffer[0], 0, sizeof(sch_acq_buffer)); + convert_and_scale(which_out_buffer, which_in_buffer, buf_len * 2, 1.f / float(rxFullScale)); if (is_first_sch_acq) { float max_corr = 0; - convert_and_scale(which_out_buffer, which_in_buffer, buf_len * 2, 1.f / float(rxFullScale)); start = get_sch_buffer_chan_imp_resp(ss, &channel_imp_resp[0], buf_len, &max_corr); - detect_burst(&ss[start], &channel_imp_resp[0], 0, sch_demod_bits); } else { - convert_and_scale(which_out_buffer, which_in_buffer, buf_len * 2, 1.f / float(rxFullScale)); start = get_sch_chan_imp_resp(ss, &channel_imp_resp[0]); start = start < 39 ? start : 39; start = start > -39 ? start : -39; - detect_burst(&ss[start], &channel_imp_resp[0], 0, sch_demod_bits); } + detect_burst(&ss[start], &channel_imp_resp[0], 0, sch_demod_bits); SoftVector bitss(148); for (int i = 0; i < 148; i++) { -- To view, visit
https://gerrit.osmocom.org/c/osmo-trx/+/32953
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-Change-Id: Ife639a78a4463f992247c19e0177f683db2ae0b7 Gerrit-Change-Number: 32953 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-MessageType: newchange
2 years, 1 month
1
0
0
0
← Newer
1
...
98
99
100
101
102
103
104
...
259
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
Results per page:
10
25
50
100
200