[Solved] RTOS SDK - Binary Semaphore Not Working

jhinkle
Posts: 32
Joined: Tue Apr 19, 2016 12:09 am

[Solved] RTOS SDK - Binary Semaphore Not Working

Postby jhinkle » Tue Apr 26, 2016 10:03 am

I've used the Counting Semaphore without issue.

I needed a mutex to control flow between a task and an ISR.

Code: Select all

xSemaphoreHandle SpiPackageComplete = 0;

   vSemaphoreCreateBinary(SpiPackageComplete);  // start of task
   ......
   
   r = xSemaphoreTake(SpiPackageComplete, 5);   // inside task's while(1)
   
Inside an ISR ...
   xSemaphoreGiveFromISR(SpiPackageComplete, &HigherPriorityTaskWoken);   // no task switch based on return



The Complete spi cycle takes just less an 700usec to complete. It takes 10 interrupt cycles to complete the spi package transmission.

The code as shown --- the return from the take should occur within the same tic count or the next and the interrupt counter should be 10 indicating a complete package. What occurs is that the task is NOT blocked by the TAKE and immediately returns (my interrupt counter is at 2 indicating 2 64 byte packages have been sent --- about 150usec.

I change the type of Semaphore binary counting of depth 1 --- and it works as expected.

Code: Select all

   SpiPackageComplete = xSemaphoreCreateCounting(1, 0);



I've instrumented this thing multiple ways and every thing indicates the "Binary Semaphore" is NOT working properly -- it will NOT block until a GIVE occurs and return immediately.

Can you verify my findings?

Thanks

jhinkle
Posts: 32
Joined: Tue Apr 19, 2016 12:09 am

Re: [Solved] RTOS SDK - Binary Semaphore Not Working

Postby jhinkle » Thu Apr 28, 2016 10:32 pm

Solved.

Issue was ME!!!

Espressif uses the OLD version of this function vSemaphoreCreateBinary which actually creates the semaphore in a "given" or set state.

I had checked the FreeRTOS documentation and referenced the function xSemaphoreCreateBinary which is the preferred function (v vs x at start of name). The x version creates it in an empty state.

I got to be more carefully with the fine print.

Who is online

Users browsing this forum: No registered users and 237 guests