ESP8266 Developer Zone The Official ESP8266 Forum 2016-04-28T22:32:51+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=2091 2016-04-28T22:32:51+08:00 2016-04-28T22:32:51+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2091&p=6660#p6660 <![CDATA[Re: [Solved] RTOS SDK - Binary Semaphore Not Working]]>
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.

Statistics: Posted by jhinkle — Thu Apr 28, 2016 10:32 pm


]]>
2016-04-26T10:03:40+08:00 2016-04-26T10:03:40+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2091&p=6606#p6606 <![CDATA[[Solved] RTOS SDK - Binary Semaphore Not Working]]>
I needed a mutex to control flow between a task and an ISR.

Code:

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:

   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

Statistics: Posted by jhinkle — Tue Apr 26, 2016 10:03 am


]]>