From 323668c521368e9dc36ae141717227260469361d Mon Sep 17 00:00:00 2001 From: Brent K <129296493+BrentK-ADI@users.noreply.github.com> Date: Thu, 9 May 2024 18:35:38 -0400 Subject: [PATCH] fix(Examples): Fix RF Test RTOS Scheduling Bug (#1011) --- Examples/MAX32655/Bluetooth/RF_Test/main.c | 22 +++++++++++++++------- Examples/MAX32665/Bluetooth/RF_Test/main.c | 22 +++++++++++++++------- Examples/MAX32690/Bluetooth/RF_Test/main.c | 22 +++++++++++++++------- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/Examples/MAX32655/Bluetooth/RF_Test/main.c b/Examples/MAX32655/Bluetooth/RF_Test/main.c index d9861254be..459bfac8ce 100644 --- a/Examples/MAX32655/Bluetooth/RF_Test/main.c +++ b/Examples/MAX32655/Bluetooth/RF_Test/main.c @@ -243,8 +243,8 @@ uint8_t processEscSequence(uint8_t *seq) * * \brief adds latest command to command history buffer * - * \param q pointer to the circular buffer holding command history - * \param cmd pointer to the command string to be added + * \param q pointer to the circular buffer holding command history + * \param cmd pointer to the command string to be added * * \return None. */ @@ -271,9 +271,9 @@ void cmdHistoryAdd(queue_t *q, const uint8_t *cmd) * \fn updateQueuePointer. * * \brief Updates an internal marker pointing to historical command to be printed, based on up/down arrow - * - * \param q pointer to the circular buffer holding command history - * + * + * \param q pointer to the circular buffer holding command history + * * \param upArrow flag used to upated the queuePoniter delimiting which command to print * * \return None. @@ -393,9 +393,9 @@ void prompt(void) * \fn printHint * * \brief Prints the help string of any command matching the current inputbuffer - * + * * \param buff pointer to the inputbuffer - * + * * \return None. */ /*************************************************************************************************/ @@ -694,17 +694,25 @@ void txTestTask(void *pvParameters) snprintf(str, sizeof(str), "%s%s", str, (const char *)getPhyStr(phy)); APP_TRACE_INFO1("%s", str); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); + /* stat test */ if (testConfig.testType == BLE_TX_TEST) { res = LlEnhancedTxTest(testConfig.channel, packetLen, packetType, phy, 0); } else { res = LlEnhancedRxTest(testConfig.channel, phy, 0, 0); } + xTaskResumeAll(); //Restore scheduler + APP_TRACE_INFO2("result = %u %s", res, res == LL_SUCCESS ? "(SUCCESS)" : "(FAIL)"); /* if duration value was given then let the test run that amount of time and end */ if (testConfig.duration_ms) { vTaskDelay(testConfig.duration_ms); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); LlEndTest(NULL); + xTaskResumeAll(); //Restore scheduler xSemaphoreGive(rfTestMutex); } pausePrompt = false; diff --git a/Examples/MAX32665/Bluetooth/RF_Test/main.c b/Examples/MAX32665/Bluetooth/RF_Test/main.c index 22f2e38ca2..1a01be00a7 100644 --- a/Examples/MAX32665/Bluetooth/RF_Test/main.c +++ b/Examples/MAX32665/Bluetooth/RF_Test/main.c @@ -246,8 +246,8 @@ uint8_t processEscSequence(uint8_t *seq) * * \brief adds latest command to command history buffer * - * \param q pointer to the circular buffer holding command history - * \param cmd pointer to the command string to be added + * \param q pointer to the circular buffer holding command history + * \param cmd pointer to the command string to be added * * \return None. */ @@ -274,9 +274,9 @@ void cmdHistoryAdd(queue_t *q, const uint8_t *cmd) * \fn updateQueuePointer. * * \brief Updates an internal marker pointing to historical command to be printed, based on up/down arrow - * - * \param q pointer to the circular buffer holding command history - * + * + * \param q pointer to the circular buffer holding command history + * * \param upArrow flag used to upated the queuePoniter delimiting which command to print * * \return None. @@ -396,9 +396,9 @@ void prompt(void) * \fn printHint * * \brief Prints the help string of any command matching the current inputbuffer - * + * * \param buff pointer to the inputbuffer - * + * * \return None. */ /*************************************************************************************************/ @@ -695,17 +695,25 @@ void txTestTask(void *pvParameters) snprintf(str, sizeof(str), "%s%s", str, (const char *)getPhyStr(phy)); APP_TRACE_INFO1("%s", str); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); + /* stat test */ if (testConfig.testType == BLE_TX_TEST) { res = LlEnhancedTxTest(testConfig.channel, packetLen, packetType, phy, 0); } else { res = LlEnhancedRxTest(testConfig.channel, phy, 0, 0); } + xTaskResumeAll(); //Restore scheduler + APP_TRACE_INFO2("result = %u %s", res, res == LL_SUCCESS ? "(SUCCESS)" : "(FAIL)"); /* if duration value was given then let the test run that amount of time and end */ if (testConfig.duration_ms) { vTaskDelay(testConfig.duration_ms); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); LlEndTest(NULL); + xTaskResumeAll(); //Restore scheduler xSemaphoreGive(rfTestMutex); } pausePrompt = false; diff --git a/Examples/MAX32690/Bluetooth/RF_Test/main.c b/Examples/MAX32690/Bluetooth/RF_Test/main.c index 22f2e38ca2..1a01be00a7 100644 --- a/Examples/MAX32690/Bluetooth/RF_Test/main.c +++ b/Examples/MAX32690/Bluetooth/RF_Test/main.c @@ -246,8 +246,8 @@ uint8_t processEscSequence(uint8_t *seq) * * \brief adds latest command to command history buffer * - * \param q pointer to the circular buffer holding command history - * \param cmd pointer to the command string to be added + * \param q pointer to the circular buffer holding command history + * \param cmd pointer to the command string to be added * * \return None. */ @@ -274,9 +274,9 @@ void cmdHistoryAdd(queue_t *q, const uint8_t *cmd) * \fn updateQueuePointer. * * \brief Updates an internal marker pointing to historical command to be printed, based on up/down arrow - * - * \param q pointer to the circular buffer holding command history - * + * + * \param q pointer to the circular buffer holding command history + * * \param upArrow flag used to upated the queuePoniter delimiting which command to print * * \return None. @@ -396,9 +396,9 @@ void prompt(void) * \fn printHint * * \brief Prints the help string of any command matching the current inputbuffer - * + * * \param buff pointer to the inputbuffer - * + * * \return None. */ /*************************************************************************************************/ @@ -695,17 +695,25 @@ void txTestTask(void *pvParameters) snprintf(str, sizeof(str), "%s%s", str, (const char *)getPhyStr(phy)); APP_TRACE_INFO1("%s", str); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); + /* stat test */ if (testConfig.testType == BLE_TX_TEST) { res = LlEnhancedTxTest(testConfig.channel, packetLen, packetType, phy, 0); } else { res = LlEnhancedRxTest(testConfig.channel, phy, 0, 0); } + xTaskResumeAll(); //Restore scheduler + APP_TRACE_INFO2("result = %u %s", res, res == LL_SUCCESS ? "(SUCCESS)" : "(FAIL)"); /* if duration value was given then let the test run that amount of time and end */ if (testConfig.duration_ms) { vTaskDelay(testConfig.duration_ms); + //Prevent FreeRTOS from context switching until the LL is finished + vTaskSuspendAll(); LlEndTest(NULL); + xTaskResumeAll(); //Restore scheduler xSemaphoreGive(rfTestMutex); } pausePrompt = false;