diff --git a/software/firmware/src/app/app_config.h b/software/firmware/src/app/app_config.h index c1e2fb9d..5a234440 100644 --- a/software/firmware/src/app/app_config.h +++ b/software/firmware/src/app/app_config.h @@ -40,6 +40,8 @@ #define BATTERY_CHECK_INTERVAL_S 300 +#define BLE_INIT_TIMEOUT_MS 1000 + // Battery Configuration ----------------------------------------------------------------------------------------------- diff --git a/software/firmware/src/tasks/app_task_maintenance.c b/software/firmware/src/tasks/app_task_maintenance.c index 0b009508..7a575366 100644 --- a/software/firmware/src/tasks/app_task_maintenance.c +++ b/software/firmware/src/tasks/app_task_maintenance.c @@ -69,8 +69,10 @@ void AppTaskMaintenance(void *uid) storage_flush_and_shutdown(); // Wait until the BLE stack has been fully initialized - while (!bluetooth_is_initialized()) - vTaskDelay(1); + for (int i = 0; !bluetooth_is_initialized() && (i < BLE_INIT_TIMEOUT_MS); i += 100) + vTaskDelay(pdMS_TO_TICKS(100)); + if (!bluetooth_is_initialized()) + system_reset(); // Clear the BLE address whitelist bluetooth_clear_whitelist(); diff --git a/software/firmware/src/tasks/app_task_ranging.c b/software/firmware/src/tasks/app_task_ranging.c index e208fa25..0612cbc6 100644 --- a/software/firmware/src/tasks/app_task_ranging.c +++ b/software/firmware/src/tasks/app_task_ranging.c @@ -81,7 +81,7 @@ static void handle_notification(app_notification_t notification) // Reset the devices-found flag and verify the app configuration while (bluetooth_is_scanning()) - am_hal_delay_us(1); + vTaskDelay(pdMS_TO_TICKS(1)); devices_found = false; verify_app_configuration(); } @@ -208,8 +208,10 @@ void AppTaskRanging(void *uid) // Wait until the BLE stack has been fully initialized devices_found = false; - while (!bluetooth_is_initialized()) - vTaskDelay(1); + for (int i = 0; !bluetooth_is_initialized() && (i < BLE_INIT_TIMEOUT_MS); i += 100) + vTaskDelay(pdMS_TO_TICKS(100)); + if (!bluetooth_is_initialized()) + system_reset(); // Update the BLE address whitelist bluetooth_clear_whitelist(); diff --git a/software/firmware/tests/tasks/test_ble_and_ranging.c b/software/firmware/tests/tasks/test_ble_and_ranging.c index f2df5bd8..bf3a4133 100644 --- a/software/firmware/tests/tasks/test_ble_and_ranging.c +++ b/software/firmware/tests/tasks/test_ble_and_ranging.c @@ -39,7 +39,7 @@ int main(void) // Create tasks with the following priority order: // IdleTask < AppTask < BLETask < RangingTask configASSERT1(xTaskCreate(RangingTask, "RangingTask", 512, uid, 5, &ranging_task_handle)); - configASSERT1(xTaskCreate(BLETask, "BLETask", 512, NULL, 3, &ble_task_handle)); + configASSERT1(xTaskCreate(BLETask, "BLETask", 1024, NULL, 3, &ble_task_handle)); configASSERT1(xTaskCreate(AppTaskRanging, "AppTask", 512, uid, 2, &app_task_handle)); // Start the task scheduler