AltPollQ.c File Reference

#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "AltPollQ.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 vStartAltPolledQueueTasks (unsigned portBASE_TYPE uxPriority)
portBASE_TYPE xAreAltPollingQueuesStillRunning (void)

Variables

static volatile signed
portBASE_TYPE 
xPollingConsumerCount = pollqINITIAL_VALUE
static volatile signed
portBASE_TYPE 
xPollingProducerCount = pollqINITIAL_VALUE


Define Documentation

#define pollqCONSUMER_DELAY   ( pollqPRODUCER_DELAY - ( portTickType ) ( 20 / portTICK_RATE_MS ) )

Definition at line 95 of file AltPollQ.c.

Referenced by portTASK_FUNCTION().

#define pollqINITIAL_VALUE   ( ( signed portBASE_TYPE ) 0 )

Definition at line 98 of file AltPollQ.c.

Referenced by xAreAltPollingQueuesStillRunning(), and xArePollingQueuesStillRunning().

#define pollqNO_DELAY   ( ( portTickType ) 0 )

Definition at line 96 of file AltPollQ.c.

Referenced by portTASK_FUNCTION().

#define pollqPRODUCER_DELAY   ( ( portTickType ) 200 / portTICK_RATE_MS )

Definition at line 94 of file AltPollQ.c.

Referenced by portTASK_FUNCTION().

#define pollqQUEUE_SIZE   ( 10 )

Definition at line 93 of file AltPollQ.c.

Referenced by vStartAltPolledQueueTasks(), and vStartPolledQueueTasks().

#define pollqSTACK_SIZE   configMINIMAL_STACK_SIZE

Definition at line 92 of file AltPollQ.c.

Referenced by vStartAltPolledQueueTasks(), and vStartPolledQueueTasks().

#define pollqVALUES_TO_PRODUCE   ( ( signed portBASE_TYPE ) 3 )

Definition at line 97 of file AltPollQ.c.

Referenced by portTASK_FUNCTION().


Function Documentation

static portTASK_FUNCTION ( vPolledQueueConsumer  ,
pvParameters   
) [static]

Definition at line 182 of file AltPollQ.c.

References pdFALSE, pdPASS, pdTRUE, pollqCONSUMER_DELAY, pollqNO_DELAY, portBASE_TYPE, portCHAR, portENTER_CRITICAL, portEXIT_CRITICAL, portSHORT, uxQueueMessagesWaiting(), vPrintDisplayMessage(), vTaskDelay(), xPollingConsumerCount, and xQueueAltReceive.

00183 {
00184 unsigned portSHORT usData, usExpectedValue = ( unsigned portSHORT ) 0;
00185 signed portBASE_TYPE xError = pdFALSE;
00186 
00187     #ifdef USE_STDIO
00188     void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );
00189     
00190         const portCHAR * const pcTaskStartMsg = "Alt blocking queue consumer task started.\r\n";
00191 
00192         /* Queue a message for printing to say the task has started. */
00193         vPrintDisplayMessage( &pcTaskStartMsg );
00194     #endif
00195 
00196     for( ;; )
00197     {       
00198         /* Loop until the queue is empty. */
00199         while( uxQueueMessagesWaiting( *( ( xQueueHandle * ) pvParameters ) ) )
00200         {
00201             if( xQueueAltReceive( *( ( xQueueHandle * ) pvParameters ), &usData, pollqNO_DELAY ) == pdPASS )
00202             {
00203                 if( usData != usExpectedValue )
00204                 {
00205                     /* This is not what we expected to receive so an error has
00206                     occurred. */
00207                     xError = pdTRUE;
00208 
00209                     /* Catch-up to the value we received so our next expected
00210                     value should again be correct. */
00211                     usExpectedValue = usData;
00212                 }
00213                 else
00214                 {
00215                     if( xError == pdFALSE )
00216                     {
00217                         /* Only increment the check variable if no errors have
00218                         occurred. */
00219                         portENTER_CRITICAL();
00220                             xPollingConsumerCount++;
00221                         portEXIT_CRITICAL();
00222                     }
00223                 }
00224 
00225                 /* Next time round we would expect the number to be one higher. */
00226                 usExpectedValue++;
00227             }
00228         }
00229 
00230         /* Now the queue is empty we block, allowing the producer to place more
00231         items in the queue. */
00232         vTaskDelay( pollqCONSUMER_DELAY );
00233     }
00234 } /*lint !e818 Function prototype must conform to API. */

static portTASK_FUNCTION ( vPolledQueueProducer  ,
pvParameters   
) [static]

Definition at line 134 of file AltPollQ.c.

References pdFALSE, pdPASS, pdTRUE, pollqNO_DELAY, pollqPRODUCER_DELAY, pollqVALUES_TO_PRODUCE, portBASE_TYPE, portCHAR, portENTER_CRITICAL, portEXIT_CRITICAL, portSHORT, vPrintDisplayMessage(), vTaskDelay(), xPollingProducerCount, and xQueueAltSendToBack.

