0

I have a situation here in my code where all tasks are running with same priority based on round robin (with fixed time slice of 50ms) scheduling algorithm. Now I want to run one particular task say Task A, exactly within a time period of 10ms to update some communication db. Since,current scheduling is based on round robin with fixed time slice of 50ms due to that the Task A is not able to get called exactly in 10ms. I am not getting any solution to cope up with the current problem. Please do provide your valuable suggestion & advice.

Thanks in advance, Vijay Khaitan

Clifford
  • 88,407
  • 13
  • 85
  • 165

1 Answers1

0

Not exactly sure what you are asking here. If you do not want Task A to run longer than 10ms, and you know that you will return from your communication functions in less than that, you can take a time reading at the beginning of Task A, and call osThreadYield() from Task A after you hit 10ms (busy loop).

If you are somewhere in Task B, and need to call Task A in exactly 10ms, it becomes a bit more complicated, since you don't know what thread can preempt your Task B at that time. What you can try, is in Task B, keep a handle to Task A. Then when you are ready to wait 10ms, do the following:

 osThreadId id;
 id = osThreadGetId ();  // id for the currently running thread
 osThreadSetPriority(id, osPriorityRealtime); // Make sure we get back here quickly
 osWait(10);             // Wait 10ms
 osThreadSetPriority(id, osPriorityNormal);   // Go back to normal
 // If you need to create Task A, do so here, otherwise you can
 // use osSignalSet here and osSignalWait in Task A

You can also call directly create Task A, set its priority to osPriorityRealtime, yield from Task B, and have the first method in Task A be osWait(10). As soon as you return, set its priority back to normal.

skobovm
  • 186
  • 1
  • 6