#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "PollQ.h"
Go to the source code of this file.
Defines | |
#define | pollqCONSUMER_DELAY ( pollqPRODUCER_DELAY - ( portTickType ) ( 20 / portTICK_RATE_MS ) ) |
#define | pollqINITIAL_VALUE ( ( signed portBASE_TYPE ) 0 ) |
#define | pollqNO_DELAY ( ( portTickType ) 0 ) |
#define | pollqPRODUCER_DELAY ( ( portTickType ) 200 / portTICK_RATE_MS ) |
#define | pollqQUEUE_SIZE ( 10 ) |
#define | pollqSTACK_SIZE configMINIMAL_STACK_SIZE |
#define | pollqVALUES_TO_PRODUCE ( ( signed portBASE_TYPE ) 3 ) |
Functions | |
static | portTASK_FUNCTION (vPolledQueueConsumer, pvParameters) |
static | portTASK_FUNCTION (vPolledQueueProducer, pvParameters) |
static | portTASK_FUNCTION_PROTO (vPolledQueueConsumer, pvParameters) |
static | portTASK_FUNCTION_PROTO (vPolledQueueProducer, pvParameters) |
void | vStartPolledQueueTasks (unsigned portBASE_TYPE uxPriority) |
portBASE_TYPE | xArePollingQueuesStillRunning (void) |
Variables | |
static volatile signed portBASE_TYPE | xPollingConsumerCount = pollqINITIAL_VALUE |
static volatile signed portBASE_TYPE | xPollingProducerCount = pollqINITIAL_VALUE |
#define pollqCONSUMER_DELAY ( pollqPRODUCER_DELAY - ( portTickType ) ( 20 / portTICK_RATE_MS ) ) |
#define pollqNO_DELAY ( ( portTickType ) 0 ) |
#define pollqPRODUCER_DELAY ( ( portTickType ) 200 / portTICK_RATE_MS ) |
#define pollqVALUES_TO_PRODUCE ( ( signed portBASE_TYPE ) 3 ) |
static portTASK_FUNCTION | ( | vPolledQueueConsumer | , | |
pvParameters | ||||
) | [static] |
Definition at line 174 of file PollQ.c.
References pdFALSE, pdPASS, pdTRUE, pollqCONSUMER_DELAY, pollqNO_DELAY, portBASE_TYPE, portENTER_CRITICAL, portEXIT_CRITICAL, uxQueueMessagesWaiting(), vTaskDelay(), xPollingConsumerCount, and xQueueReceive.
00175 { 00176 unsigned short usData, usExpectedValue = ( unsigned short ) 0; 00177 signed portBASE_TYPE xError = pdFALSE; 00178 00179 for( ;; ) 00180 { 00181 /* Loop until the queue is empty. */ 00182 while( uxQueueMessagesWaiting( *( ( xQueueHandle * ) pvParameters ) ) ) 00183 { 00184 if( xQueueReceive( *( ( xQueueHandle * ) pvParameters ), &usData, pollqNO_DELAY ) == pdPASS ) 00185 { 00186 if( usData != usExpectedValue ) 00187 { 00188 /* This is not what we expected to receive so an error has 00189 occurred. */ 00190 xError = pdTRUE; 00191 00192 /* Catch-up to the value we received so our next expected 00193 value should again be correct. */ 00194 usExpectedValue = usData; 00195 } 00196 else 00197 { 00198 if( xError == pdFALSE ) 00199 { 00200 /* Only increment the check variable if no errors have 00201 occurred. */ 00202 portENTER_CRITICAL(); 00203 xPollingConsumerCount++; 00204 portEXIT_CRITICAL(); 00205 } 00206 } 00207 00208 /* Next time round we would expect the number to be one higher. */ 00209 usExpectedValue++; 00210 } 00211 } 00212 00213 /* Now the queue is empty we block, allowing the producer to place more 00214 items in the queue. */ 00215 vTaskDelay( pollqCONSUMER_DELAY ); 00216 } 00217 } /*lint !e818 Function prototype must conform to API. */
static portTASK_FUNCTION | ( | vPolledQueueProducer | , | |
pvParameters | ||||
) | [static] |
Definition at line 135 of file PollQ.c.
References pdFALSE, pdPASS, pdTRUE, pollqNO_DELAY, pollqPRODUCER_DELAY, pollqVALUES_TO_PRODUCE, portBASE_TYPE, portENTER_CRITICAL, portEXIT_CRITICAL, vTaskDelay(), xPollingProducerCount, and xQueueSend.
00136 { 00137 unsigned short usValue = ( unsigned short ) 0; 00138 signed portBASE_TYPE xError = pdFALSE, xLoop; 00139 00140 for( ;; ) 00141 { 00142 for( xLoop = 0; xLoop < pollqVALUES_TO_PRODUCE; xLoop++ ) 00143 { 00144 /* Send an incrementing number on the queue without blocking. */ 00145 if( xQueueSend( *( ( xQueueHandle * ) pvParameters ), ( void * ) &usValue, pollqNO_DELAY ) != pdPASS ) 00146 { 00147 /* We should never find the queue full so if we get here there 00148 has been an error. */ 00149 xError = pdTRUE; 00150 } 00151 else 00152 { 00153 if( xError == pdFALSE ) 00154 { 00155 /* If an error has ever been recorded we stop incrementing the 00156 check variable. */ 00157 portENTER_CRITICAL(); 00158 xPollingProducerCount++; 00159 portEXIT_CRITICAL(); 00160 } 00161 00162 /* Update the value we are going to post next time around. */ 00163 usValue++; 00164 } 00165 } 00166 00167 /* Wait before we start posting again to ensure the consumer runs and 00168 empties the queue. */ 00169 vTaskDelay( pollqPRODUCER_DELAY ); 00170 } 00171 } /*lint !e818 Function prototype must conform to API. */
static portTASK_FUNCTION_PROTO | ( | vPolledQueueConsumer | , | |
pvParameters | ||||
) | [static] |
static portTASK_FUNCTION_PROTO | ( | vPolledQueueProducer | , | |
pvParameters | ||||
) | [static] |
void vStartPolledQueueTasks | ( | unsigned portBASE_TYPE | uxPriority | ) |
Definition at line 114 of file PollQ.c.
References pollqQUEUE_SIZE, pollqSTACK_SIZE, portBASE_TYPE, vQueueAddToRegistry, xQueueCreate(), and xTaskCreate.
Referenced by main().
00115 { 00116 static xQueueHandle xPolledQueue; 00117 00118 /* Create the queue used by the producer and consumer. */ 00119 xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) ); 00120 00121 /* vQueueAddToRegistry() adds the queue to the queue registry, if one is 00122 in use. The queue registry is provided as a means for kernel aware 00123 debuggers to locate queues and has no purpose if a kernel aware debugger 00124 is not being used. The call to vQueueAddToRegistry() will be removed 00125 by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is 00126 defined to be less than 1. */ 00127 vQueueAddToRegistry( xPolledQueue, ( signed char * ) "Poll_Test_Queue" ); 00128 00129 /* Spawn the producer and consumer. */ 00130 xTaskCreate( vPolledQueueConsumer, ( signed char * ) "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL ); 00131 xTaskCreate( vPolledQueueProducer, ( signed char * ) "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL ); 00132 }
portBASE_TYPE xArePollingQueuesStillRunning | ( | void | ) |
Definition at line 221 of file PollQ.c.
References pdFALSE, pdTRUE, pollqINITIAL_VALUE, portBASE_TYPE, xPollingConsumerCount, and xPollingProducerCount.
Referenced by prvCheckOtherTasksAreStillRunning().
00222 { 00223 portBASE_TYPE xReturn; 00224 00225 /* Check both the consumer and producer poll count to check they have both 00226 been changed since out last trip round. We do not need a critical section 00227 around the check variables as this is called from a higher priority than 00228 the other tasks that access the same variables. */ 00229 if( ( xPollingConsumerCount == pollqINITIAL_VALUE ) || 00230 ( xPollingProducerCount == pollqINITIAL_VALUE ) 00231 ) 00232 { 00233 xReturn = pdFALSE; 00234 } 00235 else 00236 { 00237 xReturn = pdTRUE; 00238 } 00239 00240 /* Set the check variables back down so we know if they have been 00241 incremented the next time around. */ 00242 xPollingConsumerCount = pollqINITIAL_VALUE; 00243 xPollingProducerCount = pollqINITIAL_VALUE; 00244 00245 return xReturn; 00246 }
volatile signed portBASE_TYPE xPollingConsumerCount = pollqINITIAL_VALUE [static] |
volatile signed portBASE_TYPE xPollingProducerCount = pollqINITIAL_VALUE [static] |