Go to the source code of this file.
Functions | |
void | vStartCountingSemaphoreTasks (void) |
portBASE_TYPE | xAreCountingSemaphoreTasksStillRunning (void) |
void vStartCountingSemaphoreTasks | ( | void | ) |
Definition at line 133 of file countsem.c.
References configMINIMAL_STACK_SIZE, countMAX_COUNT_VALUE, countSTART_AT_MAX_COUNT, portCHAR, prvCountingSemaphoreTask(), tskIDLE_PRIORITY, COUNT_SEM_STRUCT::uxExpectedStartCount, COUNT_SEM_STRUCT::uxLoopCounter, vQueueAddToRegistry, COUNT_SEM_STRUCT::xSemaphore, xSemaphoreCreateCounting, and xTaskCreate.
00134 { 00135 /* Create the semaphores that we are going to use for the test/demo. The 00136 first should be created such that it starts at its maximum count value, 00137 the second should be created such that it starts with a count value of zero. */ 00138 xParameters[ 0 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, countMAX_COUNT_VALUE ); 00139 xParameters[ 0 ].uxExpectedStartCount = countSTART_AT_MAX_COUNT; 00140 xParameters[ 0 ].uxLoopCounter = 0; 00141 00142 xParameters[ 1 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, 0 ); 00143 xParameters[ 1 ].uxExpectedStartCount = 0; 00144 xParameters[ 1 ].uxLoopCounter = 0; 00145 00146 /* vQueueAddToRegistry() adds the semaphore to the registry, if one is 00147 in use. The registry is provided as a means for kernel aware 00148 debuggers to locate semaphores and has no purpose if a kernel aware debugger 00149 is not being used. The call to vQueueAddToRegistry() will be removed 00150 by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is 00151 defined to be less than 1. */ 00152 vQueueAddToRegistry( ( xQueueHandle ) xParameters[ 0 ].xSemaphore, ( signed portCHAR * ) "Counting_Sem_1" ); 00153 vQueueAddToRegistry( ( xQueueHandle ) xParameters[ 1 ].xSemaphore, ( signed portCHAR * ) "Counting_Sem_2" ); 00154 00155 00156 /* Were the semaphores created? */ 00157 if( ( xParameters[ 0 ].xSemaphore != NULL ) || ( xParameters[ 1 ].xSemaphore != NULL ) ) 00158 { 00159 /* Create the demo tasks, passing in the semaphore to use as the parameter. */ 00160 xTaskCreate( prvCountingSemaphoreTask, ( signed portCHAR * ) "CNT1", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 0 ] ), tskIDLE_PRIORITY, NULL ); 00161 xTaskCreate( prvCountingSemaphoreTask, ( signed portCHAR * ) "CNT2", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 1 ] ), tskIDLE_PRIORITY, NULL ); 00162 } 00163 }
portBASE_TYPE xAreCountingSemaphoreTasksStillRunning | ( | void | ) |
Definition at line 276 of file countsem.c.
References pdFAIL, pdFALSE, pdPASS, portBASE_TYPE, COUNT_SEM_STRUCT::uxLoopCounter, and xErrorDetected.
00277 { 00278 static unsigned portBASE_TYPE uxLastCount0 = 0, uxLastCount1 = 0; 00279 portBASE_TYPE xReturn = pdPASS; 00280 00281 /* Return fail if any 'give' or 'take' did not result in the expected 00282 behaviour. */ 00283 if( xErrorDetected != pdFALSE ) 00284 { 00285 xReturn = pdFAIL; 00286 } 00287 00288 /* Return fail if either task is not still incrementing its loop counter. */ 00289 if( uxLastCount0 == xParameters[ 0 ].uxLoopCounter ) 00290 { 00291 xReturn = pdFAIL; 00292 } 00293 else 00294 { 00295 uxLastCount0 = xParameters[ 0 ].uxLoopCounter; 00296 } 00297 00298 if( uxLastCount1 == xParameters[ 1 ].uxLoopCounter ) 00299 { 00300 xReturn = pdFAIL; 00301 } 00302 else 00303 { 00304 uxLastCount1 = xParameters[ 1 ].uxLoopCounter; 00305 } 00306 00307 return xReturn; 00308 }