Skip to content

Commit

Permalink
Allow BLE chip to fully initialize before doing anything
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Nov 14, 2023
1 parent c72ea83 commit b860229
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions software/firmware/src/app/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

#define BATTERY_CHECK_INTERVAL_S 300

#define BLE_INIT_TIMEOUT_MS 1000


// Battery Configuration -----------------------------------------------------------------------------------------------

Expand Down
6 changes: 4 additions & 2 deletions software/firmware/src/tasks/app_task_maintenance.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions software/firmware/src/tasks/app_task_ranging.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/tests/tasks/test_ble_and_ranging.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b860229

Please sign in to comment.