Freertos Semaphore creation

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, i am using atmel studio 6 with Freertos v7 for my custom board which contains AT32uc3a0512. In my project i want synchronization between tasks for that i should block a task by taking unavailable binary semaphore then isr should release that same semaphore this is common for this concept.

I have doubt in creating binary semaphore with unavailable state in freertos, is this possible or it always created with available state.

volatile xSemaphoreHandle sem_PDCA = NULL;
vSemaphoreCreateBinary(sem_PDCA);

Above crates available state of semaphore because it did not block the task after starting task it continues the execution, please anyone tell me hoe to create empty state of semaphore.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Semaphores are created this way, if you want it to instantly block, then just create it this way:

xSemaphoreHandle sem_PDCA = NULL; 
vSemaphoreCreateBinary(sem_PDCA); 
xSemaphoreTake(sem_PDCA, 0); //This takes the default given semaphore

By the way, there is no need to make it volatile. If you use it from an interrupt, then use the

xSemaphoreGiveFromISR()

function.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i created semaphore as your instruction but it does not wait to get semaphore because waiting time is 0 and if it is maxdelay same thing happening and its like previous output state.
As well i have doubt in while creating a binary semaphore in freertos is it available or not, if it is available then how to create a empty semaphore?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Take a look at the semphr.h (see screenshot)

Semaphore creation instantly makes a xSemaphoreGive(), so what I said should be correct.

By the way, I actually use

xSemaphoreHandle sem_PDCA = NULL; 
vSemaphoreCreateBinary(sem_PDCA); 
xSemaphoreTake(sem_PDCA, portMAX_DELAY); //This takes the default given semaphore 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ya i got a point, initial itself it releases semaphore. thank you dude it helped me too.