There are two tasks in the hypothetical situation. Both are the time critical tasks. The first task is a high priority task. This must be handled and completed without failure at every 40us. it only uses 4μs of CPU time.
Second task is time consuming and uses most of the CPU resources, almost 100% if allowed to do so. It has the lowest priority but this must be completed in under 300μs.
How both tasks will schedule in free RTOS technique
FreeRTOS has a very simple scheduler, the highest priority ready task is run.
If tasks tie for priority, and the round-robin scheduling is enabled, they will cycle between themselves every tick.
FreeRTOS doesn’t know your timing requirements, so schedules are STRICTLY based on those priority rules and the task state.
For your first task to run every 40us, you will need something in the system to enable the task at that rate. You COULD make the system tick that fast, but then you will have the tick running every 40us which would use a lot of processor time.
I suppose a big question comes to how fast is your processor, and how long does it take to do a full context switch.
Personally, unless that High Priority task is doing something “special”, I would probably just do its code in an appropriate priority ISR that triggers when it is needed to run. That will minimize the context switching needed.
The low-priority task will get whatever time is left, and it meeting the 300us requirement is up to you to make sure you don’t have things that take more time than that from it. Since you imply that it is the only other thing running, that shouldn’t be a problem.
Suppose that in addition to these two tasks, I have a third task that needs to be completed.
So first task is high priority task, second task is middle priority task and third task is low priority task.
Third task occurs every 2ms If the task is not completed withing 10us the process is suspended until the next 2ms.
Now we have three tasks. A task can be in four states, ready to run, running, blocked and suspended. I want to understand when the state of each task would be change, at what time it will change?
Nothing will automatically “suspend” the task after 10us unless you provide your own hardware timer to generate an interrupt. You could have the task block itself for the rest of the 2ms tick after it does an amount of work that you expect will take that much time.