+static void prvCheckRecursiveSemaphoreFunction( SemaphoreHandle_t xSemaphore )\r
+{\r
+const BaseType_t xLoops = 5;\r
+BaseType_t x, xReturned;\r
+\r
+ /* A very basic test that the recursive semaphore behaved like a recursive\r
+ semaphore. First the semaphore should not be able to be given, as it has not\r
+ yet been taken. */\r
+ xReturned = xSemaphoreGiveRecursive( xSemaphore );\r
+\r
+ if( xReturned != pdFAIL )\r
+ {\r
+ xErrorOccurred = pdTRUE;\r
+ }\r
+\r
+ /* Now it should be possible to take the mutex a number of times. */\r
+ for( x = 0; x < xLoops; x++ )\r
+ {\r
+ xReturned = xSemaphoreTakeRecursive( xSemaphore, staticDONT_BLOCK );\r
+\r
+ if( xReturned != pdPASS )\r
+ {\r
+ xErrorOccurred = pdTRUE;\r
+ }\r
+ }\r
+\r
+ /* Should be possible to give the semaphore the same number of times as it\r
+ was given in the loop above. */\r
+ for( x = 0; x < xLoops; x++ )\r
+ {\r
+ xReturned = xSemaphoreGiveRecursive( xSemaphore );\r
+\r
+ if( xReturned != pdPASS )\r
+ {\r
+ xErrorOccurred = pdTRUE;\r
+ }\r
+ }\r
+\r
+ /* No more gives should be possible though. */\r
+ xReturned = xSemaphoreGiveRecursive( xSemaphore );\r
+\r
+ if( xReturned != pdFAIL )\r
+ {\r
+ xErrorOccurred = pdTRUE;\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvCreateAndDeleteStaticallyAllocatedCountingSemaphores( void )\r
+{\r
+SemaphoreHandle_t xSemaphore;\r
+const UBaseType_t uxMaxCount = ( UBaseType_t ) 10;\r
+\r
+/* StaticSemaphore_t is a publicly accessible structure that has the same size\r
+and alignment requirements as the real semaphore structure. It is provided as a\r
+mechanism for applications to know the size of the semaphore (which is dependent\r
+on the architecture and configuration file settings) without breaking the strict\r
+data hiding policy by exposing the real semaphore internals. This\r
+StaticSemaphore_t variable is passed into the xSemaphoreCreateCountingStatic()\r
+function calls within this function. NOTE: In most usage scenarios now it is\r
+faster and more memory efficient to use a direct to task notification instead of\r
+a counting semaphore. http://www.freertos.org/RTOS-task-notifications.html */\r
+static StaticSemaphore_t xSemaphoreBuffer; /* Static so it doesn't use too much stack space. */\r
+\r
+ /* Create the semaphore. xSemaphoreCreateCountingStatic() has one more\r
+ parameter than the usual xSemaphoreCreateCounting() function. The paraemter\r
+ is a pointer to the pre-allocated StaticSemaphore_t structure, which will\r
+ hold information on the semaphore in an anonymous way. If the pointer is\r
+ passed as NULL then the structure will be allocated dynamically, just as\r
+ when xSemaphoreCreateCounting() is called. */\r
+ xSemaphore = xSemaphoreCreateCountingStatic( uxMaxCount, 0, &xSemaphoreBuffer );\r
+\r
+ /* The semaphore handle should equal the static semaphore structure passed\r
+ into the xSemaphoreCreateBinaryStatic() function. */\r
+ configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );\r
+\r
+ /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */\r
+ prvCheckSemaphoreFunction( xSemaphore, uxMaxCount );\r
+\r
+ /* Delete the semaphore again so the buffers can be reused. */\r
+ vSemaphoreDelete( xSemaphore );\r
+\r
+\r
+ /* The semaphore created above had a statically allocated semaphore\r
+ structure. Repeat the above using NULL as the third\r
+ xSemaphoreCreateCountingStatic() parameter so the semaphore structure is\r
+ instead allocated dynamically. */\r
+ xSemaphore = xSemaphoreCreateCountingStatic( uxMaxCount, 0, NULL );\r
+\r
+ /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */\r
+ prvCheckSemaphoreFunction( xSemaphore, uxMaxCount );\r
+\r
+ /* Delete the semaphore again so the buffers can be reused. */\r
+ vSemaphoreDelete( xSemaphore );\r
+\r
+ /* Ensure lower priority tasks get CPU time. */\r
+ vTaskDelay( prvGetNextDelayTime() );\r
+\r
+ /* Just to show the check task that this task is still executing. */\r
+ uxCycleCounter++;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void )\r
+{\r
+SemaphoreHandle_t xSemaphore;\r
+\r
+/* StaticSemaphore_t is a publicly accessible structure that has the same size\r
+and alignment requirements as the real semaphore structure. It is provided as a\r
+mechanism for applications to know the size of the semaphore (which is dependent\r
+on the architecture and configuration file settings) without breaking the strict\r
+data hiding policy by exposing the real semaphore internals. This\r
+StaticSemaphore_t variable is passed into the\r
+xSemaphoreCreateRecursiveMutexStatic() function calls within this function. */\r
+static StaticSemaphore_t xSemaphoreBuffer; /* Static so it doesn't use too much stack space. */\r
+\r
+ /* Create the semaphore. xSemaphoreCreateRecursiveMutexStatic() has one\r
+ more parameter than the usual xSemaphoreCreateRecursiveMutex() function.\r
+ The parameter is a pointer to the pre-allocated StaticSemaphore_t structure,\r
+ which will hold information on the semaphore in an anonymous way. If the\r
+ pointer is passed as NULL then the structure will be allocated dynamically,\r
+ just as when xSemaphoreCreateRecursiveMutex() is called. */\r
+ xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xSemaphoreBuffer );\r
+\r
+ /* The semaphore handle should equal the static semaphore structure passed\r
+ into the xSemaphoreCreateBinaryStatic() function. */\r
+ configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );\r
+\r
+ /* Ensure the semaphore passes a few sanity checks as a valid\r
+ recursive semaphore. */\r
+ prvCheckRecursiveSemaphoreFunction( xSemaphore );\r
+\r
+ /* Delete the semaphore again so the buffers can be reused. */\r
+ vSemaphoreDelete( xSemaphore );\r
+\r
+\r
+ /* The semaphore created above had a statically allocated semaphore\r
+ structure. Repeat the above using NULL as the\r
+ xSemaphoreCreateRecursiveMutexStatic() parameter so the semaphore structure\r
+ is instead allocated dynamically. */\r
+ xSemaphore = xSemaphoreCreateRecursiveMutexStatic( NULL );\r
+\r
+ /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */\r
+ prvCheckRecursiveSemaphoreFunction( xSemaphore );\r
+\r
+ /* Delete the semaphore again so the buffers can be reused. */\r
+ vSemaphoreDelete( xSemaphore );\r
+\r
+ /* Ensure lower priority tasks get CPU time. */\r
+ vTaskDelay( prvGetNextDelayTime() );\r
+\r
+ /* Just to show the check task that this task is still executing. */\r
+ uxCycleCounter++;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r