Meaning FreeRTOS recursive semaphores

Recursive semaphores properties: the same task can be retrieved many times, and requires the same number of times in order to be released for additional tasks.

1. Create a recursive semaphores, acquisition, release:

xxMux = xSemaphoreCreateRecursiveMutex();

xSemaphoreTakeRecursive(xxMux,osWaitForever);

xSemaphoreGiveRecursive(xxMux);

2. The following function e.g.

void fun1(void)

{

  xSemaphoreTakeRecursive(xxMux,osWaitForever);

  //...code

  xSemaphoreGiveRecursive(xxMux);

}

void fun2(void)

{

  //...code

}

void fun(void)

{

  fun1();

  delay_ms(1000);

  fun2();

}

Analysis: fun1 () is a public function , may be invoked by any other task, fun2 just fun calls. If after fun1 () executed, entirely possible switch to other tasks performed fun2 () can not delay immediately after; to read as follows

void fun(void)

{

  xSemaphoreTakeRecursive(xxMux,osWaitForever); //......1

  fun1();

  delay_ms(1000);

  fun2();

  xSemaphoreGiveRecursive(xxMux);//........2

}

Analysis: If the above ordinary mutex changed at 1, then fun1 executed, switch to other tasks, other tasks will be executed fun1, but fun2 requiring immediate implementation in accordance with the results of fun1. At this point it is necessary to ensure fun1 not perform other tasks.

Summary: Recursive semaphore is to ensure that at the middle of the common function, the code segment is continuously performed to ensure that public function is not performing other tasks, thus the amount of the recursive signal is present.

Guess you like

Origin www.cnblogs.com/ycpkbql/p/11770402.html