This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to switch between task by receving data on BLE using FREERTOS?

Hi Everyone,

I have two task in which i am receving data from bluetooth and if i receive a particular hex value , i want a task(which is Toggling LED State) to run on the basis of the received data.

If there was no data received , then both task should run as per they are scheduled.

If i give a task delay of 2 minutes , the task switches from BLE to LED but , it runs continously there and BLE task also runs alongwith it. (NOT WHAT I WANT)

However if i give a task delay 1 minute , The task switches from BLE to LED and does not run continously.(EXPECTING SAME WITH 2 MINUTES OF TASK DELAY)

What i need is , its something like Immediate Task Switching. 

I have been trying to use xTaskAbortDelay function , the task does run from the input from bluetooth data, however , after that the LED task is running continously.

Does xTaskAbortDelay creating some problem here? Should I use something else to achieve the same functionality?

I am using SDK 15.0 With Segger Embedded Studio

Thanks 

Rajat

  • Hi Rajat,

    I am little unsure if I understood your question correctly. 

    If there was no data received , then both task should run as per they are scheduled.

    What do you mean here? 

    vTaskAbortDelay function will be a task from blocked to ready state, and this does not mean that your task will run immediately. This means that when other high priority tasks are blocked/yielded, then the task that now entered ready state (due to vTaskAbortDelay) will run.

     

     

  • I am trying to say, That on the basis of input from BLE ,LED task should run immediately by blocking all other tasks. 

    But as per your explaination, this is not what the function xTaskAbortDelay does. So What is the workaround for this?

  • Rajat said:
    I am trying to say, That on the basis of input from BLE ,LED task should run immediately by blocking all other tasks.

    one way could be to make LED task higher priority than others and suspend it when created. When BLE activity happens, resume the LED task, and since this LED task is higher priority, it will run as soon as you call the portYield function in the BLE task.

  • We have actually dropped the idea of this, because there are other important tasks that need to be run. We did this: We changed the time according to the BLE rxed data. If the LED task was previously blinking after 5 minutes then we made one global variable in which BLE rxed data is stored. If a particular hex value is recived from BLE then we Change the parameter of vTaskDelay() and it is running fine :). 

    Not very professonal, but it works Smiley

Related