+++ /dev/null
-/*\r
- FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.\r
- \r
-\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS tutorial books are available in pdf and paperback. *\r
- * Complete, revised, and edited pdf reference manuals are also *\r
- * available. *\r
- * *\r
- * Purchasing FreeRTOS documentation will not only help you, by *\r
- * ensuring you get running as quickly as possible and with an *\r
- * in-depth knowledge of how to use FreeRTOS, it will also help *\r
- * the FreeRTOS project to continue with its mission of providing *\r
- * professional grade, cross platform, de facto standard solutions *\r
- * for microcontrollers - completely free of charge! *\r
- * *\r
- * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
- * *\r
- * Thank you for using FreeRTOS, and thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- >>>NOTE<<< The modification to the GPL is included to allow you to\r
- distribute a combined work that includes FreeRTOS without being obliged to\r
- provide the source code for proprietary components outside of the FreeRTOS\r
- kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public\r
- License and the FreeRTOS license exception along with FreeRTOS; if not it\r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
- \r
- ***************************************************************************\r
- * *\r
- * Having a problem? Start by reading the FAQ "My application does *\r
- * not run, what could be wrong? *\r
- * *\r
- * http://www.FreeRTOS.org/FAQHelp.html *\r
- * *\r
- ***************************************************************************\r
-\r
- \r
- http://www.FreeRTOS.org - Documentation, training, latest information, \r
- license and contact details.\r
- \r
- http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
- including FreeRTOS+Trace - an indispensable productivity tool.\r
-\r
- Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
- the code with commercial support, indemnification, and middleware, under \r
- the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also\r
- provide a safety engineered and independently SIL3 certified version under \r
- the SafeRTOS brand: http://www.SafeRTOS.com.\r
-*/\r
-\r
-/*\r
- * This is a version of PollQ.c that uses the alternative (Alt) API.\r
- * \r
- * Creates two tasks that communicate over a single queue. One task acts as a\r
- * producer, the other a consumer.\r
- *\r
- * The producer loops for three iteration, posting an incrementing number onto the\r
- * queue each cycle. It then delays for a fixed period before doing exactly the\r
- * same again.\r
- *\r
- * The consumer loops emptying the queue. Each item removed from the queue is\r
- * checked to ensure it contains the expected value. When the queue is empty it\r
- * blocks for a fixed period, then does the same again.\r
- *\r
- * All queue access is performed without blocking. The consumer completely empties\r
- * the queue each time it runs so the producer should never find the queue full.\r
- *\r
- * An error is flagged if the consumer obtains an unexpected value or the producer\r
- * find the queue is full.\r
- */\r
-\r
-/*\r
-Changes from V2.0.0\r
-\r
- + Delay periods are now specified using variables and constants of\r
- portTickType rather than unsigned portLONG.\r
-*/\r
-\r
-#include <stdlib.h>\r
-\r
-/* Scheduler include files. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-#include "queue.h"\r
-\r
-/* Demo program include files. */\r
-#include "AltPollQ.h"\r
-\r
-#define pollqSTACK_SIZE configMINIMAL_STACK_SIZE\r
-#define pollqQUEUE_SIZE ( 10 )\r
-#define pollqPRODUCER_DELAY ( ( portTickType ) 200 / portTICK_RATE_MS )\r
-#define pollqCONSUMER_DELAY ( pollqPRODUCER_DELAY - ( portTickType ) ( 20 / portTICK_RATE_MS ) )\r
-#define pollqNO_DELAY ( ( portTickType ) 0 )\r
-#define pollqVALUES_TO_PRODUCE ( ( signed portBASE_TYPE ) 3 )\r
-#define pollqINITIAL_VALUE ( ( signed portBASE_TYPE ) 0 )\r
-\r
-/* The task that posts the incrementing number onto the queue. */\r
-static portTASK_FUNCTION_PROTO( vPolledQueueProducer, pvParameters );\r
-\r
-/* The task that empties the queue. */\r
-static portTASK_FUNCTION_PROTO( vPolledQueueConsumer, pvParameters );\r
-\r
-/* Variables that are used to check that the tasks are still running with no\r
-errors. */\r
-static volatile signed portBASE_TYPE xPollingConsumerCount = pollqINITIAL_VALUE, xPollingProducerCount = pollqINITIAL_VALUE;\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-void vStartAltPolledQueueTasks( unsigned portBASE_TYPE uxPriority )\r
-{\r
-static xQueueHandle xPolledQueue;\r
-\r
- /* Create the queue used by the producer and consumer. */\r
- xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( unsigned portBASE_TYPE ) sizeof( unsigned portSHORT ) );\r
-\r
- /* vQueueAddToRegistry() adds the queue to the queue registry, if one is\r
- in use. The queue registry is provided as a means for kernel aware \r
- debuggers to locate queues and has no purpose if a kernel aware debugger\r
- is not being used. The call to vQueueAddToRegistry() will be removed\r
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
- defined to be less than 1. */\r
- vQueueAddToRegistry( xPolledQueue, ( signed portCHAR * ) "AltPollQueue" );\r
-\r
-\r
- /* Spawn the producer and consumer. */\r
- xTaskCreate( vPolledQueueConsumer, ( signed portCHAR * ) "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );\r
- xTaskCreate( vPolledQueueProducer, ( signed portCHAR * ) "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( xTaskHandle * ) NULL );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static portTASK_FUNCTION( vPolledQueueProducer, pvParameters )\r
-{\r
-unsigned portSHORT usValue = ( unsigned portSHORT ) 0;\r
-signed portBASE_TYPE xError = pdFALSE, xLoop;\r
-\r
- #ifdef USE_STDIO\r
- void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );\r
- \r
- const portCHAR * const pcTaskStartMsg = "Alt polling queue producer task started.\r\n";\r
-\r
- /* Queue a message for printing to say the task has started. */\r
- vPrintDisplayMessage( &pcTaskStartMsg );\r
- #endif\r
-\r
- for( ;; )\r
- { \r
- for( xLoop = 0; xLoop < pollqVALUES_TO_PRODUCE; xLoop++ )\r
- {\r
- /* Send an incrementing number on the queue without blocking. */\r
- if( xQueueAltSendToBack( *( ( xQueueHandle * ) pvParameters ), ( void * ) &usValue, pollqNO_DELAY ) != pdPASS )\r
- {\r
- /* We should never find the queue full so if we get here there\r
- has been an error. */\r
- xError = pdTRUE;\r
- }\r
- else\r
- {\r
- if( xError == pdFALSE )\r
- {\r
- /* If an error has ever been recorded we stop incrementing the\r
- check variable. */\r
- portENTER_CRITICAL();\r
- xPollingProducerCount++;\r
- portEXIT_CRITICAL();\r
- }\r
-\r
- /* Update the value we are going to post next time around. */\r
- usValue++;\r
- }\r
- }\r
-\r
- /* Wait before we start posting again to ensure the consumer runs and\r
- empties the queue. */\r
- vTaskDelay( pollqPRODUCER_DELAY );\r
- }\r
-} /*lint !e818 Function prototype must conform to API. */\r
-/*-----------------------------------------------------------*/\r
-\r
-static portTASK_FUNCTION( vPolledQueueConsumer, pvParameters )\r
-{\r
-unsigned portSHORT usData, usExpectedValue = ( unsigned portSHORT ) 0;\r
-signed portBASE_TYPE xError = pdFALSE;\r
-\r
- #ifdef USE_STDIO\r
- void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );\r
- \r
- const portCHAR * const pcTaskStartMsg = "Alt blocking queue consumer task started.\r\n";\r
-\r
- /* Queue a message for printing to say the task has started. */\r
- vPrintDisplayMessage( &pcTaskStartMsg );\r
- #endif\r
-\r
- for( ;; )\r
- { \r
- /* Loop until the queue is empty. */\r
- while( uxQueueMessagesWaiting( *( ( xQueueHandle * ) pvParameters ) ) )\r
- {\r
- if( xQueueAltReceive( *( ( xQueueHandle * ) pvParameters ), &usData, pollqNO_DELAY ) == pdPASS )\r
- {\r
- if( usData != usExpectedValue )\r
- {\r
- /* This is not what we expected to receive so an error has\r
- occurred. */\r
- xError = pdTRUE;\r
-\r
- /* Catch-up to the value we received so our next expected\r
- value should again be correct. */\r
- usExpectedValue = usData;\r
- }\r
- else\r
- {\r
- if( xError == pdFALSE )\r
- {\r
- /* Only increment the check variable if no errors have\r
- occurred. */\r
- portENTER_CRITICAL();\r
- xPollingConsumerCount++;\r
- portEXIT_CRITICAL();\r
- }\r
- }\r
-\r
- /* Next time round we would expect the number to be one higher. */\r
- usExpectedValue++;\r
- }\r
- }\r
-\r
- /* Now the queue is empty we block, allowing the producer to place more\r
- items in the queue. */\r
- vTaskDelay( pollqCONSUMER_DELAY );\r
- }\r
-} /*lint !e818 Function prototype must conform to API. */\r
-/*-----------------------------------------------------------*/\r
-\r
-/* This is called to check that all the created tasks are still running with no errors. */\r
-portBASE_TYPE xAreAltPollingQueuesStillRunning( void )\r
-{\r
-portBASE_TYPE xReturn;\r
-\r
- /* Check both the consumer and producer poll count to check they have both\r
- been changed since out last trip round. We do not need a critical section\r
- around the check variables as this is called from a higher priority than\r
- the other tasks that access the same variables. */\r
- if( ( xPollingConsumerCount == pollqINITIAL_VALUE ) ||\r
- ( xPollingProducerCount == pollqINITIAL_VALUE )\r
- )\r
- {\r
- xReturn = pdFALSE;\r
- }\r
- else\r
- {\r
- xReturn = pdTRUE;\r
- }\r
-\r
- /* Set the check variables back down so we know if they have been\r
- incremented the next time around. */\r
- xPollingConsumerCount = pollqINITIAL_VALUE;\r
- xPollingProducerCount = pollqINITIAL_VALUE;\r
-\r
- return xReturn;\r
-}\r