This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Block preemption :

Hi,

There is a main task "Task1" created from main

Task1 has sub tasks

Hardware task : Hwtask  ( created with Hwi_create() API)

Task threads : Below tasks created with Task_create() API

1) PDItask with priority 7

2) SPItask with priority 6

3) LEDtask with priority 5

 

1)  When SPItask is running we need to block all other tasks ( Hwtask   and PDItask ) from preemptive so that SPI read and write data goes well.

Can any one suggest a API to block other task?

2) One observation PDItask is not with Task_Sleep (), then how is SPItask getting time to schedule the execution?

3) When SPItask is not with Task_Sleep(), execution stays with in while (1) of SPItask, LEDtask is not scheduled why is this behaviour?

4) If SPItask is given with a Task_Sleep () of 1ms, then if LEDtask is between exection of a critical section where it has disabled all other task

what is the behaviour if Task_sleep has exceded 1ms of time in SPItask, Will the Disable all task work fine in this case? will not SPItask preempt ?

Regards,

Bindu

  • Bindu,

    you may want to re-evaluate your task priority structure here. SYS/BIOS is a preemptive kernel, which means that the highest priority will always run if its ready to run. If you want some sort of time slicing option, see the SYS/BIOS user's guide, section 3.5.6 "Task Yielding for Time-Slice Scheduling".

    Bindu Ganesh said:
    2) One observation PDItask is not with Task_Sleep (), then how is SPItask getting time to schedule the execution?

    PDItask has the highest priority. Since it is always ready to run, it will execute until it gets blocked in some way (e.g. Task_sleep() or Semaphore_pend(), etc...)

    Bindu Ganesh said:
    3) When SPItask is not with Task_Sleep(), execution stays with in while (1) of SPItask, LEDtask is not scheduled why is this b

    The same thing is happening here. As long as SPItask is ready to run, it will execute. This will cause your LEDtask to be starved if SPItask doesn't go into a blocked state.

    Bindu Ganesh said:

    4) If SPItask is given with a Task_Sleep () of 1ms, then if LEDtask is between exection of a critical section where it has disabled all other task

    what is the behaviour if Task_sleep has exceded 1ms of time in SPItask, Will the Disable all task work fine in this case? will not SPItask preempt ?

    In any case, your critical code section should be as short as possible. You may want to look into using Hwi_disable()/Hwi_restore(), Task_disable()/Task_restore(), or Gate_enter()/Gate_leave() locks to accomplish this. I'm not sure what the nature of your crictical code section is, so you'd want to refer to the SYS/BIOS user's guide for that.

    You may want to look designing your task to stay blocked on a Semaphore_pend() until your Hwi calls a Semaphore_post(). For example, you SPItask can stay blocked (on a Semaphore_pend()) until a SPI Hwi calls Semaphore_post() when it has data to process. If you SPI data is time critical, could look into handling that portion within the SPI Hwi itself. Perhaps a DMA-based solution might also work for you.