X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=FreeRTOS%2FDemo%2FCommon%2FMinimal%2FBlockQ.c;h=93ce0d36aeb150f5f7c182dece484030217e17a2;hb=97fffb1d1d396472be491bbdb38503c7dc2ba44d;hp=b9b1adb8743bd5e8595809d49288595df2447f42;hpb=3d0d1ed95c06f04774d003858a3de19aef948ace;p=freertos diff --git a/FreeRTOS/Demo/Common/Minimal/BlockQ.c b/FreeRTOS/Demo/Common/Minimal/BlockQ.c index b9b1adb87..93ce0d36a 100644 --- a/FreeRTOS/Demo/Common/Minimal/BlockQ.c +++ b/FreeRTOS/Demo/Common/Minimal/BlockQ.c @@ -1,67 +1,29 @@ /* - FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. - All rights reserved - - VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. - - *************************************************************************** - * * - * FreeRTOS provides completely free yet professionally developed, * - * robust, strictly quality controlled, supported, and cross * - * platform software that has become a de facto standard. * - * * - * Help yourself get started quickly and support the FreeRTOS * - * project by purchasing a FreeRTOS tutorial book, reference * - * manual, or both from: http://www.FreeRTOS.org/Documentation * - * * - * Thank you! * - * * - *************************************************************************** - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. - - >>! NOTE: The modification to the GPL is included to allow you to distribute - >>! a combined work that includes FreeRTOS without being obliged to provide - >>! the source code for proprietary components outside of the FreeRTOS - >>! kernel. - - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. Full license text is available from the following - link: http://www.freertos.org/a00114.html - - 1 tab == 4 spaces! - - *************************************************************************** - * * - * Having a problem? Start by reading the FAQ "My application does * - * not run, what could be wrong?" * - * * - * http://www.FreeRTOS.org/FAQHelp.html * - * * - *************************************************************************** - - http://www.FreeRTOS.org - Documentation, books, training, latest versions, - license and Real Time Engineers Ltd. contact details. - - http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool, a DOS - compatible FAT file system, and our tiny thread aware UDP/IP stack. - - http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High - Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS - licenses offer ticketed support, indemnification and middleware. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. - - 1 tab == 4 spaces! -*/ + * FreeRTOS Kernel V10.1.0 + * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ /* * Creates six tasks that operate on three queues as follows: @@ -100,11 +62,15 @@ #define blckqSTACK_SIZE configMINIMAL_STACK_SIZE #define blckqNUM_TASK_SETS ( 3 ) +#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This example cannot be used if dynamic allocation is not allowed. +#endif + /* Structure used to pass parameters to the blocking queue tasks. */ typedef struct BLOCKING_QUEUE_PARAMETERS { - xQueueHandle xQueue; /*< The queue to be used by the task. */ - portTickType xBlockTime; /*< The block time to use on queue reads/writes. */ + QueueHandle_t xQueue; /*< The queue to be used by the task. */ + TickType_t xBlockTime; /*< The block time to use on queue reads/writes. */ volatile short *psCheckVariable; /*< Incremented on each successful cycle to check the task is still running. */ } xBlockingQueueParameters; @@ -118,22 +84,22 @@ static portTASK_FUNCTION_PROTO( vBlockingQueueConsumer, pvParameters ); /* Variables which are incremented each time an item is removed from a queue, and found to be the expected value. These are used to check that the tasks are still running. */ -static volatile short sBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( unsigned short ) 0, ( unsigned short ) 0, ( unsigned short ) 0 }; +static volatile short sBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 }; /* Variable which are incremented each time an item is posted on a queue. These are used to check that the tasks are still running. */ -static volatile short sBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( unsigned short ) 0, ( unsigned short ) 0, ( unsigned short ) 0 }; +static volatile short sBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 }; /*-----------------------------------------------------------*/ -void vStartBlockingQueueTasks( unsigned portBASE_TYPE uxPriority ) +void vStartBlockingQueueTasks( UBaseType_t uxPriority ) { xBlockingQueueParameters *pxQueueParameters1, *pxQueueParameters2; xBlockingQueueParameters *pxQueueParameters3, *pxQueueParameters4; xBlockingQueueParameters *pxQueueParameters5, *pxQueueParameters6; -const unsigned portBASE_TYPE uxQueueSize1 = 1, uxQueueSize5 = 5; -const portTickType xBlockTime = ( portTickType ) 1000 / portTICK_RATE_MS; -const portTickType xDontBlock = ( portTickType ) 0; +const UBaseType_t uxQueueSize1 = 1, uxQueueSize5 = 5; +const TickType_t xBlockTime = pdMS_TO_TICKS( ( TickType_t ) 1000 ); +const TickType_t xDontBlock = ( TickType_t ) 0; /* Create the first two tasks as described at the top of the file. */ @@ -142,7 +108,7 @@ const portTickType xDontBlock = ( portTickType ) 0; /* Create the queue used by the first two tasks to pass the incrementing number. Pass a pointer to the queue in the parameter structure. */ - pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) ); + pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) ); /* The consumer is created first so gets a block time as described above. */ pxQueueParameters1->xBlockTime = xBlockTime; @@ -168,8 +134,8 @@ const portTickType xDontBlock = ( portTickType ) 0; /* Note the producer has a lower priority than the consumer when the tasks are spawned. */ - xTaskCreate( vBlockingQueueConsumer, ( signed char * ) "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL ); - xTaskCreate( vBlockingQueueProducer, ( signed char * ) "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL ); + xTaskCreate( vBlockingQueueConsumer, "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL ); + xTaskCreate( vBlockingQueueProducer, "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL ); @@ -177,7 +143,7 @@ const portTickType xDontBlock = ( portTickType ) 0; the same mechanism but reverses the task priorities. */ pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); - pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) ); + pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) ); pxQueueParameters3->xBlockTime = xDontBlock; pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] ); @@ -186,15 +152,15 @@ const portTickType xDontBlock = ( portTickType ) 0; pxQueueParameters4->xBlockTime = xBlockTime; pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] ); - xTaskCreate( vBlockingQueueConsumer, ( signed char * ) "QConsB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL ); - xTaskCreate( vBlockingQueueProducer, ( signed char * ) "QProdB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL ); + xTaskCreate( vBlockingQueueConsumer, "QConsB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL ); + xTaskCreate( vBlockingQueueProducer, "QProdB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL ); /* Create the last two tasks as described above. The mechanism is again just the same. This time both parameter structures are given a block time. */ pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); - pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) ); + pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( UBaseType_t ) sizeof( uint16_t ) ); pxQueueParameters5->xBlockTime = xBlockTime; pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] ); @@ -203,14 +169,14 @@ const portTickType xDontBlock = ( portTickType ) 0; pxQueueParameters6->xBlockTime = xBlockTime; pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] ); - xTaskCreate( vBlockingQueueProducer, ( signed char * ) "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL ); - xTaskCreate( vBlockingQueueConsumer, ( signed char * ) "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL ); + xTaskCreate( vBlockingQueueProducer, "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL ); + xTaskCreate( vBlockingQueueConsumer, "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL ); } /*-----------------------------------------------------------*/ static portTASK_FUNCTION( vBlockingQueueProducer, pvParameters ) { -unsigned short usValue = 0; +uint16_t usValue = 0; xBlockingQueueParameters *pxQueueParameters; short sErrorEverOccurred = pdFALSE; @@ -245,7 +211,7 @@ short sErrorEverOccurred = pdFALSE; static portTASK_FUNCTION( vBlockingQueueConsumer, pvParameters ) { -unsigned short usData, usExpectedValue = 0; +uint16_t usData, usExpectedValue = 0; xBlockingQueueParameters *pxQueueParameters; short sErrorEverOccurred = pdFALSE; @@ -290,11 +256,11 @@ short sErrorEverOccurred = pdFALSE; /*-----------------------------------------------------------*/ /* This is called to check that all the created tasks are still running. */ -portBASE_TYPE xAreBlockingQueuesStillRunning( void ) +BaseType_t xAreBlockingQueuesStillRunning( void ) { -static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( unsigned short ) 0, ( unsigned short ) 0, ( unsigned short ) 0 }; -static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( unsigned short ) 0, ( unsigned short ) 0, ( unsigned short ) 0 }; -portBASE_TYPE xReturn = pdPASS, xTasks; +static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 }; +static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 }; +BaseType_t xReturn = pdPASS, xTasks; /* Not too worried about mutual exclusion on these variables as they are 16 bits and we are only reading them. We also only care to see if they have