0
votes

So I have a half duplex bus driver, where I send something and then always have to wait a lot of time to get a response. During this wait time I want the processor to do something valuable, so I'm thinking about using FreeRTOS and vTaskDelay() or something.

One way to do it would off be splitting the driver up in some send/receive part. After sending, it returns to the caller. The caller then suspends, and does the reception part after a certain period of time.

But, the level of abstraction would be finer if it continues to be one task from the user point of view, as today. Therefore I was thinking, is it possible for a function within a task to suspend the task itself? Like

 void someTask()
 {
     while(true){
       someFunction(&someTask(), arg 1, arg 2,...);
       otherStuff(); 
 }


 }

 void someFunction(*someSortOfReferenceToWhateverTaskWhoCalled, arg1, arg2 ...)
 {
    if(something)  
    {

       /*Use the pointer or whatever to suspend the task that called this                      function*/
    }

 }
1

1 Answers

0
votes

Have a look at the FreeRTOS API reference for vTaskSuspend, http://www.freertos.org/a00130.html

However I am not sure you are going about controlling the flow of the program in the correct way. Tasks can be suspended on queues, events, delays etc.

For example in serial comms, you might have a task that feeds data into a queue (but suspends if it is full) and an interrupt that takes data out of the queue and transmits the data, or an interrupt putting data in a queue, or sending an event to a task to say there is data ready for it to process, the task can then wake up and process the data or take it out of the queue.

One thing I think is important though (in my opinion) is to only have one suspend point in any task. This is not a strict rule, but will make your life a lot easier in most situations.

There a numerous other task control mechanisms that are common to most RTOS's.

Have a good look around the FreeRTOS website and play with a few demo's. There is also plenty of generic RTOS tutorials on the web. It it worth learning how use the basic features of most RTOS's. It is actually not that complicated.