diff --git a/FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/Full-Demo/UARTCommandConsole.c b/FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/Full-Demo/UARTCommandConsole.c index 73aa0178e..fe54b0ed5 100644 --- a/FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/Full-Demo/UARTCommandConsole.c +++ b/FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/Full-Demo/UARTCommandConsole.c @@ -1,54 +1,65 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd. + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * - * FreeRTOS tutorial books are available in pdf and paperback. * - * Complete, revised, and edited pdf reference manuals are also * - * available. * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * * * - * Purchasing FreeRTOS documentation will not only help you, by * - * ensuring you get running as quickly as possible and with an * - * in-depth knowledge of how to use FreeRTOS, it will also help * - * the FreeRTOS project to continue with its mission of providing * - * professional grade, cross platform, de facto standard solutions * - * for microcontrollers - completely free of charge! * + * 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 * * * - * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * - * * - * Thank you for using FreeRTOS, and thank you for your support! * + * 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. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + 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! - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. + *************************************************************************** + * * + * 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.SafeRTOS.com - A version that is certified for use in safety - critical systems. + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + 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! */ /* Standard includes. */ diff --git a/FreeRTOS/Demo/Common/Minimal/BlockQ.c b/FreeRTOS/Demo/Common/Minimal/BlockQ.c index 43f5ac70c..ee51b8b5e 100644 --- a/FreeRTOS/Demo/Common/Minimal/BlockQ.c +++ b/FreeRTOS/Demo/Common/Minimal/BlockQ.c @@ -86,15 +86,6 @@ * */ -/* - -Changes from V4.1.1 - - + The second set of tasks were created the wrong way around. This has been - corrected. -*/ - - #include /* Scheduler include files. */ diff --git a/FreeRTOS/Demo/Common/Minimal/QueueSet.c b/FreeRTOS/Demo/Common/Minimal/QueueSet.c index b1c40c173..b38df3c2e 100644 --- a/FreeRTOS/Demo/Common/Minimal/QueueSet.c +++ b/FreeRTOS/Demo/Common/Minimal/QueueSet.c @@ -387,6 +387,9 @@ static void prvQueueSetReceivingTask( void *pvParameters ) unsigned long ulReceived; xQueueHandle xActivatedQueue; + /* Remove compiler warnings. */ + ( void ) pvParameters; + /* Create the queues and add them to the queue set before resuming the Tx task. */ prvSetupTest(); diff --git a/FreeRTOS/Demo/WIN32-MSVC/main_full.c b/FreeRTOS/Demo/WIN32-MSVC/main_full.c index a08b3dcdb..308d55cfd 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/main_full.c +++ b/FreeRTOS/Demo/WIN32-MSVC/main_full.c @@ -161,6 +161,11 @@ static void prvTestTask( void *pvParameters ); */ static void prvDemonstrateTaskStateAndHandleGetFunctions( void ); +/* + * A task to demonstrate the use of the xQueueSpacesAvailable() function. + */ +static void prvDemoQueueSpaceFunctions( void *pvParameters ); + /*-----------------------------------------------------------*/ /* The variable into which error messages are latched. */ @@ -190,7 +195,8 @@ int main_full( void ) vStartCountingSemaphoreTasks(); vStartDynamicPriorityTasks(); vStartQueueSetTasks(); - vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY ); + vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY ); + xTaskCreate( prvDemoQueueSpaceFunctions, ( signed char * ) "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); /* The suicide tasks must be created last as they need to know how many tasks were running prior to their creation. This then allows them to @@ -453,4 +459,69 @@ xTaskHandle xTestTask; } /*-----------------------------------------------------------*/ +static void prvDemoQueueSpaceFunctions( void *pvParameters ) +{ +xQueueHandle xQueue = NULL; +const unsigned portBASE_TYPE uxQueueLength = 10; +unsigned portBASE_TYPE uxReturn, x; + + /* Remove compiler warnings. */ + ( void ) pvParameters; + + /* Create the queue that will be used. Nothing is actually going to be + sent or received so the queue item size is set to 0. */ + xQueue = xQueueCreate( uxQueueLength, 0 ); + configASSERT( xQueue ); + + for( ;; ) + { + for( x = 0; x < uxQueueLength; x++ ) + { + /* Ask how many messages are available... */ + uxReturn = uxQueueMessagesWaiting( xQueue ); + + /* Check the number of messages being reported as being available + is as expected, and force an assert if not. */ + if( uxReturn != x ) + { + /* xQueue cannot be NULL so this is deliberately causing an + assert to be triggered as there is an error. */ + configASSERT( xQueue == NULL ); + } + + /* Ask how many spaces remain in the queue... */ + uxReturn = uxQueueSpacesAvailable( xQueue ); + + /* Check the number of spaces being reported as being available + is as expected, and force an assert if not. */ + if( uxReturn != ( uxQueueLength - x ) ) + { + /* xQueue cannot be NULL so this is deliberately causing an + assert to be triggered as there is an error. */ + configASSERT( xQueue == NULL ); + } + + /* Fill one more space in the queue. */ + xQueueSendToBack( xQueue, NULL, 0 ); + } + + /* Perform the same check while the queue is full. */ + uxReturn = uxQueueMessagesWaiting( xQueue ); + if( uxReturn != uxQueueLength ) + { + configASSERT( xQueue == NULL ); + } + + uxReturn = uxQueueSpacesAvailable( xQueue ); + + if( uxReturn != 0 ) + { + configASSERT( xQueue == NULL ); + } + + /* The queue is full, start again. */ + xQueueReset( xQueue ); + } +} + diff --git a/FreeRTOS/Source/include/FreeRTOS.h b/FreeRTOS/Source/include/FreeRTOS.h index ee0a186cf..7b84e0a80 100644 --- a/FreeRTOS/Source/include/FreeRTOS.h +++ b/FreeRTOS/Source/include/FreeRTOS.h @@ -511,6 +511,14 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define traceTIMER_COMMAND_RECEIVED( pxTimer, xMessageID, xMessageValue ) #endif +#ifndef traceMALLOC + #define traceMALLOC( pvAddress, uiSize ) +#endif + +#ifndef traceFREE + #define traceFREE( pvAddress, uiSize ) +#endif + #ifndef configGENERATE_RUN_TIME_STATS #define configGENERATE_RUN_TIME_STATS 0 #endif diff --git a/FreeRTOS/Source/portable/GCC/ARM_CM0/port.c b/FreeRTOS/Source/portable/GCC/ARM_CM0/port.c index 6966c848e..5aef176cf 100644 --- a/FreeRTOS/Source/portable/GCC/ARM_CM0/port.c +++ b/FreeRTOS/Source/portable/GCC/ARM_CM0/port.c @@ -107,6 +107,11 @@ void vPortSVCHandler( void ) __attribute__ (( naked )); */ static void vPortStartFirstTask( void ) __attribute__ (( naked )); +/* + * Used to catch tasks that attempt to return from their implementing function. + */ +static void prvTaskExitError( void ); + /*-----------------------------------------------------------*/ /* @@ -120,7 +125,9 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* PC */ - pxTopOfStack -= 6; /* LR, R12, R3..R1 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) prvTaskExitError; /* LR */ + pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */ pxTopOfStack -= 8; /* R11..R4. */ @@ -128,6 +135,20 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE } /*-----------------------------------------------------------*/ +static void prvTaskExitError( void ) +{ + /* A function that implements a task must not exit or attempt to return to + its caller as there is nothing to return to. If a task wants to exit it + should instead call vTaskDelete( NULL ). + + Artificially force an assert() to be triggered if configASSERT() is + defined, then stop here so application writers can catch the error. */ + configASSERT( uxCriticalNesting == ~0UL ); + portDISABLE_INTERRUPTS(); + for( ;; ); +} +/*-----------------------------------------------------------*/ + void vPortSVCHandler( void ) { __asm volatile ( @@ -250,6 +271,9 @@ void vClearInterruptMaskFromISR( unsigned long ulMask ) " msr PRIMASK, r0 \n" " bx lr " ); + + /* Just to avoid compiler warning. */ + ( void ) ulMask; } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c b/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c index 6b3cc4162..bf5b33469 100644 --- a/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c +++ b/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c @@ -113,6 +113,11 @@ void xPortSysTickHandler( void ); */ extern void vPortStartFirstTask( void ); +/* + * Used to catch tasks that attempt to return from their implementing function. + */ +static void prvTaskExitError( void ); + /*-----------------------------------------------------------*/ /* @@ -126,7 +131,9 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* PC */ - pxTopOfStack -= 6; /* LR, R12, R3..R1 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) prvTaskExitError; /* LR */ + pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */ pxTopOfStack -= 8; /* R11..R4. */ @@ -134,6 +141,20 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE } /*-----------------------------------------------------------*/ +static void prvTaskExitError( void ) +{ + /* A function that implements a task must not exit or attempt to return to + its caller as there is nothing to return to. If a task wants to exit it + should instead call vTaskDelete( NULL ). + + Artificially force an assert() to be triggered if configASSERT() is + defined, then stop here so application writers can catch the error. */ + configASSERT( uxCriticalNesting == ~0UL ); + portDISABLE_INTERRUPTS(); + for( ;; ); +} +/*-----------------------------------------------------------*/ + /* * See header file for description. */ diff --git a/FreeRTOS/Source/portable/RVDS/ARM_CM0/port.c b/FreeRTOS/Source/portable/RVDS/ARM_CM0/port.c index 2c0169f7e..86bbc7b13 100644 --- a/FreeRTOS/Source/portable/RVDS/ARM_CM0/port.c +++ b/FreeRTOS/Source/portable/RVDS/ARM_CM0/port.c @@ -110,6 +110,11 @@ void vPortSVCHandler( void ); */ static void prvPortStartFirstTask( void ); +/* + * Used to catch tasks that attempt to return from their implementing function. + */ +static void prvTaskExitError( void ); + /*-----------------------------------------------------------*/ /* @@ -123,7 +128,9 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* PC */ - pxTopOfStack -= 6; /* LR, R12, R3..R1 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) prvTaskExitError; /* LR */ + pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */ pxTopOfStack -= 8; /* R11..R4. */ @@ -131,6 +138,20 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE } /*-----------------------------------------------------------*/ +static void prvTaskExitError( void ) +{ + /* A function that implements a task must not exit or attempt to return to + its caller as there is nothing to return to. If a task wants to exit it + should instead call vTaskDelete( NULL ). + + Artificially force an assert() to be triggered if configASSERT() is + defined, then stop here so application writers can catch the error. */ + configASSERT( uxCriticalNesting == ~0UL ); + portDISABLE_INTERRUPTS(); + for( ;; ); +} +/*-----------------------------------------------------------*/ + __asm void vPortSVCHandler( void ) { extern pxCurrentTCB; diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index 417ccd42a..359072964 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c @@ -89,7 +89,7 @@ privileged Vs unprivileged linkage and placement. */ uxTaskGetSystemState() function. Note the formatting functions are provided for convenience only, and are NOT considered part of the kernel. */ #include -#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) ) */ +#endif /* configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) */ /* Sanity check the configuration. */ #if configUSE_TICKLESS_IDLE != 0 @@ -1196,7 +1196,11 @@ tskTCB * pxNewTCB; if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE ) { - xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ); + if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) + { + xYieldRequired = pdTRUE; + } + ( void ) uxListRemove( &( pxTCB->xGenericListItem ) ); prvAddTaskToReadyList( pxTCB ); } @@ -1250,12 +1254,17 @@ portBASE_TYPE xReturn; before or during the call to xPortStartScheduler(). The stacks of the created tasks contain a status word with interrupts switched on so interrupts will automatically get re-enabled when the first task - starts to run. - - STEPPING THROUGH HERE USING A DEBUGGER CAN CAUSE BIG PROBLEMS IF THE - DEBUGGER ALLOWS INTERRUPTS TO BE PROCESSED. */ + starts to run. */ portDISABLE_INTERRUPTS(); + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + /* Switch Newlib's _impure_ptr variable to point to the _reent + structure specific to the task that will run first. */ + _impure_ptr = &( pxCurrentTCB->xNewLib_reent ); + } + #endif /* configUSE_NEWLIB_REENTRANT */ + xSchedulerRunning = pdTRUE; xTickCount = ( portTickType ) 0U; @@ -1337,7 +1346,6 @@ signed portBASE_TYPE xTaskResumeAll( void ) { tskTCB *pxTCB; portBASE_TYPE xAlreadyYielded = pdFALSE; -portBASE_TYPE xYieldRequired = pdFALSE; /* If uxSchedulerSuspended is zero then this function does not match a previous call to vTaskSuspendAll(). */ @@ -1369,7 +1377,7 @@ portBASE_TYPE xYieldRequired = pdFALSE; the current task then we should yield. */ if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) { - xYieldRequired = pdTRUE; + xYieldPending = pdTRUE; } } @@ -1382,16 +1390,15 @@ portBASE_TYPE xYieldRequired = pdFALSE; { if( xTaskIncrementTick() != pdFALSE ) { - xYieldRequired = pdTRUE; + xYieldPending = pdTRUE; } --uxPendedTicks; } } - if( ( xYieldRequired == pdTRUE ) || ( xYieldPending == pdTRUE ) ) + if( xYieldPending == pdTRUE ) { xAlreadyYielded = pdTRUE; - xYieldPending = pdFALSE; portYIELD_WITHIN_API(); } } @@ -1519,7 +1526,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) portALT_GET_RUN_TIME_COUNTER_VALUE( ( *pulTotalRunTime ) ); #else *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE(); - #endif + #endif } } #else @@ -1678,6 +1685,17 @@ portBASE_TYPE xSwitchRequired = pdFALSE; } } #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */ + + #if ( configUSE_TICK_HOOK == 1 ) + { + /* Guard against the tick hook being called when the pended tick + count is being unwound (when the scheduler is being unlocked). */ + if( uxPendedTicks == ( unsigned portBASE_TYPE ) 0U ) + { + vApplicationTickHook(); + } + } + #endif /* configUSE_TICK_HOOK */ } else { @@ -1692,16 +1710,14 @@ portBASE_TYPE xSwitchRequired = pdFALSE; #endif } - #if ( configUSE_TICK_HOOK == 1 ) + #if ( configUSE_PREEMPTION == 1 ) { - /* Guard against the tick hook being called when the missed tick - count is being unwound (when the scheduler is being unlocked). */ - if( uxPendedTicks == ( unsigned portBASE_TYPE ) 0U ) + if( xYieldPending != pdFALSE ) { - vApplicationTickHook(); + xSwitchRequired = pdTRUE; } } - #endif /* configUSE_TICK_HOOK */ + #endif /* configUSE_PREEMPTION */ return xSwitchRequired; } @@ -1804,6 +1820,7 @@ void vTaskSwitchContext( void ) } else { + xYieldPending = pdFALSE; traceTASK_SWITCHED_OUT(); #if ( configGENERATE_RUN_TIME_STATS == 1 ) @@ -1981,6 +1998,10 @@ portBASE_TYPE xReturn; the calling task to know if it should force a context switch now. */ xReturn = pdTRUE; + + /* Mark that a yield is pending in case the user is not using the + "xHigherPriorityTaskWoken" parameter to an ISR safe FreeRTOS function. */ + xYieldPending = pdTRUE; } else { diff --git a/FreeRTOS/Source/timers.c b/FreeRTOS/Source/timers.c index 0414604f1..f9f50b4bd 100644 --- a/FreeRTOS/Source/timers.c +++ b/FreeRTOS/Source/timers.c @@ -569,6 +569,13 @@ portTickType xTimeNow; case tmrCOMMAND_CHANGE_PERIOD : pxTimer->xTimerPeriodInTicks = xMessage.xMessageValue; configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) ); + + /* The new period does not really have a reference, and can be + longer or shorter than the old one. The command time is + therefore set to the current time, and as the period cannot be + zero the next expiry time can only be in the future, meaning + (unlike for the xTimerStart() case above) there is no fail case + that needs to be handled here. */ ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow ); break;