X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=FreeRTOS%2FDemo%2FCommon%2FMinimal%2Fcountsem.c;h=4f2e5dc7f3df360fc3ccbc850dbe80d7bc7cd7a3;hb=70f0bb6133065c1f0049f8258d0454027d37f657;hp=0483a0a8fa988f3b4a6b162f653492eaab1bf95c;hpb=62c041d220c4812a1ea4350cac687998fcd5d733;p=freertos diff --git a/FreeRTOS/Demo/Common/Minimal/countsem.c b/FreeRTOS/Demo/Common/Minimal/countsem.c index 0483a0a8f..4f2e5dc7f 100644 --- a/FreeRTOS/Demo/Common/Minimal/countsem.c +++ b/FreeRTOS/Demo/Common/Minimal/countsem.c @@ -1,5 +1,5 @@ /* - FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd. + FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd. All rights reserved VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. @@ -8,7 +8,7 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. *************************************************************************** >>! NOTE: The modification to the GPL is included to allow you to !<< @@ -68,7 +68,7 @@ */ -/* +/* * Simple demonstration of the usage of counting semaphore. */ @@ -84,7 +84,7 @@ #define countMAX_COUNT_VALUE ( 200 ) /* Constants used to indicate whether or not the semaphore should have been -created with its maximum count value, or its minimum count value. These +created with its maximum count value, or its minimum count value. These numbers are used to ensure that the pointers passed in as the task parameters are valid. */ #define countSTART_AT_MAX_COUNT ( 0xaa ) @@ -118,7 +118,7 @@ static void prvCountingSemaphoreTask( void *pvParameters ); static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore, UBaseType_t *puxLoopCounter ); /* - * Utility function to decrement the semaphore count value up from + * Utility function to decrement the semaphore count value up from * countMAX_COUNT_VALUE to zero. */ static void prvDecrementSemaphoreCount( SemaphoreHandle_t xSemaphore, UBaseType_t *puxLoopCounter ); @@ -134,11 +134,11 @@ typedef struct COUNT_SEM_STRUCT /* Set to countSTART_AT_MAX_COUNT if the semaphore should be created with its count value set to its max count value, or countSTART_AT_ZERO if it should have been created with its count value set to 0. */ - UBaseType_t uxExpectedStartCount; + UBaseType_t uxExpectedStartCount; /* Incremented on each cycle of the demo task. Used to detect a stalled task. */ - UBaseType_t uxLoopCounter; + UBaseType_t uxLoopCounter; } xCountSemStruct; /* Two structures are defined, one is passed to each test task. */ @@ -159,22 +159,21 @@ void vStartCountingSemaphoreTasks( void ) xParameters[ 1 ].uxExpectedStartCount = 0; xParameters[ 1 ].uxLoopCounter = 0; - /* vQueueAddToRegistry() adds the semaphore to the registry, if one is - in use. The registry is provided as a means for kernel aware - debuggers to locate semaphores and has no purpose if a kernel aware debugger - is not being used. The call to vQueueAddToRegistry() will be removed - by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is - defined to be less than 1. */ - vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 0 ].xSemaphore, "Counting_Sem_1" ); - vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 1 ].xSemaphore, "Counting_Sem_2" ); - - /* Were the semaphores created? */ if( ( xParameters[ 0 ].xSemaphore != NULL ) || ( xParameters[ 1 ].xSemaphore != NULL ) ) { + /* vQueueAddToRegistry() adds the semaphore to the registry, if one is + in use. The registry is provided as a means for kernel aware + debuggers to locate semaphores and has no purpose if a kernel aware + debugger is not being used. The call to vQueueAddToRegistry() will be + removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not + defined or is defined to be less than 1. */ + vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 0 ].xSemaphore, "Counting_Sem_1" ); + vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 1 ].xSemaphore, "Counting_Sem_2" ); + /* Create the demo tasks, passing in the semaphore to use as the parameter. */ xTaskCreate( prvCountingSemaphoreTask, "CNT1", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 0 ] ), tskIDLE_PRIORITY, NULL ); - xTaskCreate( prvCountingSemaphoreTask, "CNT2", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 1 ] ), tskIDLE_PRIORITY, NULL ); + xTaskCreate( prvCountingSemaphoreTask, "CNT2", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 1 ] ), tskIDLE_PRIORITY, NULL ); } } /*-----------------------------------------------------------*/ @@ -193,6 +192,8 @@ UBaseType_t ux; /* We should be able to 'take' the semaphore countMAX_COUNT_VALUE times. */ for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ ) { + configASSERT( uxSemaphoreGetCount( xSemaphore ) == ( countMAX_COUNT_VALUE - ux ) ); + if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) != pdPASS ) { /* We expected to be able to take the semaphore. */ @@ -206,8 +207,9 @@ UBaseType_t ux; taskYIELD(); #endif - /* If the semaphore count is zero then we should not be able to 'take' + /* If the semaphore count is zero then we should not be able to 'take' the semaphore. */ + configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 ); if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS ) { xErrorDetected = pdTRUE; @@ -219,7 +221,7 @@ static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore, UBaseType_ { UBaseType_t ux; - /* If the semaphore count is zero then we should not be able to 'take' + /* If the semaphore count is zero then we should not be able to 'take' the semaphore. */ if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS ) { @@ -229,6 +231,8 @@ UBaseType_t ux; /* We should be able to 'give' the semaphore countMAX_COUNT_VALUE times. */ for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ ) { + configASSERT( uxSemaphoreGetCount( xSemaphore ) == ux ); + if( xSemaphoreGive( xSemaphore ) != pdPASS ) { /* We expected to be able to take the semaphore. */ @@ -257,7 +261,7 @@ xCountSemStruct *pxParameter; #ifdef USE_STDIO void vPrintDisplayMessage( const char * const * ppcMessageToSend ); - + const char * const pcTaskStartMsg = "Counting semaphore demo started.\r\n"; /* Queue a message for printing to say the task has started. */