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.

Semaphores post/pend



I'm using F28235 processor and I believe this question does not matter what processor though. 

If I setup, let say 3 hardware devices, that use the same SPI port (with different CS) and use semaphore to block and unblock the individual tasks. Therefore, I created a SEM_SPI that calls Semaphore_pend(SEM_SPI, BIOS_WAIT_FOREVER); in each task and call the task randomly. From my understand,  if the count equal 1 then if two or more tasks posting the semaphore only one will run and the others will be put on the stack to execute in order once the other task(s) are done - right or am I missing something? Whether right or wrong is there a good doc to refer to get a good understanding of best practices.

 Rob

  • Have you read the Semaphores chapter of the SYS/BIOS User's Guide? Note that in the intro to the chapter there's a link to a video too.

    It sounds like you have the right idea though. If the count is 1, only one of those functions will be able to unblock, decreasing the count to 0. When the semaphore is posted again, the tasks will execute in the order they were queued up (although there is a priority Semaphore mode to adjust this if needed).

    Whitney

  • I have tested it and if the priority is the same then only one get call when the post occurs. If I set the priority different then it seem to then call both one then the other. Does that sound right? I did not see the video and I did look at the guide and it was not totally clear. what do you mean by priority mode. I really just need the three to be called and then loop back around to the first - serial mode thru the queue. If I post the semaphore three time in a row does that get them all on the queue? I will go watch the video

  • By priority mode, I was referring to the mode parameter options Semaphore_Mode_COUNTING_PRIORITY and Semaphore_Mode_BINARY_PRIORITY. They're described in the User Guide. There's also this API reference documentation although I'm not sure it provides much more detail.

    What mode are you using? BINARY? BINARY_PRIORITY?

    Assuming BINARY, my understanding is that if you call pend in all 3 of the tasks, they will be unblocked in the same order they called pend (think FIFO). So assuming all 3 of them are in the queue, after 3 calls to post, they all should have had a chance to run.

    Whitney

  • hi Whitney, yes i'm using binary fifo. so if I understand u correctly. put a pend and post in each servicing task and maybe a Task_sleep (x) (after the post). This will cause the task to be put on and of the queue as they were put on - does this sound right? 

    BTW: thanks some much - the doc is not very clear and the video does kinda of imply it.

  • one more thing, does the task priority beyond the order in which they are first called matter for the semapore?

  • so if I understand u correctly. put a pend and post in each servicing task and maybe a Task_sleep (x) (after the post). This will cause the task to be put on and of the queue as they were put on - does this sound right?

    Yes, that sounds good.

    does the task priority beyond the order in which they are first called matter for the semapore?

    Like you pointed out, the priority could affect the order in which the Tasks execute at start up or after some non-Semaphore-related context switch and therefore affect the order in which calls to the pend function are reached, but the Semaphore functions themselves will not take priority into consideration.

    Whitney