Go to the source code of this file.
Functions | |
void | vStartBlockingQueueTasks (unsigned portBASE_TYPE uxPriority) |
portBASE_TYPE | xAreBlockingQueuesStillRunning (void) |
void vStartBlockingQueueTasks | ( | unsigned portBASE_TYPE | uxPriority | ) |
Definition at line 126 of file BlockQ.c.
References blckqSTACK_SIZE, portBASE_TYPE, portTICK_RATE_MS, BLOCKING_QUEUE_PARAMETERS::psCheckVariable, pvPortMalloc(), sBlockingConsumerCount, tskIDLE_PRIORITY, BLOCKING_QUEUE_PARAMETERS::xBlockTime, BLOCKING_QUEUE_PARAMETERS::xQueue, xQueueCreate(), and xTaskCreate.
Referenced by main().
00127 { 00128 xBlockingQueueParameters *pxQueueParameters1, *pxQueueParameters2; 00129 xBlockingQueueParameters *pxQueueParameters3, *pxQueueParameters4; 00130 xBlockingQueueParameters *pxQueueParameters5, *pxQueueParameters6; 00131 const unsigned portBASE_TYPE uxQueueSize1 = 1, uxQueueSize5 = 5; 00132 const portTickType xBlockTime = ( portTickType ) 1000 / portTICK_RATE_MS; 00133 const portTickType xDontBlock = ( portTickType ) 0; 00134 00135 /* Create the first two tasks as described at the top of the file. */ 00136 00137 /* First create the structure used to pass parameters to the consumer tasks. */ 00138 pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); 00139 00140 /* Create the queue used by the first two tasks to pass the incrementing number. 00141 Pass a pointer to the queue in the parameter structure. */ 00142 pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) ); 00143 00144 /* The consumer is created first so gets a block time as described above. */ 00145 pxQueueParameters1->xBlockTime = xBlockTime; 00146 00147 /* Pass in the variable that this task is going to increment so we can check it 00148 is still running. */ 00149 pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] ); 00150 00151 /* Create the structure used to pass parameters to the producer task. */ 00152 pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); 00153 00154 /* Pass the queue to this task also, using the parameter structure. */ 00155 pxQueueParameters2->xQueue = pxQueueParameters1->xQueue; 00156 00157 /* The producer is not going to block - as soon as it posts the consumer will 00158 wake and remove the item so the producer should always have room to post. */ 00159 pxQueueParameters2->xBlockTime = xDontBlock; 00160 00161 /* Pass in the variable that this task is going to increment so we can check 00162 it is still running. */ 00163 pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] ); 00164 00165 00166 /* Note the producer has a lower priority than the consumer when the tasks are 00167 spawned. */ 00168 xTaskCreate( vBlockingQueueConsumer, ( signed char * ) "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL ); 00169 xTaskCreate( vBlockingQueueProducer, ( signed char * ) "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL ); 00170 00171 00172 00173 /* Create the second two tasks as described at the top of the file. This uses 00174 the same mechanism but reverses the task priorities. */ 00175 00176 pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); 00177 pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) ); 00178 pxQueueParameters3->xBlockTime = xDontBlock; 00179 pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] ); 00180 00181 pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); 00182 pxQueueParameters4->xQueue = pxQueueParameters3->xQueue; 00183 pxQueueParameters4->xBlockTime = xBlockTime; 00184 pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] ); 00185 00186 xTaskCreate( vBlockingQueueConsumer, ( signed char * ) "QProdB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL ); 00187 xTaskCreate( vBlockingQueueProducer, ( signed char * ) "QConsB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL ); 00188 00189 00190 00191 /* Create the last two tasks as described above. The mechanism is again just 00192 the same. This time both parameter structures are given a block time. */ 00193 pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); 00194 pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) ); 00195 pxQueueParameters5->xBlockTime = xBlockTime; 00196 pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] ); 00197 00198 pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); 00199 pxQueueParameters6->xQueue = pxQueueParameters5->xQueue; 00200 pxQueueParameters6->xBlockTime = xBlockTime; 00201 pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] ); 00202 00203 xTaskCreate( vBlockingQueueProducer, ( signed char * ) "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL ); 00204 xTaskCreate( vBlockingQueueConsumer, ( signed char * ) "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL ); 00205 }
portBASE_TYPE xAreBlockingQueuesStillRunning | ( | void | ) |
Definition at line 277 of file BlockQ.c.
References blckqNUM_TASK_SETS, pdFALSE, pdPASS, portBASE_TYPE, and sBlockingConsumerCount.
Referenced by prvCheckOtherTasksAreStillRunning().
00278 { 00279 static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( unsigned short ) 0, ( unsigned short ) 0, ( unsigned short ) 0 }; 00280 static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( unsigned short ) 0, ( unsigned short ) 0, ( unsigned short ) 0 }; 00281 portBASE_TYPE xReturn = pdPASS, xTasks; 00282 00283 /* Not too worried about mutual exclusion on these variables as they are 16 00284 bits and we are only reading them. We also only care to see if they have 00285 changed or not. 00286 00287 Loop through each check variable to and return pdFALSE if any are found not 00288 to have changed since the last call. */ 00289 00290 for( xTasks = 0; xTasks < blckqNUM_TASK_SETS; xTasks++ ) 00291 { 00292 if( sBlockingConsumerCount[ xTasks ] == sLastBlockingConsumerCount[ xTasks ] ) 00293 { 00294 xReturn = pdFALSE; 00295 } 00296 sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ]; 00297 00298 00299 if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] ) 00300 { 00301 xReturn = pdFALSE; 00302 } 00303 sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ]; 00304 } 00305 00306 return xReturn; 00307 }