Go to the source code of this file.
Functions | |
void | vStartSemaphoreTasks (unsigned portBASE_TYPE uxPriority) |
portBASE_TYPE | xAreSemaphoreTasksStillRunning (void) |
void vStartSemaphoreTasks | ( | unsigned portBASE_TYPE | uxPriority | ) |
Definition at line 115 of file semtest.c.
References portTICK_RATE_MS, SEMAPHORE_PARAMETERS::pulSharedVariable, pvPortMalloc(), semtstBLOCKING_EXPECTED_VALUE, semtstNON_BLOCKING_EXPECTED_VALUE, semtstSTACK_SIZE, tskIDLE_PRIORITY, vQueueAddToRegistry, vSemaphoreCreateBinary, SEMAPHORE_PARAMETERS::xBlockTime, SEMAPHORE_PARAMETERS::xSemaphore, and xTaskCreate.
Referenced by main().
00116 { 00117 xSemaphoreParameters *pxFirstSemaphoreParameters, *pxSecondSemaphoreParameters; 00118 const portTickType xBlockTime = ( portTickType ) 100; 00119 00120 /* Create the structure used to pass parameters to the first two tasks. */ 00121 pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) ); 00122 00123 if( pxFirstSemaphoreParameters != NULL ) 00124 { 00125 /* Create the semaphore used by the first two tasks. */ 00126 vSemaphoreCreateBinary( pxFirstSemaphoreParameters->xSemaphore ); 00127 00128 if( pxFirstSemaphoreParameters->xSemaphore != NULL ) 00129 { 00130 /* Create the variable which is to be shared by the first two tasks. */ 00131 pxFirstSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) ); 00132 00133 /* Initialise the share variable to the value the tasks expect. */ 00134 *( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE; 00135 00136 /* The first two tasks do not block on semaphore calls. */ 00137 pxFirstSemaphoreParameters->xBlockTime = ( portTickType ) 0; 00138 00139 /* Spawn the first two tasks. As they poll they operate at the idle priority. */ 00140 xTaskCreate( prvSemaphoreTest, ( signed char * ) "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL ); 00141 xTaskCreate( prvSemaphoreTest, ( signed char * ) "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL ); 00142 } 00143 } 00144 00145 /* Do exactly the same to create the second set of tasks, only this time 00146 provide a block time for the semaphore calls. */ 00147 pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) ); 00148 if( pxSecondSemaphoreParameters != NULL ) 00149 { 00150 vSemaphoreCreateBinary( pxSecondSemaphoreParameters->xSemaphore ); 00151 00152 if( pxSecondSemaphoreParameters->xSemaphore != NULL ) 00153 { 00154 pxSecondSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) ); 00155 *( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE; 00156 pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_RATE_MS; 00157 00158 xTaskCreate( prvSemaphoreTest, ( signed char * ) "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( xTaskHandle * ) NULL ); 00159 xTaskCreate( prvSemaphoreTest, ( signed char * ) "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( xTaskHandle * ) NULL ); 00160 } 00161 } 00162 00163 /* vQueueAddToRegistry() adds the semaphore to the registry, if one is 00164 in use. The registry is provided as a means for kernel aware 00165 debuggers to locate semaphores and has no purpose if a kernel aware debugger 00166 is not being used. The call to vQueueAddToRegistry() will be removed 00167 by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is 00168 defined to be less than 1. */ 00169 vQueueAddToRegistry( ( xQueueHandle ) pxFirstSemaphoreParameters->xSemaphore, ( signed char * ) "Counting_Sem_1" ); 00170 vQueueAddToRegistry( ( xQueueHandle ) pxSecondSemaphoreParameters->xSemaphore, ( signed char * ) "Counting_Sem_2" ); 00171 }
portBASE_TYPE xAreSemaphoreTasksStillRunning | ( | void | ) |
Definition at line 266 of file semtest.c.
References pdFALSE, pdTRUE, portBASE_TYPE, sCheckVariables, and semtstNUM_TASKS.
Referenced by prvCheckOtherTasksAreStillRunning().
00267 { 00268 static short sLastCheckVariables[ semtstNUM_TASKS ] = { 0 }; 00269 portBASE_TYPE xTask, xReturn = pdTRUE; 00270 00271 for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ ) 00272 { 00273 if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] ) 00274 { 00275 xReturn = pdFALSE; 00276 } 00277 00278 sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ]; 00279 } 00280 00281 return xReturn; 00282 }