Exemple #1
0
static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void )
{
SemaphoreHandle_t xSemaphore;

/* StaticSemaphore_t is a publicly accessible structure that has the same size
and alignment requirements as the real semaphore structure.  It is provided as a
mechanism for applications to know the size of the semaphore (which is dependent
on the architecture and configuration file settings) without breaking the strict
data hiding policy by exposing the real semaphore internals.  This
StaticSemaphore_t variable is passed into the
xSemaphoreCreateRecursiveMutexStatic() function calls within this function. */
StaticSemaphore_t xSemaphoreBuffer;

	/* Create the semaphore.  xSemaphoreCreateRecursiveMutexStatic() has one
	more parameter than the usual xSemaphoreCreateRecursiveMutex() function.
	The parameter is a pointer to the pre-allocated StaticSemaphore_t structure,
	which will hold information on the semaphore in an anonymous way.  If the
	pointer is passed as NULL then the structure will be allocated dynamically,
	just as	when xSemaphoreCreateRecursiveMutex() is called. */
	xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xSemaphoreBuffer );

	/* The semaphore handle should equal the static semaphore structure passed
	into the xSemaphoreCreateBinaryStatic() function. */
	configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );

	/* Ensure the semaphore passes a few sanity checks as a valid
	recursive semaphore. */
	prvSanityCheckCreatedRecursiveMutex( xSemaphore );

	/* Delete the semaphore again so the buffers can be reused. */
	vSemaphoreDelete( xSemaphore );


	/* The semaphore created above had a statically allocated semaphore
	structure.  Repeat the above using NULL as the
	xSemaphoreCreateRecursiveMutexStatic() parameter so the semaphore structure
	is instead allocated dynamically. */
	xSemaphore = xSemaphoreCreateRecursiveMutexStatic( NULL );

	/* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
	prvSanityCheckCreatedRecursiveMutex( xSemaphore );

	/* Delete the semaphore again so the buffers can be reused. */
	vSemaphoreDelete( xSemaphore );

	/* Ensure lower priority tasks get CPU time. */
	vTaskDelay( prvGetNextDelayTime() );

	/* Just to show the check task that this task is still executing. */
	uxCycleCounter++;
}
static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void )
{
SemaphoreHandle_t xSemaphore;

/* StaticSemaphore_t is a publicly accessible structure that has the same size
and alignment requirements as the real semaphore structure.  It is provided as a
mechanism for applications to know the size of the semaphore (which is dependent
on the architecture and configuration file settings) without breaking the strict
data hiding policy by exposing the real semaphore internals.  This
StaticSemaphore_t variable is passed into the
xSemaphoreCreateRecursiveMutexStatic() function calls within this function. */
StaticSemaphore_t xSemaphoreBuffer;

	/* Create the semaphore.  xSemaphoreCreateRecursiveMutexStatic() has one
	more parameter than the usual xSemaphoreCreateRecursiveMutex() function.
	The parameter is a pointer to the pre-allocated StaticSemaphore_t structure,
	which will hold information on the semaphore in an anonymous way.  If the
	pointer is passed as NULL then the structure will be allocated dynamically,
	just as	when xSemaphoreCreateRecursiveMutex() is called. */
	xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xSemaphoreBuffer );

	/* The semaphore handle should equal the static semaphore structure passed
	into the xSemaphoreCreateBinaryStatic() function. */
	configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );

	/* Ensure the semaphore passes a few sanity checks as a valid
	recursive semaphore. */
	prvSanityCheckCreatedRecursiveMutex( xSemaphore );

	/* Delete the semaphore again so the buffers can be reused. */
	vSemaphoreDelete( xSemaphore );

	/* Now do the same using dynamically allocated buffers to ensure the delete
	functions are working correctly in both the static and dynamic memory
	allocation cases. */
	#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
	{
		xSemaphore = xSemaphoreCreateRecursiveMutex();
		configASSERT( xSemaphore != NULL );
		prvSanityCheckCreatedRecursiveMutex( xSemaphore );
		vSemaphoreDelete( xSemaphore );
	}
	#endif
}