Skip to content

Commit

Permalink
BLE+Ranging test application
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Nov 11, 2023
1 parent d0c953a commit 2298770
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion software/firmware/src/tasks/app_task_ranging.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void AppTaskRanging(void *uid)
// Store the UID and application task handle
device_uid_short = ((uint8_t*)uid)[0];
app_task_handle = xTaskGetCurrentTaskHandle();
uint32_t notification_bits = APP_NOTIFY_NETWORK_LOST;
uint32_t notification_bits = 0;

// Initialize the BLE scanning window timer
am_hal_timer_config_t scanning_timer_config;
Expand Down Expand Up @@ -211,6 +211,7 @@ void AppTaskRanging(void *uid)
for (uint8_t i = 0; i < current_experiment.num_devices; ++i)
bluetooth_add_device_to_whitelist(current_experiment.uids[i]);
bluetooth_set_current_ranging_role(ROLE_IDLE);
verify_app_configuration();

// Loop forever, sleeping until an application notification is received
while (true)
Expand Down
48 changes: 48 additions & 0 deletions software/firmware/tests/tasks/test_ble_and_ranging.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "app_tasks.h"
#include "battery.h"
#include "bluetooth.h"
#include "led.h"
#include "logging.h"
#include "ranging.h"
#include "rtc.h"
#include "system.h"

static TaskHandle_t app_task_handle, ble_task_handle, ranging_task_handle;

void storage_retrieve_experiment_details(experiment_details_t *details) { memset(details, 0, sizeof(*details)); };
void storage_begin_reading(void) {}
void storage_end_reading(void) {}
uint32_t storage_retrieve_data_length(void) { return 0; }
uint32_t storage_retrieve_next_data_chunk(uint8_t *buffer) { return 0; }

int main(void)
{
// Set up system hardware and fetch the device UID
setup_hardware();
static uint8_t uid[EUI_LEN];
system_read_UID(uid, sizeof(uid));

// Initialize all required peripherals and enable interrupts
battery_monitor_init();
bluetooth_init(uid);
leds_init();
rtc_init();
system_enable_interrupts(true);
print("Initialized BLE with address %02X:%02X:%02X:%02X:%02X:%02X\n", uid[0], uid[1], uid[2], uid[3], uid[4], uid[5]);

// Initialize the ranging radio and put it into deep sleep
ranging_radio_init(uid);
ranging_radio_sleep(true);
am_hal_delay_us(1000000);
system_enable_interrupts(false);

// 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(AppTaskRanging, "AppTask", 512, uid, 2, &app_task_handle));

// Start the task scheduler
vTaskStartScheduler();
return 0;
}

0 comments on commit 2298770

Please sign in to comment.