00135 {
00136 unsigned portSHORT usValue = ( unsigned portSHORT ) 0;
00137 signed portBASE_TYPE xError = pdFALSE, xLoop;
00138 
00139     #ifdef USE_STDIO
00140     void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );
00141     
00142         const portCHAR * const pcTaskStartMsg = "Alt polling queue producer task started.\r\n";
00143 
00144         /* Queue a message for printing to say the task has started. */
00145         vPrintDisplayMessage( &pcTaskStartMsg );
00146     #endif
00147 
00148     for( ;; )
00149     {       
00150         for( xLoop = 0; xLoop < pollqVALUES_TO_PRODUCE; xLoop++ )
00151         {
00152             /* Send an incrementing number on the queue without blocking. */
00153             if( xQueueAltSendToBack( *( ( xQueueHandle * ) pvParameters ), ( void * ) &usValue, pollqNO_DELAY ) != pdPASS )
00154             {
00155                 /* We should never find the queue full so if we get here there
00156                 has been an error. */
00157                 xError = pdTRUE;
00158             }
00159             else
00160             {
00161                 if( xError == pdFALSE )
00162                 {
00163                     /* If an error has ever been recorded we stop incrementing the
00164                     check variable. */
00165                     portENTER_CRITICAL();
00166                         xPollingProducerCount++;
00167                     portEXIT_CRITICAL();
00168                 }
00169 
00170                 /* Update the value we are going to post next time around. */
00171                 usValue++;
00172             }
00173         }
00174 
00175         /* Wait before we start posting again to ensure the consumer runs and
00176         empties the queue. */
00177         vTaskDelay( pollqPRODUCER_DELAY );
00178     }
00179 }  /*lint !e818 Function prototype must conform to API. */

static portTASK_FUNCTION_PROTO ( vPolledQueueConsumer  ,
pvParameters   
) [static]

static portTASK_FUNCTION_PROTO ( vPolledQueueProducer  ,
pvParameters   
) [static]

void vStartAltPolledQueueTasks ( unsigned portBASE_TYPE  uxPriority  ) 

Definition at line 112 of file AltPollQ.c.

References pollqQUEUE_SIZE, pollqSTACK_SIZE, portBASE_TYPE, portCHAR, portSHORT, vQueueAddToRegistry, xQueueCreate(), and xTaskCreate.

00113 {
00114 static xQueueHandle xPolledQueue;
00115 
00116     /* Create the queue used by the producer and consumer. */
00117     xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( unsigned portBASE_TYPE ) sizeof( unsigned portSHORT ) );
00118 
00119     /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
00120     in use.  The queue registry is provided as a means for kernel aware 
00121     debuggers to locate queues and has no purpose if a kernel aware debugger
00122     is not being used.  The call to vQueueAddToRegistry() will be removed
00123     by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is 
00124     defined to be less than 1. */
00125     vQueueAddToRegistry( xPolledQueue, ( signed portCHAR * ) "AltPollQueue" );
00126 
00127 
00128     /* Spawn the producer and consumer. */
00129     xTaskCreate( vPolledQueueConsumer, ( signed portCHAR * ) "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
00130     xTaskCreate( vPolledQueueProducer, ( signed portCHAR * ) "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );
00131 }

portBASE_TYPE xAreAltPollingQueuesStillRunning ( void   ) 

Definition at line 238 of file AltPollQ.c.

References pdFALSE, pdTRUE, pollqINITIAL_VALUE, portBASE_TYPE, xPollingConsumerCount, and xPollingProducerCount.

00239 {
00240 portBASE_TYPE xReturn;
00241 
00242     /* Check both the consumer and producer poll count to check they have both
00243     been changed since out last trip round.  We do not need a critical section
00244     around the check variables as this is called from a higher priority than
00245     the other tasks that access the same variables. */
00246     if( ( xPollingConsumerCount == pollqINITIAL_VALUE ) ||
00247         ( xPollingProducerCount == pollqINITIAL_VALUE )
00248       )
00249     {
00250         xReturn = pdFALSE;
00251     }
00252     else
00253     {
00254         xReturn = pdTRUE;
00255     }
00256 
00257     /* Set the check variables back down so we know if they have been
00258     incremented the next time around. */
00259     xPollingConsumerCount = pollqINITIAL_VALUE;
00260     xPollingProducerCount = pollqINITIAL_VALUE;
00261 
00262     return xReturn;
00263 }


Variable Documentation

volatile signed portBASE_TYPE xPollingConsumerCount = pollqINITIAL_VALUE [static]

volatile signed portBASE_TYPE xPollingProducerCount = pollqINITIAL_VALUE [static]


Generated on Thu Dec 17 20:02:00 2009 for AVR32 UC3 - FreeRTOS Real Time Kernel by  doxygen 1.5.5