From 4fb8011a6dac397c53eeef1ac26202e13dc1f310 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Tue, 14 Jul 2020 12:05:17 +0100 Subject: [PATCH] updated phy controller to use task scheduler --- srsue/hdr/stack/rrc/phy_controller.h | 6 +++--- srsue/hdr/stack/rrc/rrc.h | 2 -- srsue/src/stack/rrc/phy_controller.cc | 26 ++++++++++++++++++-------- srsue/src/stack/rrc/rrc.cc | 22 +--------------------- srsue/test/upper/rrc_phy_ctrl_test.cc | 13 +++++++------ 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/srsue/hdr/stack/rrc/phy_controller.h b/srsue/hdr/stack/rrc/phy_controller.h index 69f15daf1..1fdb99e79 100644 --- a/srsue/hdr/stack/rrc/phy_controller.h +++ b/srsue/hdr/stack/rrc/phy_controller.h @@ -54,7 +54,7 @@ public: struct in_sync_ev {}; struct out_sync_ev {}; - explicit phy_controller(phy_interface_rrc_lte* phy_, stack_interface_rrc* stack_); + explicit phy_controller(phy_interface_rrc_lte* phy_, srslte::task_sched_handle task_sched_); // PHY procedures interfaces bool start_cell_select(const phy_cell_t& phy_cell, const srslte::event_callback& on_complete); @@ -117,8 +117,8 @@ public: }; private: - phy_interface_rrc_lte* phy = nullptr; - stack_interface_rrc* stack = nullptr; + phy_interface_rrc_lte* phy = nullptr; + srslte::task_sched_handle task_sched; std::vector > csearch_callbacks; diff --git a/srsue/hdr/stack/rrc/rrc.h b/srsue/hdr/stack/rrc/rrc.h index 55d595b4f..4ede92dcc 100644 --- a/srsue/hdr/stack/rrc/rrc.h +++ b/srsue/hdr/stack/rrc/rrc.h @@ -165,8 +165,6 @@ private: srslte::block_queue cmd_q; void process_pcch(srslte::unique_byte_buffer_t pdu); - void start_phy_cell_search(); - void start_phy_cell_select(const phy_interface_rrc_lte::phy_cell_t* cell); stack_interface_rrc* stack = nullptr; srslte::task_sched_handle task_sched; diff --git a/srsue/src/stack/rrc/phy_controller.cc b/srsue/src/stack/rrc/phy_controller.cc index 08c9cfe81..5889cef34 100644 --- a/srsue/src/stack/rrc/phy_controller.cc +++ b/srsue/src/stack/rrc/phy_controller.cc @@ -30,10 +30,10 @@ std::string to_string(const phy_interface_rrc_lte::phy_cell_t& cell) return buffer; } -phy_controller::phy_controller(srsue::phy_interface_rrc_lte* phy_, srsue::stack_interface_rrc* stack_) : +phy_controller::phy_controller(srsue::phy_interface_rrc_lte* phy_, srslte::task_sched_handle task_sched_) : base_t(srslte::log_ref{"RRC"}), phy(phy_), - stack(stack_) + task_sched(task_sched_) {} /************************************** @@ -62,7 +62,7 @@ void phy_controller::in_sync() phy_controller::selecting_cell::selecting_cell(phy_controller* parent_) : nested_fsm_t(parent_) { - wait_in_sync_timer = parent_fsm()->stack->get_unique_timer(); + wait_in_sync_timer = parent_fsm()->task_sched.get_unique_timer(); } void phy_controller::selecting_cell::enter(phy_controller* f, const cell_sel_cmd& ev) @@ -72,7 +72,12 @@ void phy_controller::selecting_cell::enter(phy_controller* f, const cell_sel_cmd csel_res.result = false; fsmInfo("Starting for pci=%d, earfcn=%d\n", target_cell.pci, target_cell.earfcn); - f->stack->start_cell_select(&target_cell); + phy_interface_rrc_lte::phy_cell_t cell_copy = target_cell; + f->task_sched.enqueue_background_task([f, cell_copy](uint32_t worker_id) { + bool ret = f->phy->cell_select(&cell_copy); + // notify back RRC + f->task_sched.notify_background_task_result([f, ret]() { f->cell_selection_completed(ret); }); + }); } void phy_controller::selecting_cell::exit(phy_controller* f) @@ -86,7 +91,7 @@ void phy_controller::selecting_cell::exit(phy_controller* f) } // Signal result back to FSM that called cell selection - f->stack->defer_task(srslte::make_move_task(csel_callback, csel_res.result)); + f->task_sched.defer_task(srslte::make_move_task(csel_callback, csel_res.result)); } void phy_controller::selecting_cell::wait_in_sync::enter(selecting_cell* f, const cell_sel_res& ev) @@ -126,9 +131,14 @@ bool phy_controller::cell_search_completed(cell_search_ret_t cs_ret, phy_cell_t void phy_controller::searching_cell::enter(phy_controller* f, const cell_search_cmd& cmd) { - f->log_h->info("Initiated Cell search\n"); + otherfsmInfo(f, "Initiating Cell search\n"); f->csearch_callbacks.emplace_back(cmd.callback); - f->stack->start_cell_search(); + f->task_sched.enqueue_background_task([f](uint32_t worker_id) { + phy_interface_rrc_lte::phy_cell_t found_cell; + phy_interface_rrc_lte::cell_search_ret_t ret = f->phy->cell_search(&found_cell); + // notify back RRC + f->task_sched.notify_background_task_result([f, found_cell, ret]() { f->cell_search_completed(ret, found_cell); }); + }); } void phy_controller::handle_cell_search_res(searching_cell& s, const cell_srch_res& result) @@ -146,7 +156,7 @@ void phy_controller::handle_cell_search_res(searching_cell& s, const cell_srch_r } // Signal result back to FSM that called cell search - stack->defer_task(srslte::make_move_task(std::move(csearch_callbacks), result)); + task_sched.defer_task(srslte::make_move_task(std::move(csearch_callbacks), result)); } void phy_controller::share_cell_search_res(searching_cell& s, const cell_search_cmd& cmd) diff --git a/srsue/src/stack/rrc/rrc.cc b/srsue/src/stack/rrc/rrc.cc index 2b64f6dc6..e19879c08 100644 --- a/srsue/src/stack/rrc/rrc.cc +++ b/srsue/src/stack/rrc/rrc.cc @@ -116,7 +116,7 @@ void rrc::init(phy_interface_rrc_lte* phy_, args = args_; - phy_ctrl.reset(new phy_controller{phy, stack}); + phy_ctrl.reset(new phy_controller{phy, task_sched}); state = RRC_STATE_IDLE; plmn_is_selected = false; @@ -1368,26 +1368,6 @@ void rrc::parse_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) } } -void rrc::start_phy_cell_search() -{ - task_sched.enqueue_background_task([this](uint32_t worker_id) { - phy_interface_rrc_lte::phy_cell_t found_cell; - phy_interface_rrc_lte::cell_search_ret_t ret = phy->cell_search(&found_cell); - // notify back RRC - task_sched.notify_background_task_result([this, found_cell, ret]() { cell_search_completed(ret, found_cell); }); - }); -} - -void rrc::start_phy_cell_select(const phy_interface_rrc_lte::phy_cell_t* cell) -{ - phy_interface_rrc_lte::phy_cell_t cell_copy = *cell; - task_sched.enqueue_background_task([this, cell_copy](uint32_t worker_id) { - bool ret = phy->cell_select(&cell_copy); - // notify back RRC - task_sched.notify_background_task_result([this, ret]() { cell_select_completed(ret); }); - }); -} - /******************************************************************************* * * diff --git a/srsue/test/upper/rrc_phy_ctrl_test.cc b/srsue/test/upper/rrc_phy_ctrl_test.cc index f1bc80c8d..d4bf5f413 100644 --- a/srsue/test/upper/rrc_phy_ctrl_test.cc +++ b/srsue/test/upper/rrc_phy_ctrl_test.cc @@ -65,9 +65,9 @@ struct cell_select_result_test { int test_phy_ctrl_fsm() { srslte::log_ref test_log{"TEST"}; - stack_test_dummy stack; + srslte::task_scheduler task_sched; phy_dummy_interface phy; - phy_controller phy_ctrl{&phy, &stack}; + phy_controller phy_ctrl{&phy, &task_sched}; cell_search_result_test csearch_tester{&phy_ctrl}; cell_select_result_test csel_tester{&phy_ctrl}; @@ -101,7 +101,7 @@ int test_phy_ctrl_fsm() TESTASSERT(phy_ctrl.current_state_name() != "searching_cell"); // TEST: Check propagation of cell search result to caller - stack.run_tti(); + task_sched.run_pending_tasks(); TESTASSERT(csearch_tester.trigger_called); TESTASSERT(csearch_tester.result.cs_ret.found == cs_ret.found); TESTASSERT(csearch_tester.result.found_cell.pci == found_cell.pci); @@ -128,7 +128,7 @@ int test_phy_ctrl_fsm() TESTASSERT(phy_ctrl.current_state_name() != "selecting_cell"); // TEST: Propagation of cell selection result to caller - stack.run_tti(); + task_sched.run_pending_tasks(); TESTASSERT(csel_tester.result == 1); // TEST: Cell Selection with timeout being reached @@ -141,12 +141,13 @@ int test_phy_ctrl_fsm() for (uint32_t i = 0; i < phy_controller::wait_sync_timeout_ms; ++i) { TESTASSERT(phy_ctrl.current_state_name() == "selecting_cell"); - stack.run_tti(); + task_sched.tic(); + task_sched.run_pending_tasks(); } TESTASSERT(phy_ctrl.current_state_name() != "selecting_cell"); // TEST: Propagation of cell selection result to caller - stack.run_tti(); + task_sched.run_pending_tasks(); TESTASSERT(csel_tester.result == 0); test_log->info("Finished RRC PHY controller test successfully\n");