FM: Notify ON to upper layer, only If TX & RX threads are actually running
A case, where there is a delay(eg 4ms) to start tx worker thread
by OS or platform. FM ON is immediately notified to upper layer after
creating threads, Upper layer immediately sends FM commands. which won't
be sent to transport layer, as tx thread is not yet running. which
immediately leads FM on failure, Hence notifying ON to upper layer,
only If tx & rx threads are actually running.
CRs-fixed: 2063882
Change-Id: I1817e9f31906090bcf180db4f2df5e711389b2f2
diff --git a/fm_hci/fm_hci.cpp b/fm_hci/fm_hci.cpp
index 5b4475c..f10312b 100644
--- a/fm_hci/fm_hci.cpp
+++ b/fm_hci/fm_hci.cpp
@@ -43,6 +43,7 @@
#include <thread>
#include <utils/Log.h>
+#include <unistd.h>
#include <vendor/qti/hardware/fm/1.0/IFmHci.h>
#include <vendor/qti/hardware/fm/1.0/IFmHciCallbacks.h>
@@ -263,6 +264,7 @@
static void hci_tx_thread()
{
ALOGI("%s: ##### starting hci_tx_thread Worker thread!!! #####", __func__);
+ hci.is_tx_thread_running = true;
while (hci.state != FM_RADIO_DISABLING && hci.state != FM_RADIO_DISABLED) {
//wait for tx cmd
@@ -272,6 +274,7 @@
dequeue_fm_tx_cmd();
}
+ hci.is_tx_thread_running =false;
ALOGI("%s: ##### Exiting hci_tx_thread Worker thread!!! #####", __func__);
}
@@ -291,6 +294,7 @@
{
ALOGI("%s: ##### starting hci_rx_thread Worker thread!!! #####", __func__);
+ hci.is_rx_thread_running = true;
while (hci.state != FM_RADIO_DISABLING && hci.state != FM_RADIO_DISABLED) {
//wait for rx event
@@ -299,6 +303,7 @@
dequeue_fm_rx_event();
}
+ hci.is_rx_thread_running = false;
ALOGI("%s: ##### Exiting hci_rx_thread Worker thread!!! #####", __func__);
}
@@ -612,6 +617,8 @@
hci.command_credits = 1;
hci.is_tx_processing = false;
hci.is_rx_processing = false;
+ hci.is_tx_thread_running = false;
+ hci.is_rx_thread_running = false;
hci.state = FM_RADIO_DISABLED;
hci_hal->hci = &hci;
@@ -626,6 +633,13 @@
}
if (hci.state == FM_RADIO_ENABLED) {
+ while (hci.is_tx_thread_running == false
+ || hci.is_rx_thread_running == false)
+ {
+ /* checking tx & rx thread running status after every
+ 5ms before notifying on to upper layer */
+ usleep(5000);
+ }
ALOGD("--%s success", __func__);
ret = FM_HC_STATUS_SUCCESS;
} else {
diff --git a/fm_hci/fm_hci.h b/fm_hci/fm_hci.h
index 92c5942..5c48827 100644
--- a/fm_hci/fm_hci.h
+++ b/fm_hci/fm_hci.h
@@ -45,6 +45,9 @@
bool is_tx_processing;
bool is_rx_processing;
+ bool is_tx_thread_running;
+ bool is_rx_thread_running;
+
std::condition_variable tx_cond;
std::mutex tx_cond_mtx;