Hi,
I got the example github.com/.../nrf52-ble-multi-link-multi-role and I have added FreeRTOS to the example refer to ble_app_hrs_freertos in SDK v15.2.0 with S140 v6.1.0.
We want to do a game project. One 52840 works in mutilrole(central_and_peripheral) and another one just work in peripheral. APP,peripheral and mutilrole device would exchane data each other and also the devie would have a lot of data to cacaulate using FPU.
static void BLEAppTask(void * pvParameter)
{
if (pdPASS != xTimerStart(m_battery_timer, OSTIMER_WAIT_FOR_QUEUE))
{
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
while(1)
{
process_ble_commands();
send_device_status();
flash_operate(fs_event_num);
taskYIELD();
}
}
static void ble_task(void *arg)
{
advertising_start();
scan_start(); // Start scanning for peripherals and initiate connection to devices which advertise.
}
static void app_task_demo(void *arg)
{
if (pdPASS != xTimerStart(m_master_receive_timer, OSTIMER_WAIT_FOR_QUEUE))
{
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
uart_printf("app_task_demo start.\n");
vTaskSuspend(NULL);
}
static void run_task(void)
{
nrf_sdh_freertos_init(ble_task, NULL); // Create a FreeRTOS task for the BLE stack.
if (pdPASS != xTaskCreate(BLEAppTask, "BLEAppTask", 256, NULL, 2, &m_app_thread))
{
uart_printf("Failed to create BLEAppTask.\n");
}
else
{
uart_printf("BLEAppTask FreeRTOS created.\n");
}
if (pdPASS != xTaskCreate(app_task_demo, "TaskDemo", 256, NULL, 1, &m_demo_thread))
{
uart_printf("Failed to create TaskDemo task.\n");
}
else
{
uart_printf("TaskDemo FreeRTOS created.\n");
}
}
int main(void)
{
.....
.....
run_task();
vTaskStartScheduler();
uart_printf("MutilRole application start %s\n",FIRM_WARE_REVERSION);
for (;;)
{
APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);
}
}
void send_device_status(void)
{
uint8_t dev_info[10];
if(DeviceStaChanged)
{
DeviceStaChanged = false;
uart_printf("send_device_status\n");
dev_info[0] = APP_PACKET_TAG;
dev_info[1] = 1;
dev_info[2] = MODULE_EVENT_TYPE;
dev_info[3] = 0;
dev_info[4] = 4;
dev_info[5] = 7;
dev_info[6] = 0;
dev_info[7] = 1;
if(m_service_discovery_conn_handle!= BLE_CONN_HANDLE_INVALID)
dev_info[8] = 1; // connected status
else
dev_info[8] = 0; // disconnected status
dev_info[9] = Crc8(dev_info,9);
BLE_peripheral_send(dev_info,10);
}
}
In the BLEAppTask, process_ble_commands() is used to send data to APP or peripheral and it's OK now.
send_device_status() is used to send the link status to APP between center and peripheral . But I found that it would send data to APP even though it has run into send_device_status function and have printf send_device_status log. I'm also sure BLE_peripheral_send function is good.
It seems that CPU has been rob by other task so that it couldn't send data to APP. I set the priority of BLEAppTask to 2 and it is the same as nrf_sdh_freertos_init(ble_task, NULL);
If I set the priority to 1 for the BLEAppTask ,the BLEAppTask couldn't run well. For example, mutilrole could connect to peripheral but it wouldn't advertise after center connect to peripheral .
So could you give me some advice about it? Thanks.
Another question, I also want to do some data caculation in the app_task_demo, but I have not done caculation now. The task creation is OK.
I hope the task wouldn't affect BLE data transmission.
I have start a timer in the app_task_demo task and it would invert a LED on the development kit. But the task has not run becasuse the LED could not blink.
Best regards,
Bruse