suspending and resuming NimBLE Task

aygh4266
Posts: 24
Joined: Mon Mar 04, 2024 10:33 am

suspending and resuming NimBLE Task

Postby aygh4266 » Fri Nov 15, 2024 12:40 pm

Hello everyone,

I want to activate bluetooth only for a while and when it is only necessary. Should it be better to suspend and resume the NimBLE freertos task based on :

Code: Select all

void vAFunction( void )
{
    TaskHandle_t xHandle;

    // Create a task, storing the handle.
    xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );

    // ...

    // Use the handle to suspend the created task.
    vTaskSuspend( xHandle );

    // ...

    // The created task will not run during this period, unless
    // another task calls vTaskResume( xHandle ).

    //...

    // Resume the suspended task ourselves.
    vTaskResume( xHandle );

    // The created task will once again get microcontroller processing
    // time in accordance with its priority within the system.
}
or to initialize and deinitialize the nimble port based on:

Code: Select all

void start_bt_task() {
    nimble_port_init();
    nimble_port_freertos_init(your_host_task_fn);  
}


void stop_bt_task() {
    nimble_port_stop(); 
    nimble_port_deinit();  
    nimble_port_freertos_deinit();  
}


MicroController
Posts: 1724
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: suspending and resuming NimBLE Task

Postby MicroController » Fri Nov 15, 2024 1:05 pm

The latter.
A task should never suspend any task other than itself.

Who is online

Users browsing this forum: No registered users and 152 guests