]> git.sur5r.net Git - freertos/commitdiff
Changes to the FreeRTOS code:
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 20 Dec 2015 13:44:21 +0000 (13:44 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 20 Dec 2015 13:44:21 +0000 (13:44 +0000)
+ Introduced xTaskCreateStatic() to allow tasks to be created without any dynamic memory allocation.
+ When a task notification is used to unblock a task from an ISR, but the xHigherPriorityTaskWoken parameter is not used, then pend a context switch to occur during the next tick interrupt.

Demo application changes:
+ Updated TaskNotify.c to test the case where a task is unblocked by an ISR, but does not use its xHigherPriorityTaskWoken parameter.
+ Updated the Win32 MSVC project to test statically allocated tasks being created and deleted.
+ Introduced StaticAllocation.c standard demo task.

git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2397 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

15 files changed:
FreeRTOS/Demo/Common/Minimal/StaticAllocation.c [new file with mode: 0644]
FreeRTOS/Demo/Common/Minimal/TaskNotify.c
FreeRTOS/Demo/Common/Minimal/death.c
FreeRTOS/Demo/Common/Minimal/recmutex.c
FreeRTOS/Demo/Common/include/StaticAllocation.h [new file with mode: 0644]
FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h
FreeRTOS/Demo/WIN32-MSVC/WIN32.vcxproj
FreeRTOS/Demo/WIN32-MSVC/WIN32.vcxproj.filters
FreeRTOS/Demo/WIN32-MSVC/main.c
FreeRTOS/Demo/WIN32-MSVC/main_full.c
FreeRTOS/Source/include/FreeRTOS.h
FreeRTOS/Source/include/task.h
FreeRTOS/Source/queue.c
FreeRTOS/Source/tasks.c
FreeRTOS/Source/timers.c

diff --git a/FreeRTOS/Demo/Common/Minimal/StaticAllocation.c b/FreeRTOS/Demo/Common/Minimal/StaticAllocation.c
new file mode 100644 (file)
index 0000000..a957aee
--- /dev/null
@@ -0,0 +1,310 @@
+/*\r
+    FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.\r
+    All rights reserved\r
+\r
+    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\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
+\r
+    ***************************************************************************\r
+    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
+    >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
+    >>!   obliged to provide the source code for proprietary components     !<<\r
+    >>!   outside of the FreeRTOS kernel.                                   !<<\r
+    ***************************************************************************\r
+\r
+    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
+    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
+    link: http://www.freertos.org/a00114.html\r
+\r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
+     *                                                                       *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
+     *                                                                       *\r
+    ***************************************************************************\r
+\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\r
+\r
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+    compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+\r
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial middleware.\r
+\r
+    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+    engineered and independently SIL3 certified version for use in safety and\r
+    mission critical applications that require provable dependability.\r
+\r
+    1 tab == 4 spaces!\r
+*/\r
+\r
+\r
+/*\r
+ * Demonstrates how to create FreeRTOS objects using pre-allocated memory,\r
+ * rather than the normal dynamically allocated memory.  Currently only tasks\r
+ * are being allocated statically.\r
+ *\r
+ * Two buffers are required by a task - one that is used by the task as its\r
+ * stack, and one that holds the task's control block (TCB).\r
+ * prvStaticallyAllocatedTaskCreator() creates and deletes tasks with all\r
+ * possible combinations of statically allocated and dynamically allocated\r
+ * stacks and TCBs.\r
+ */\r
+\r
+/* Scheduler include files. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+\r
+/* Demo program include files. */\r
+#include "StaticAllocation.h"\r
+\r
+#define staticTASK_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
+\r
+/*\r
+ * A task that is created multiple times, using both statically and dynamically\r
+ * allocated stack and TCB.\r
+ */\r
+static void prvStaticallyAllocatedTask( void *pvParameters );\r
+\r
+/*\r
+ * The task that creates and deletes the prvStaticallyAllocatedTask() task,\r
+ * using various priorities, and sometimes with statically and sometimes\r
+ * dynamically allocated stack and TCB.\r
+ */\r
+static void prvStaticallyAllocatedTaskCreator( void *pvParameters );\r
+\r
+/*\r
+ * Utility function to create pseudo random numbers.\r
+ */\r
+static UBaseType_t prvRand( void );\r
+\r
+/*\r
+ * The task that creates and deletes other tasks has to delay occasionally to\r
+ * ensure lower priority tasks are not starved of processing time.  A pseudo\r
+ * random delay time is used just to add a little bit of randomisation into the\r
+ * execution pattern.  prvGetNextDelayTime() generates the pseudo random delay.\r
+ */\r
+static TickType_t prvGetNextDelayTime( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* DummyTCB_t is a publicly accessible structure that has the same size and\r
+alignment requirements as the real TCB structure.  It is provided as a mechanism\r
+for applications to know the size of the TCB (which is dependent on the\r
+architecture and configuration file settings) without breaking the strict data\r
+hiding policy by exposing the real TCB.  This DummyTCB_t variable is passed into\r
+the xTaskCreateStatic() function, and will hold the task's TCB. */\r
+static DummyTCB_t xTCBBuffer;\r
+\r
+/* This is the stack that will be used by the task.  The alignment requirements\r
+for the stack depend on the architecture, and the method of forcing an alignment\r
+is dependent on the compiler, but any bad alignment is corrected inside the\r
+FreeRTOS code. */\r
+static StackType_t uxStackBuffer[ configMINIMAL_STACK_SIZE ];\r
+\r
+/* Used by the pseudo random number generating function. */\r
+static uint32_t ulNextRand = 0;\r
+\r
+/* Used so a check task can ensure this test is still executing, and not\r
+stalled. */\r
+static volatile UBaseType_t uxCycleCounter = 0;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void vStartStaticallyAllocatedTasks( void  )\r
+{\r
+       /* Create a single task, which then repeatedly creates and deletes the\r
+       task implemented by prvStaticallyAllocatedTask() at various different\r
+       priorities, and both with and without statically allocated TCB and stack. */\r
+       xTaskCreate( prvStaticallyAllocatedTaskCreator, "StatCreate", configMINIMAL_STACK_SIZE, NULL, staticTASK_PRIORITY, NULL );\r
+\r
+       /* Pseudo seed the random number generator. */\r
+       ulNextRand = ( uint32_t ) prvRand;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvStaticallyAllocatedTaskCreator( void *pvParameters )\r
+{\r
+TaskHandle_t xCreatedTask;\r
+BaseType_t xReturned;\r
+\r
+       /* Avoid compiler warnings. */\r
+       ( void ) pvParameters;\r
+\r
+       for( ;; )\r
+       {\r
+               /* Create the task.  xTaskCreateStatic() has two more parameters than\r
+               the usual xTaskCreate() function.  The first new parameter is a pointer to\r
+               the pre-allocated stack.  The second new parameter is a pointer to the\r
+               DummyTCB_t structure that will hold the task's TCB.  If either pointer is\r
+               passed as NULL then the respective object will be allocated dynamically as\r
+               if xTaskCreate() had been called. */\r
+               xReturned = xTaskCreateStatic(\r
+                                                       prvStaticallyAllocatedTask, /* Function that implements the task. */\r
+                                                       "Static",                                       /* Human readable name for the task. */\r
+                                                       configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
+                                                       NULL,                                           /* Parameter to pass into the task. */\r
+                                                       tskIDLE_PRIORITY,                       /* The priority of the task. */\r
+                                                       &xCreatedTask,                          /* Handle of the task being created. */\r
+                                                       &( uxStackBuffer[ 0 ] ),        /* The buffer to use as the task's stack. */\r
+                                                       &xTCBBuffer );                          /* The variable that will hold that task's TCB. */\r
+\r
+               /* Check the task was created correctly, then delete the task. */\r
+               configASSERT( xReturned == pdPASS );\r
+               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+               vTaskDelete( xCreatedTask );\r
+\r
+               /* Ensure lower priority tasks get CPU time. */\r
+               vTaskDelay( prvGetNextDelayTime() );\r
+\r
+               /* Create and delete the task a few times again - testing both static and\r
+               dynamic allocation for the stack and TCB. */\r
+               xReturned = xTaskCreateStatic(\r
+                                                       prvStaticallyAllocatedTask, /* Function that implements the task. */\r
+                                                       "Static",                                       /* Human readable name for the task. */\r
+                                                       configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
+                                                       NULL,                                           /* Parameter to pass into the task. */\r
+                                                       staticTASK_PRIORITY + 1,        /* The priority of the task. */\r
+                                                       &xCreatedTask,                          /* Handle of the task being created. */\r
+                                                       NULL,                                           /* This time, dynamically allocate the stack. */\r
+                                                       &xTCBBuffer );                          /* The variable that will hold that task's TCB. */\r
+\r
+               configASSERT( xReturned == pdPASS );\r
+               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+               vTaskDelete( xCreatedTask );\r
+\r
+               /* Just to show the check task that this task is still executing. */\r
+               uxCycleCounter++;\r
+\r
+               /* Ensure lower priority tasks get CPU time. */\r
+               vTaskDelay( prvGetNextDelayTime() );\r
+\r
+               xReturned = xTaskCreateStatic(\r
+                                                       prvStaticallyAllocatedTask, /* Function that implements the task. */\r
+                                                       "Static",                                       /* Human readable name for the task. */\r
+                                                       configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
+                                                       NULL,                                           /* Parameter to pass into the task. */\r
+                                                       staticTASK_PRIORITY - 1,        /* The priority of the task. */\r
+                                                       &xCreatedTask,                          /* Handle of the task being created. */\r
+                                                       &( uxStackBuffer[ 0 ] ),        /* The buffer to use as the task's stack. */\r
+                                                       NULL );                                         /* This time dynamically allocate the TCB. */\r
+\r
+               configASSERT( xReturned == pdPASS );\r
+               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+               vTaskDelete( xCreatedTask );\r
+\r
+               /* Ensure lower priority tasks get CPU time. */\r
+               vTaskDelay( prvGetNextDelayTime() );\r
+\r
+               xReturned = xTaskCreateStatic(\r
+                                                       prvStaticallyAllocatedTask, /* Function that implements the task. */\r
+                                                       "Static",                                       /* Human readable name for the task. */\r
+                                                       configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
+                                                       NULL,                                           /* Parameter to pass into the task. */\r
+                                                       staticTASK_PRIORITY,            /* The priority of the task. */\r
+                                                       &xCreatedTask,                          /* Handle of the task being created. */\r
+                                                       NULL,                                           /* This time dynamically allocate the stack and TCB. */\r
+                                                       NULL );                                         /* This time dynamically allocate the stack and TCB. */\r
+\r
+               configASSERT( xReturned == pdPASS );\r
+               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
+               vTaskDelete( xCreatedTask );\r
+\r
+               /* Ensure lower priority tasks get CPU time. */\r
+               vTaskDelay( prvGetNextDelayTime() );\r
+\r
+               /* Just to show the check task that this task is still executing. */\r
+               uxCycleCounter++;\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvStaticallyAllocatedTask( void *pvParameters )\r
+{\r
+       ( void ) pvParameters;\r
+\r
+       /* The created task doesn't do anything - just waits to get deleted. */\r
+       vTaskSuspend( NULL );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static UBaseType_t prvRand( void )\r
+{\r
+const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;\r
+\r
+       /* Utility function to generate a pseudo random number. */\r
+       ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;\r
+       return( ( ulNextRand >> 16UL ) & 0x7fffUL );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static TickType_t prvGetNextDelayTime( void )\r
+{\r
+TickType_t xNextDelay;\r
+const TickType_t xMaxDelay = pdMS_TO_TICKS( ( TickType_t ) 150 );\r
+const TickType_t xMinDelay = pdMS_TO_TICKS( ( TickType_t ) 75 );\r
+const TickType_t xTinyDelay = pdMS_TO_TICKS( ( TickType_t ) 2 );\r
+\r
+       /* Generate the next delay time.  This is kept within a narrow band so as\r
+       not to disturb the timing of other tests - but does add in some pseudo\r
+       randomisation into the tests. */\r
+       do\r
+       {\r
+               xNextDelay = prvRand() % xMaxDelay;\r
+\r
+               /* Just in case this loop is executed lots of times. */\r
+               vTaskDelay( xTinyDelay );\r
+\r
+       } while ( xNextDelay < xMinDelay );\r
+\r
+       return xNextDelay;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t xAreStaticAllocationTasksStillRunning( void )\r
+{\r
+static UBaseType_t uxLastCycleCounter = 0;\r
+BaseType_t xReturn;\r
+\r
+       if( uxCycleCounter == uxLastCycleCounter )\r
+       {\r
+               xReturn = pdFAIL;\r
+       }\r
+       else\r
+       {\r
+               xReturn = pdPASS;\r
+               uxLastCycleCounter = uxCycleCounter;\r
+       }\r
+\r
+       return xReturn;\r
+}\r
+\r
index ca02b4bbca633cf0401b3f32c68a0c7963f472c1..2a65b86c1567d3909683e23facd02b0f88bf6b5d 100644 (file)
@@ -425,6 +425,7 @@ static void prvNotifiedTask( void *pvParameters )
 {\r
 const TickType_t xMaxPeriod = pdMS_TO_TICKS( 90 ), xMinPeriod = pdMS_TO_TICKS( 10 ), xDontBlock = 0;\r
 TickType_t xPeriod;\r
+const uint32_t ulCyclesToRaisePriority = 50UL;\r
 \r
        /* Remove compiler warnings about unused parameters. */\r
        ( void ) pvParameters;\r
@@ -482,9 +483,28 @@ TickType_t xPeriod;
                the function call. */\r
                ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, xPeriod );\r
 \r
-               /* Wait for the next notification again, clearing all notifications if\r
-               one is received, but this time blocking indefinitely. */\r
-               ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
+               /* Occasionally raise the priority of the task being notified to test\r
+               the path where the task is notified from an ISR and becomes the highest\r
+               priority ready state task, but the pxHigherPriorityTaskWoken parameter\r
+               is NULL (which it is in the tick hook that sends notifications to this\r
+               task. */\r
+               if( ( ulNotifyCycleCount % ulCyclesToRaisePriority ) == 0 )\r
+               {\r
+                       vTaskPrioritySet( xTaskToNotify, configMAX_PRIORITIES - 1 );\r
+\r
+                       /* Wait for the next notification again, clearing all notifications if\r
+                       one is received, but this time blocking indefinitely. */\r
+                       ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
+\r
+                       /* Reset the priority. */\r
+                       vTaskPrioritySet( xTaskToNotify, notifyTASK_PRIORITY );\r
+               }\r
+               else\r
+               {\r
+                       /* Wait for the next notification again, clearing all notifications if\r
+                       one is received, but this time blocking indefinitely. */\r
+                       ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
+               }\r
 \r
                /* Incremented to show the task is still running. */\r
                ulNotifyCycleCount++;\r
index 46c711e9c0acf74a494590fb9deb00906d78dd34..9a258bf38380cf52e787e875505e391ae02ff7ee 100644 (file)
@@ -114,9 +114,11 @@ task can tell if any of the suicidal tasks have failed to die.
 */\r
 static volatile UBaseType_t uxTasksRunningAtStart = 0;\r
 \r
-/* Tasks are deleted by the idle task.  Under heavy load the idle task might\r
-not get much processing time, so it would be legitimate for several tasks to\r
-remain undeleted for a short period. */\r
+/* When a task deletes itself, it stack and TCB are cleaned up by the Idle task.\r
+Under heavy load the idle task might not get much processing time, so it would \r
+be legitimate for several tasks to remain undeleted for a short period.  There\r
+may also be a few other unexpected tasks if, for example, the tasks that test\r
+static allocation are also being used. */\r
 static const UBaseType_t uxMaxNumberOfExtraTasksRunning = 3;\r
 \r
 /* Used to store a handle to the task that should be killed by a suicidal task,\r
@@ -151,7 +153,9 @@ UBaseType_t *puxPriority;
        If this is done, then uxTasksRunningAtStart needs incrementing again as that\r
        too is created when the scheduler is started. */\r
        #if configUSE_TIMERS == 1\r
+       {\r
                uxTasksRunningAtStart++;\r
+       }\r
        #endif\r
 }\r
 /*-----------------------------------------------------------*/\r
index a9a8c9c20331ceebc5a4f78b0d15970427390d6e..93238e741483db8cbfe28764a04d873ecb14aee0 100644 (file)
@@ -125,7 +125,7 @@ be overridden by a definition in FreeRTOSConfig.h. */
 /* Misc. */\r
 #define recmuSHORT_DELAY                               ( pdMS_TO_TICKS( 20 ) )\r
 #define recmuNO_DELAY                                  ( ( TickType_t ) 0 )\r
-#define recmuEIGHT_TICK_DELAY                  ( ( TickType_t ) 8 )\r
+#define recmu15ms_DELAY                                        ( pdMS_TO_TICKS( 15 ) )\r
 \r
 /* The three tasks as described at the top of this file. */\r
 static void prvRecursiveMutexControllingTask( void *pvParameters );\r
@@ -199,7 +199,7 @@ UBaseType_t ux;
                        long enough to ensure the polling task will execute again before the\r
                        block time expires.  If the block time does expire then the error\r
                        flag will be set here. */\r
-                       if( xSemaphoreTakeRecursive( xMutex, recmuEIGHT_TICK_DELAY ) != pdPASS )\r
+                       if( xSemaphoreTakeRecursive( xMutex, recmu15ms_DELAY ) != pdPASS )\r
                        {\r
                                xErrorOccurred = pdTRUE;\r
                        }\r
diff --git a/FreeRTOS/Demo/Common/include/StaticAllocation.h b/FreeRTOS/Demo/Common/include/StaticAllocation.h
new file mode 100644 (file)
index 0000000..6460627
--- /dev/null
@@ -0,0 +1,79 @@
+/*\r
+    FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.\r
+    All rights reserved\r
+\r
+    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\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
+\r
+    ***************************************************************************\r
+    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
+    >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
+    >>!   obliged to provide the source code for proprietary components     !<<\r
+    >>!   outside of the FreeRTOS kernel.                                   !<<\r
+    ***************************************************************************\r
+\r
+    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
+    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
+    link: http://www.freertos.org/a00114.html\r
+\r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
+     *                                                                       *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
+     *                                                                       *\r
+    ***************************************************************************\r
+\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\r
+\r
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+    compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+\r
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial middleware.\r
+\r
+    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+    engineered and independently SIL3 certified version for use in safety and\r
+    mission critical applications that require provable dependability.\r
+\r
+    1 tab == 4 spaces!\r
+*/\r
+\r
+#ifndef STATIC_ALLOCATION_H\r
+#define STATIC_ALLOCATION_H\r
+\r
+void vStartStaticallyAllocatedTasks( void  );\r
+BaseType_t xAreStaticAllocationTasksStillRunning( void );\r
+\r
+#endif /* STATIC_ALLOCATION_H */\r
+\r
+\r
+\r
index ce71af2df6db355de807266f5a5875674c2c3442..37aaf95515fdcb4710d26a7836cbb21531c24c92 100644 (file)
@@ -78,7 +78,8 @@
  * application requirements.\r
  *\r
  * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE\r
- * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.\r
+ * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.  See\r
+ * http://www.freertos.org/a00110.html\r
  *----------------------------------------------------------*/\r
 \r
 #define configUSE_PREEMPTION                                   1\r
 #define configUSE_ALTERNATIVE_API                              1\r
 #define configUSE_QUEUE_SETS                                   1\r
 #define configUSE_TASK_NOTIFICATIONS                   1\r
+#define configSUPPORT_STATIC_ALLOCATION                        1\r
 \r
 /* Software timer related configuration options. */\r
 #define configUSE_TIMERS                                               1\r
index 45919e965e06caf0c61a8504912868d3c2693927..5349d5037d36e0033141b689a8cf89ef655f446d 100644 (file)
     <ClCompile Include="..\Common\Minimal\QueueSetPolling.c" />\r
     <ClCompile Include="..\Common\Minimal\recmutex.c" />\r
     <ClCompile Include="..\Common\Minimal\semtest.c" />\r
+    <ClCompile Include="..\Common\Minimal\StaticAllocation.c" />\r
     <ClCompile Include="..\Common\Minimal\TaskNotify.c" />\r
     <ClCompile Include="..\Common\Minimal\timerdemo.c" />\r
     <ClCompile Include="main.c">\r
index 47b88f09e1cc2a374fe00d8609fee1ec0970a6e7..f9181f51040e840ec0e4b9a5e024f4a324329f93 100644 (file)
@@ -19,9 +19,6 @@
       <UniqueIdentifier>{34567deb-d5ab-4a56-8640-0aaec609521a}</UniqueIdentifier>\r
       <Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>\r
     </Filter>\r
-    <Filter Include="Demo App Source\Common Demo Tasks">\r
-      <UniqueIdentifier>{2d4a700c-06e3-4dd2-afbe-ab1be71ebe2a}</UniqueIdentifier>\r
-    </Filter>\r
     <Filter Include="FreeRTOS Source\Source\Portable">\r
       <UniqueIdentifier>{88f409e6-d396-4ac5-94bd-7a99c914be46}</UniqueIdentifier>\r
     </Filter>\r
     <Filter Include="Demo App Source\FreeRTOS+Trace Recorder">\r
       <UniqueIdentifier>{90b56567-bab6-4d92-b319-b514d378329d}</UniqueIdentifier>\r
     </Filter>\r
+    <Filter Include="Demo App Source\Full_Demo">\r
+      <UniqueIdentifier>{4ae1665e-a7bb-4c1a-81a3-531d883e6f2d}</UniqueIdentifier>\r
+    </Filter>\r
+    <Filter Include="Demo App Source\Full_Demo\Common Demo Tasks">\r
+      <UniqueIdentifier>{2d4a700c-06e3-4dd2-afbe-ab1be71ebe2a}</UniqueIdentifier>\r
+    </Filter>\r
+    <Filter Include="Demo App Source\Blinky_Demo">\r
+      <UniqueIdentifier>{fb86fa48-ac27-4f87-9215-ce9e1a1a85f9}</UniqueIdentifier>\r
+    </Filter>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="main.c">\r
       <Filter>FreeRTOS Source\Source\Portable</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\flop.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\GenQTest.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\integer.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\PollQ.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\QPeek.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\semtest.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\BlockQ.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\blocktim.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\..\Source\timers.c">\r
       <Filter>FreeRTOS Source\Source</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\timerdemo.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\countsem.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\death.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\dynamic.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\QueueSet.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="Run-time-stats-utils.c">\r
       <Filter>Demo App Source</Filter>\r
       <Filter>Demo App Source\FreeRTOS+Trace Recorder</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\QueueOverwrite.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
-    </ClCompile>\r
-    <ClCompile Include="main_full.c">\r
-      <Filter>Demo App Source</Filter>\r
-    </ClCompile>\r
-    <ClCompile Include="main_blinky.c">\r
-      <Filter>Demo App Source</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\EventGroupsDemo.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\..\Source\event_groups.c">\r
       <Filter>FreeRTOS Source\Source</Filter>\r
       <Filter>FreeRTOS Source\Source\Portable</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\IntSemTest.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\TaskNotify.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\QueueSetPolling.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
     <ClCompile Include="..\Common\Minimal\recmutex.c">\r
-      <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="main_full.c">\r
+      <Filter>Demo App Source\Full_Demo</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="main_blinky.c">\r
+      <Filter>Demo App Source\Blinky_Demo</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\Common\Minimal\StaticAllocation.c">\r
+      <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
index 6f89e265a4dc9fc0c9f3cea64b95a2f31d8bcdcc..a69126e3d6e8f1117d4e396f3d8ae4cbd5989978 100644 (file)
@@ -154,6 +154,8 @@ void vApplicationMallocFailedHook( void );
 void vApplicationIdleHook( void );\r
 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
 void vApplicationTickHook( void );\r
+void vApplicationGetIdleTaskMemory( DummyTCB_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint16_t *pusIdleTaskStackSize );\r
+void vApplicationGetTimerTaskMemory( DummyTCB_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint16_t *pusTimerTaskStackSize );\r
 \r
 /*\r
  * Writes trace data to a disk file when the trace recording is stopped.\r
@@ -390,3 +392,37 @@ const HeapRegion_t xHeapRegions[] =
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+void vApplicationGetIdleTaskMemory( DummyTCB_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint16_t *pusIdleTaskStackSize )\r
+{\r
+/* The buffers used by the idle task must be static so they are persistent, and\r
+so exist after this function returns. */\r
+static DummyTCB_t xIdleTaskTCB;\r
+static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];\r
+\r
+       /* configUSE_STATIC_ALLOCATION is set to 1, so the application has the\r
+       opportunity to supply the buffers that will be used by the Idle task as its\r
+       stack and to hold its TCB.  If these are set to NULL then the buffers will\r
+       be allocated dynamically, just as if xTaskCreate() had been called. */\r
+       *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
+       *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
+       *pusIdleTaskStackSize = configMINIMAL_STACK_SIZE; /* In words.  NOT in bytes! */\r
+}\r
+/*-----------------------------------------------------------*/\r
+DummyTCB_t xTimerTaskTCB;\r
+void vApplicationGetTimerTaskMemory( DummyTCB_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint16_t *pusTimerTaskStackSize )\r
+{\r
+/* The buffers used by the Timer/Daemon task must be static so they are\r
+persistent, and so exist after this function returns. */\r
+//static DummyTCB_t xTimerTaskTCB;\r
+static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];\r
+\r
+       /* configUSE_STATIC_ALLOCATION is set to 1, so the application has the\r
+       opportunity to supply the buffers that will be used by the Timer/RTOS daemon\r
+       task as its     stack and to hold its TCB.  If these are set to NULL then the\r
+       buffers will be allocated dynamically, just as if xTaskCreate() had been\r
+       called. */\r
+       *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
+       *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
+       *pusTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; /* In words.  NOT in bytes! */\r
+}\r
+\r
index b429d8c930f06aa5620f06cd27a0624beb8e46d3..a0ad433f6f40eb18eee754789bcf9b563954e955 100644 (file)
@@ -99,7 +99,7 @@
  * to ensure it gets processor time.  Its main function is to check that all the\r
  * standard demo tasks are still operational.  While no errors have been\r
  * discovered the check task will print out "No Errors" along with some system\r
- * status information.  If an error is discovered in the execution of a task \r
+ * status information.  If an error is discovered in the execution of a task\r
  * then the check task will print out an appropriate error message.\r
  *\r
  */\r
 #include "IntSemTest.h"\r
 #include "TaskNotify.h"\r
 #include "QueueSetPolling.h"\r
+#include "StaticAllocation.h"\r
 \r
 /* Priorities at which the tasks are created. */\r
 #define mainCHECK_TASK_PRIORITY                        ( configMAX_PRIORITIES - 2 )\r
@@ -214,6 +215,7 @@ int main_full( void )
        vStartInterruptSemaphoreTasks();\r
        vStartQueueSetPollingTask();\r
        xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
+       vStartStaticallyAllocatedTasks();\r
 \r
        #if( configUSE_PREEMPTION != 0  )\r
        {\r
@@ -337,6 +339,10 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );
                {\r
                        pcStatusMessage = "Error: Queue set polling";\r
                }\r
+               else if( xAreStaticAllocationTasksStillRunning() != pdPASS )\r
+               {\r
+                       pcStatusMessage = "Error: Static allocation";\r
+               }\r
 \r
                /* This is the only task that uses stdout so its ok to call printf()\r
                directly. */\r
index 8951b25b0df5168ae3fd33bfdfc2212eadc160db..a0e55e6d8f0b4ab88d26267811f6367bcf80e343 100644 (file)
@@ -681,7 +681,7 @@ extern "C" {
 #endif\r
 \r
 #ifndef pvPortMallocAligned\r
-       #define pvPortMallocAligned( x, puxStackBuffer ) ( ( ( puxStackBuffer ) == NULL ) ? ( pvPortMalloc( ( x ) ) ) : ( puxStackBuffer ) )\r
+       #define pvPortMallocAligned( x, puxPreallocatedBuffer ) ( ( ( puxPreallocatedBuffer ) == NULL ) ? ( pvPortMalloc( ( x ) ) ) : ( puxPreallocatedBuffer ) )\r
 #endif\r
 \r
 #ifndef vPortFreeAligned\r
@@ -772,6 +772,10 @@ extern "C" {
        #define portTICK_TYPE_IS_ATOMIC 0\r
 #endif\r
 \r
+#ifndef configSUPPORT_STATIC_ALLOCATION\r
+       #define configSUPPORT_STATIC_ALLOCATION 0\r
+#endif\r
+\r
 #if( portTICK_TYPE_IS_ATOMIC == 0 )\r
        /* Either variables of tick type cannot be read atomically, or\r
        portTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when\r
index b8d6dd89094179130a8ddcfac6ccda5bd341be98..1108d34212811f20ef8c7bb9415ece7572a2fc33 100644 (file)
@@ -128,6 +128,12 @@ typedef enum
        eSetValueWithoutOverwrite       /* Set the task's notification value if the previous value has been read by the task. */\r
 } eNotifyAction;\r
 \r
+/* For data hiding purposes. */\r
+typedef enum\r
+{\r
+       eNothing = 0\r
+} eDummy;\r
+\r
 /*\r
  * Used internally only.\r
  */\r
@@ -183,6 +189,65 @@ typedef enum
        eNoTasksWaitingTimeout  /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */\r
 } eSleepModeStatus;\r
 \r
+/* Value that can be assigned to the eNotifyState member of the TCB. */\r
+typedef enum\r
+{\r
+       eNotWaitingNotification = 0,\r
+       eWaitingNotification,\r
+       eNotified\r
+} eNotifyValue;\r
+\r
+/*\r
+ * FreeRTOS implements a strict data hiding policy, so the real task control\r
+ * block (TCB) structure is not accessible to the application code.  However, if\r
+ * the application writer wants to statically allocate a TCB then the size of\r
+ * the TCB needs to be know.  The dummy TCB structure below is used for this\r
+ * purpose.  Its size will allows match the size of the real TCB, no matter what\r
+ * the FreeRTOSConfig.h settings.\r
+ */\r
+typedef struct xDUMMY_TCB\r
+{\r
+       void                            *pxDummy1;\r
+       #if ( portUSING_MPU_WRAPPERS == 1 )\r
+               xMPU_SETTINGS   xDummy2;\r
+       #endif\r
+       ListItem_t                      xDummy3[ 2 ];\r
+       UBaseType_t                     uxDummy5;\r
+       void                            *pxDummy6;\r
+       uint8_t                         ucDummy7[ configMAX_TASK_NAME_LEN ];\r
+       #if ( portSTACK_GROWTH > 0 )\r
+               void                    *pxDummy8;\r
+       #endif\r
+       #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+               UBaseType_t             uxDummy9;\r
+       #endif\r
+       #if ( configUSE_TRACE_FACILITY == 1 )\r
+               UBaseType_t             uxDummy10[ 2 ];\r
+       #endif\r
+       #if ( configUSE_MUTEXES == 1 )\r
+               UBaseType_t             uxDummy12[ 2 ];\r
+       #endif\r
+       #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
+               void                    *pxDummy14;\r
+       #endif\r
+       #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )\r
+               void                    pvDummy15[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];\r
+       #endif\r
+       #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+               uint32_t                ulDummy16;\r
+       #endif\r
+       #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
+               struct  _reent  xDummy17;\r
+       #endif\r
+       #if ( configUSE_TASK_NOTIFICATIONS == 1 )\r
+               uint32_t                ulDummy18;\r
+               eDummy                  eDummy19;\r
+       #endif\r
+       #if ( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+               UBaseType_t             uxDummy20;\r
+       #endif\r
+\r
+} DummyTCB_t;\r
 \r
 /**\r
  * Defines the priority used by the idle task.  This must not be modified.\r
@@ -342,7 +407,112 @@ is used in assert() statements. */
  * \defgroup xTaskCreate xTaskCreate\r
  * \ingroup Tasks\r
  */\r
-#define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )\r
+#define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ), ( NULL ) )\r
+\r
+/**\r
+ * task. h\r
+ *<pre>\r
+ BaseType_t xTaskCreateStatic(\r
+                                                         TaskFunction_t pvTaskCode,\r
+                                                         const char * const pcName,\r
+                                                         uint16_t usStackDepth,\r
+                                                         void *pvParameters,\r
+                                                         UBaseType_t uxPriority,\r
+                                                         TaskHandle_t *pvCreatedTask,\r
+                                                         StackType_t *pxStackBuffer,\r
+                                                         DummyTCB_t *pxTCBBuffer\r
+                                                 );</pre>\r
+ *\r
+ * Create a new task and add it to the list of tasks that are ready to run.\r
+ * If a task is created using xTaskCreate() then the stack and task control \r
+ * block (TCB) used by the task are allocated dynamically.  If a task is created\r
+ * using xTaskCreateStatic() then the application writer can optionally provide\r
+ * the buffers that will hold the task stack and TCB respectively.  \r
+ * xTaskCreateStatic() therefore allows tasks to be created without any dynamic\r
+ * memory allocation.\r
+ *\r
+ * @param pvTaskCode Pointer to the task entry function.  Tasks\r
+ * must be implemented to never return (i.e. continuous loop).\r
+ *\r
+ * @param pcName A descriptive name for the task.  This is mainly used to\r
+ * facilitate debugging.  The maximum length of the string is defined by \r
+ * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.\r
+ *\r
+ * @param usStackDepth The size of the task stack specified as the number of\r
+ * variables the stack can hold - not the number of bytes.  For example, if\r
+ * the stack is 32-bits wide and usStackDepth is defined as 100 then 400 bytes\r
+ * will be allocated for stack storage.\r
+ *\r
+ * @param pvParameters Pointer that will be used as the parameter for the task\r
+ * being created.\r
+ *\r
+ * @param uxPriority The priority at which the task will run.\r
+ *\r
+ * @param pvCreatedTask Used to pass back a handle by which the created task\r
+ * can be referenced.  Pass as NULL if the handle is not required.\r
+ *\r
+ * @param pxStackBuffer If pxStackBuffer is NULL then the stack used by the\r
+ * task will be allocated dynamically, just as if the task was created using\r
+ * xTaskCreate().  if pxStackBuffer is not NULL then it must point to a \r
+ * StackType_t array that has at least usStackDepth indexes - the array will\r
+ * then be used as the task's stack.\r
+ *\r
+ * @param pxTCBBuffer If pxTCBBuffer is NULL then the TCB (which is the\r
+ * structures used internally within FreeRTOS to hold information on the task)\r
+ * will be allocated dynamically, just as when xTaskCreate() is used.  If\r
+ * pxTCBBuffer is not NULL then it must point to a variable of type DummyTCB_T,\r
+ * which will then be used as the TCB of the task being created.\r
+ *\r
+ * @return pdPASS if the task was successfully created and added to a ready\r
+ * list, otherwise an error code defined in the file projdefs.h\r
+ *\r
+ * Example usage:\r
+   <pre>\r
+\r
+ // Dimensions the buffer that the task being created will use as its stack.\r
+ // NOTE:  This is the number of words the stack will hold, not the number of\r
+ // bytes.  For example, if each stack item is 32-bits, and this is set to 100,\r
+ // then 400 bytes (100 * 32-bits) will be allocated.\r
+ #define STACK_SIZE 200\r
+\r
+ // Structure that will hold the TCB of the task being created.\r
+ DummyTCB_t xTCB;\r
+\r
+ // Buffer that the task being created will use as its stack.\r
+ StackType_t xStack[ STACK_SIZE ];\r
+   \r
+ // Task to be created.\r
+ void vTaskCode( void * pvParameters )\r
+ {\r
+        for( ;; )\r
+        {\r
+                // Task code goes here.\r
+        }\r
+ }\r
+\r
+ // Function that creates a task.\r
+ void vOtherFunction( void )\r
+ {\r
+ static uint8_t ucParameterToPass;\r
+ TaskHandle_t xHandle = NULL;\r
+\r
+        // Create the task without using any dynamic memory allocation.\r
+        xTaskCreate( vTaskCode,          // As per xTaskCreate() parameter.\r
+                                 "NAME",             // As per xTaskCreate() parameter.\r
+                                 STACK_SIZE,         // As per xTaskCreate() parameter.\r
+                                 &ucParameterToPass, // As per xTaskCreate() parameter. \r
+                                 tskIDLE_PRIORITY,   // As per xTaskCreate() parameter.\r
+                                 &xHandle,           // As per xTaskCreate() parameter.\r
+                                 xStack,             // Pointer to the buffer that the task being created will use as its stack.\r
+                                 &xTCB );            // Pointer to a structure in which the TCB of the task being created will be stored.\r
+ }\r
+   </pre>\r
+ * \defgroup xTaskCreateStatic xTaskCreateStatic\r
+ * \ingroup Tasks\r
+ */\r
+#if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+       #define xTaskCreateStatic( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask, puxStackBuffer, pxDummyTCB ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( puxStackBuffer ), ( pxDummyTCB ), ( NULL ) )\r
+#endif\r
 \r
 /**\r
  * task. h\r
@@ -411,7 +581,7 @@ TaskHandle_t xHandle;
  * \defgroup xTaskCreateRestricted xTaskCreateRestricted\r
  * \ingroup Tasks\r
  */\r
-#define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ((x)->xRegions) )\r
+#define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ( NULL ), ((x)->xRegions) )\r
 \r
 /**\r
  * task. h\r
@@ -1983,7 +2153,7 @@ BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGE
  * Generic version of the task creation function which is in turn called by the\r
  * xTaskCreate() and xTaskCreateRestricted() macros.\r
  */\r
-BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, DummyTCB_t * const pxTCBBuffer, const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
 \r
 /*\r
  * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.\r
index 7b0406d2add29b1a0a18ff409cbbaab5596c7f27..b74b4efa132ca8448eb07c839f6ecebbe4b82e18 100644 (file)
@@ -1935,8 +1935,8 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
                                {\r
                                        if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                        {\r
-                                               /* The task waiting has a higher priority so record that a\r
-                                               context switch is required. */\r
+                                               /* The task waiting has a higher priority so record that\r
+                                               context switch is required. */\r
                                                vTaskMissedYield();\r
                                        }\r
                                        else\r
index fe2f5ae1aa627b342c4d04dd91e7c43f02652ea4..04208ca4a9fc4cae3b2ac7424e695d743d165cac 100644 (file)
@@ -105,6 +105,10 @@ functions but without including stdio.h here. */
        #endif /* INCLUDE_vTaskSuspend */\r
 #endif /* configUSE_TICKLESS_IDLE */\r
 \r
+#if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION != 1 ) )\r
+       #error configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h when the MPU is used.\r
+#endif\r
+\r
 /*\r
  * Defines the size, in words, of the stack allocated to the idle task.\r
  */\r
@@ -118,13 +122,12 @@ functions but without including stdio.h here. */
        #define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()\r
 #endif\r
 \r
-/* Value that can be assigned to the eNotifyState member of the TCB. */\r
-typedef enum\r
-{\r
-       eNotWaitingNotification = 0,\r
-       eWaitingNotification,\r
-       eNotified\r
-} eNotifyValue;\r
+/* Bits that can be set in tskTCB->uxStaticAllocationFlags to indicate that the\r
+stack and TCB were statically allocated respectively.  When these are statically\r
+allocated they won't be freed if the task using the stack and TCB gets\r
+deleted. */\r
+#define taskSTATICALLY_ALLOCATED_STACK ( ( UBaseType_t ) 0x01 )\r
+#define taskSTATICALLY_ALLOCATED_TCB   ( ( UBaseType_t ) 0x02 )\r
 \r
 /*\r
  * Task control block.  A task control block (TCB) is allocated for each task,\r
@@ -137,7 +140,6 @@ typedef struct tskTaskControlBlock
 \r
        #if ( portUSING_MPU_WRAPPERS == 1 )\r
                xMPU_SETTINGS   xMPUSettings;           /*< The MPU settings are defined as part of the port layer.  THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */\r
-               BaseType_t              xUsingStaticallyAllocatedStack; /* Set to pdTRUE if the stack is a statically allocated array, and pdFALSE if the stack is dynamically allocated. */\r
        #endif\r
 \r
        ListItem_t                      xGenericListItem;       /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */\r
@@ -151,17 +153,17 @@ typedef struct tskTaskControlBlock
        #endif\r
 \r
        #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
-               UBaseType_t     uxCriticalNesting;      /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */\r
+               UBaseType_t             uxCriticalNesting;      /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */\r
        #endif\r
 \r
        #if ( configUSE_TRACE_FACILITY == 1 )\r
                UBaseType_t             uxTCBNumber;            /*< Stores a number that increments each time a TCB is created.  It allows debuggers to determine when a task has been deleted and then recreated. */\r
-               UBaseType_t     uxTaskNumber;           /*< Stores a number specifically for use by third party trace code. */\r
+               UBaseType_t             uxTaskNumber;           /*< Stores a number specifically for use by third party trace code. */\r
        #endif\r
 \r
        #if ( configUSE_MUTEXES == 1 )\r
-               UBaseType_t     uxBasePriority;         /*< The priority last assigned to the task - used by the priority inheritance mechanism. */\r
-               UBaseType_t     uxMutexesHeld;\r
+               UBaseType_t             uxBasePriority;         /*< The priority last assigned to the task - used by the priority inheritance mechanism. */\r
+               UBaseType_t             uxMutexesHeld;\r
        #endif\r
 \r
        #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
@@ -184,7 +186,7 @@ typedef struct tskTaskControlBlock
                newlib and must provide system-wide implementations of the necessary\r
                stubs. Be warned that (at the time of writing) the current newlib design\r
                implements a system-wide malloc() that must be provided with locks. */\r
-               struct  _reent xNewLib_reent;\r
+               struct  _reent xNewLib_reent;\r
        #endif\r
 \r
        #if ( configUSE_TASK_NOTIFICATIONS == 1 )\r
@@ -192,7 +194,11 @@ typedef struct tskTaskControlBlock
                volatile eNotifyValue eNotifyState;\r
        #endif\r
 \r
-} tskTCB;\r
+       #if ( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+               UBaseType_t             uxStaticAllocationFlags; /* Set to pdTRUE if the stack is a statically allocated array, and pdFALSE if the stack is dynamically allocated. */\r
+       #endif\r
+\r
+       } tskTCB;\r
 \r
 /* The old tskTCB name is maintained above then typedefed to the new TCB_t name\r
 below to enable the use of older kernel aware debuggers. */\r
@@ -232,12 +238,6 @@ PRIVILEGED_DATA static List_t xPendingReadyList;                                           /*< Tasks that have been r
 \r
 #endif\r
 \r
-#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
-\r
-       PRIVILEGED_DATA static TaskHandle_t xIdleTaskHandle = NULL;                     /*< Holds the handle of the idle task.  The idle task is created automatically when the scheduler is started. */\r
-\r
-#endif\r
-\r
 /* Other file private variables. --------------------------------*/\r
 PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks     = ( UBaseType_t ) 0U;\r
 PRIVILEGED_DATA static volatile TickType_t xTickCount                          = ( TickType_t ) 0U;\r
@@ -248,6 +248,7 @@ PRIVILEGED_DATA static volatile BaseType_t xYieldPending                    = pdFALSE;
 PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows                     = ( BaseType_t ) 0;\r
 PRIVILEGED_DATA static UBaseType_t uxTaskNumber                                        = ( UBaseType_t ) 0U;\r
 PRIVILEGED_DATA static volatile TickType_t xNextTaskUnblockTime                = ( TickType_t ) 0U; /* Initialised to portMAX_DELAY before the scheduler starts. */\r
+PRIVILEGED_DATA static TaskHandle_t xIdleTaskHandle                                    = NULL;                 /*< Holds the handle of the idle task.  The idle task is created automatically when the scheduler is started. */\r
 \r
 /* Context switches are held pending while the scheduler is suspended.  Also,\r
 interrupts must not manipulate the xGenericListItem of a TCB, or any of the\r
@@ -409,21 +410,25 @@ being used for another purpose.  The following bit definition is used to inform
 the scheduler that the value should not be changed - in which case it is the\r
 responsibility of whichever module is using the value to ensure it gets set back\r
 to its original value when it is released. */\r
-#if configUSE_16_BIT_TICKS == 1\r
+#if( configUSE_16_BIT_TICKS == 1 )\r
        #define taskEVENT_LIST_ITEM_VALUE_IN_USE        0x8000U\r
 #else\r
        #define taskEVENT_LIST_ITEM_VALUE_IN_USE        0x80000000UL\r
 #endif\r
 \r
 /* Callback function prototypes. --------------------------*/\r
-#if configCHECK_FOR_STACK_OVERFLOW > 0\r
+#if(  configCHECK_FOR_STACK_OVERFLOW > 0 )\r
        extern void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName );\r
 #endif\r
 \r
-#if configUSE_TICK_HOOK > 0\r
+#if( configUSE_TICK_HOOK > 0 )\r
        extern void vApplicationTickHook( void );\r
 #endif\r
 \r
+#if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+       extern void vApplicationGetIdleTaskMemory( DummyTCB_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint16_t *pusIdleTaskStackSize );\r
+#endif\r
+\r
 /* File private functions. --------------------------------*/\r
 \r
 /*\r
@@ -490,7 +495,7 @@ static void prvAddCurrentTaskToDelayedList( const TickType_t xTimeToWake ) PRIVI
  * Allocates memory from the heap for a TCB and associated stack.  Checks the\r
  * allocation was successful.\r
  */\r
-static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer ) PRIVILEGED_FUNCTION;\r
+static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer, TCB_t * const pucTCBBuffer ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Fills an TaskStatus_t structure with information on each task that is\r
@@ -549,7 +554,7 @@ static void prvResetNextTaskUnblockTime( void );
 #endif\r
 /*-----------------------------------------------------------*/\r
 \r
-BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, const MemoryRegion_t * const xRegions ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, DummyTCB_t * const pxTCBBuffer, const MemoryRegion_t * const xRegions ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
 {\r
 BaseType_t xReturn;\r
 TCB_t * pxNewTCB;\r
@@ -560,7 +565,7 @@ StackType_t *pxTopOfStack;
 \r
        /* Allocate the memory required by the TCB and stack for the new task,\r
        checking that the allocation was successful. */\r
-       pxNewTCB = prvAllocateTCBAndStack( usStackDepth, puxStackBuffer );\r
+       pxNewTCB = prvAllocateTCBAndStack( usStackDepth, puxStackBuffer, ( TCB_t* ) pxTCBBuffer ); /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\r
 \r
        if( pxNewTCB != NULL )\r
        {\r
@@ -576,20 +581,6 @@ StackType_t *pxTopOfStack;
                                xRunPrivileged = pdFALSE;\r
                        }\r
                        uxPriority &= ~portPRIVILEGE_BIT;\r
-\r
-                       if( puxStackBuffer != NULL )\r
-                       {\r
-                               /* The application provided its own stack.  Note this so no\r
-                               attempt is made to delete the stack should that task be\r
-                               deleted. */\r
-                               pxNewTCB->xUsingStaticallyAllocatedStack = pdTRUE;\r
-                       }\r
-                       else\r
-                       {\r
-                               /* The stack was allocated dynamically.  Note this so it can be\r
-                               deleted again if the task is deleted. */\r
-                               pxNewTCB->xUsingStaticallyAllocatedStack = pdFALSE;\r
-                       }\r
                #endif /* portUSING_MPU_WRAPPERS == 1 */\r
 \r
                /* Calculate the top of stack address.  This depends on whether the\r
@@ -1045,7 +1036,7 @@ StackType_t *pxTopOfStack;
                                else if( ( pxStateList == &xTasksWaitingTermination ) || ( pxStateList == NULL ) )\r
                                {\r
                                        /* The task being queried is referenced from the deleted\r
-                                       tasks list, or it is not referenced from any lists at \r
+                                       tasks list, or it is not referenced from any lists at\r
                                        all. */\r
                                        eReturn = eDeleted;\r
                                }\r
@@ -1555,20 +1546,18 @@ StackType_t *pxTopOfStack;
 void vTaskStartScheduler( void )\r
 {\r
 BaseType_t xReturn;\r
+DummyTCB_t *pxIdleTaskTCBBuffer = NULL;\r
+StackType_t *pxIdleTaskStackBuffer = NULL;\r
+uint16_t usIdleTaskStackSize = tskIDLE_STACK_SIZE;\r
 \r
-       /* Add the idle task at the lowest priority. */\r
-       #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
+       #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
        {\r
-               /* Create the idle task, storing its handle in xIdleTaskHandle so it can\r
-               be returned by the xTaskGetIdleTaskHandle() function. */\r
-               xReturn = xTaskCreate( prvIdleTask, "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
+               vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &usIdleTaskStackSize );\r
        }\r
-       #else\r
-       {\r
-               /* Create the idle task without storing its handle. */\r
-               xReturn = xTaskCreate( prvIdleTask, "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), NULL );  /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
-       }\r
-       #endif /* INCLUDE_xTaskGetIdleTaskHandle */\r
+       #endif /* configSUPPORT_STATIC_ALLOCATION */\r
+\r
+       /* Add the idle task at the lowest priority. */\r
+       xReturn = xTaskGenericCreate( prvIdleTask, "IDLE", usIdleTaskStackSize, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle, pxIdleTaskStackBuffer, pxIdleTaskTCBBuffer, NULL ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\r
 \r
        #if ( configUSE_TIMERS == 1 )\r
        {\r
@@ -1628,6 +1617,10 @@ BaseType_t xReturn;
                or the timer task. */\r
                configASSERT( xReturn );\r
        }\r
+\r
+       /* Prevent compiler warnings if INCLUDE_xTaskGetIdleTaskHandle is set to 0, \r
+       meaning xIdleTaskHandle is not used anywhere else. */\r
+       ( void ) xIdleTaskHandle;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -3145,10 +3138,17 @@ static void prvAddCurrentTaskToDelayedList( const TickType_t xTimeToWake )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer )\r
+static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer, TCB_t * const pxTCBBuffer )\r
 {\r
 TCB_t *pxNewTCB;\r
 \r
+       #if( configASSERT_DEFINED == 1 )\r
+       {\r
+               volatile size_t xSize = sizeof( DummyTCB_t );\r
+               configASSERT( xSize == sizeof( TCB_t ) );\r
+       }\r
+       #endif /* configASSERT_DEFINED */\r
+\r
        /* If the stack grows down then allocate the stack then the TCB so the stack\r
        does not grow into the TCB.  Likewise if the stack grows up then allocate\r
        the TCB then the stack. */\r
@@ -3156,7 +3156,7 @@ TCB_t *pxNewTCB;
        {\r
                /* Allocate space for the TCB.  Where the memory comes from depends on\r
                the implementation of the port malloc function. */\r
-               pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\r
+               pxNewTCB = ( TCB_t * ) pvPortMallocAligned( sizeof( TCB_t ), pxTCBBuffer );\r
 \r
                if( pxNewTCB != NULL )\r
                {\r
@@ -3167,8 +3167,12 @@ TCB_t *pxNewTCB;
 \r
                        if( pxNewTCB->pxStack == NULL )\r
                        {\r
-                               /* Could not allocate the stack.  Delete the allocated TCB. */\r
-                               vPortFree( pxNewTCB );\r
+                               /* Could not allocate the stack.  Delete the allocated TCB - if\r
+                               it was allocated dynamically. */\r
+                               if( pxTCBBuffer == NULL )\r
+                               {\r
+                                       vPortFree( pxNewTCB );\r
+                               }\r
                                pxNewTCB = NULL;\r
                        }\r
                }\r
@@ -3182,9 +3186,8 @@ TCB_t *pxNewTCB;
 \r
                if( pxStack != NULL )\r
                {\r
-                       /* Allocate space for the TCB.  Where the memory comes from depends\r
-                       on the implementation of the port malloc function. */\r
-                       pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );\r
+                       /* Allocate space for the TCB. */\r
+                       pxNewTCB = ( TCB_t * ) pvPortMallocAligned( sizeof( TCB_t ), pxTCBBuffer ); /*lint !e961 MISRA exception as the casts are only redundant for some paths. */\r
 \r
                        if( pxNewTCB != NULL )\r
                        {\r
@@ -3199,6 +3202,10 @@ TCB_t *pxNewTCB;
                                {\r
                                        vPortFree( pxStack );\r
                                }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
                        }\r
                }\r
                else\r
@@ -3217,6 +3224,34 @@ TCB_t *pxNewTCB;
                        ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) usStackDepth * sizeof( StackType_t ) );\r
                }\r
                #endif /* ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) ) */\r
+\r
+               #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+               {\r
+                       pxNewTCB->uxStaticAllocationFlags = 0;\r
+\r
+                       if( puxStackBuffer != NULL )\r
+                       {\r
+                               /* The application provided its own stack - note the fact so no\r
+                               attempt is made to delete the stack if the task is deleted. */\r
+                               pxNewTCB->uxStaticAllocationFlags |= taskSTATICALLY_ALLOCATED_STACK;\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+\r
+                       if( pxTCBBuffer != NULL )\r
+                       {\r
+                               /* The application provided its own TCB.  Note the fact so no\r
+                               attempt is made to delete the TCB if the task is deleted. */\r
+                               pxNewTCB->uxStaticAllocationFlags |= taskSTATICALLY_ALLOCATED_TCB;\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+               }\r
+               #endif /* configSUPPORT_STATIC_ALLOCATION */\r
        }\r
 \r
        return pxNewTCB;\r
@@ -3373,22 +3408,34 @@ TCB_t *pxNewTCB;
                }\r
                #endif /* configUSE_NEWLIB_REENTRANT */\r
 \r
-               #if( portUSING_MPU_WRAPPERS == 1 )\r
+               #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
                {\r
-                       /* Only free the stack if it was allocated dynamically in the first\r
-                       place. */\r
-                       if( pxTCB->xUsingStaticallyAllocatedStack == pdFALSE )\r
+                       /* Only free the stack and TCB if they were allocated dynamically in\r
+                       the first place. */\r
+                       if( ( pxTCB->uxStaticAllocationFlags & taskSTATICALLY_ALLOCATED_STACK ) == ( UBaseType_t ) 0 )\r
                        {\r
                                vPortFreeAligned( pxTCB->pxStack );\r
                        }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+\r
+                       if( ( pxTCB->uxStaticAllocationFlags & taskSTATICALLY_ALLOCATED_TCB ) == ( UBaseType_t ) 0 )\r
+                       {\r
+                               vPortFreeAligned( pxTCB );\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
                }\r
                #else\r
                {\r
                        vPortFreeAligned( pxTCB->pxStack );\r
+                       vPortFree( pxTCB );\r
                }\r
                #endif\r
-\r
-               vPortFree( pxTCB );\r
        }\r
 \r
 #endif /* INCLUDE_vTaskDelete */\r
@@ -4392,6 +4439,13 @@ TickType_t uxReturn;
                                        {\r
                                                *pxHigherPriorityTaskWoken = pdTRUE;\r
                                        }\r
+                                       else\r
+                                       {\r
+                                               /* Mark that a yield is pending in case the user is not\r
+                                               using the "xHigherPriorityTaskWoken" parameter to an ISR\r
+                                               safe FreeRTOS function. */\r
+                                               xYieldPending = pdTRUE;\r
+                                       }\r
                                }\r
                                else\r
                                {\r
@@ -4475,6 +4529,13 @@ TickType_t uxReturn;
                                        {\r
                                                *pxHigherPriorityTaskWoken = pdTRUE;\r
                                        }\r
+                                       else\r
+                                       {\r
+                                               /* Mark that a yield is pending in case the user is not\r
+                                               using the "xHigherPriorityTaskWoken" parameter in an ISR\r
+                                               safe FreeRTOS function. */\r
+                                               xYieldPending = pdTRUE;\r
+                                       }\r
                                }\r
                                else\r
                                {\r
@@ -4496,11 +4557,9 @@ TickType_t uxReturn;
        TCB_t *pxTCB;\r
        BaseType_t xReturn;\r
 \r
-               pxTCB = ( TCB_t * ) xTask;\r
-\r
                /* If null is passed in here then it is the calling task that is having\r
                its notification state cleared. */\r
-               pxTCB = prvGetTCBFromHandle( pxTCB );\r
+               pxTCB = prvGetTCBFromHandle( xTask );\r
 \r
                taskENTER_CRITICAL();\r
                {\r
@@ -4520,6 +4579,8 @@ TickType_t uxReturn;
        }\r
 \r
 #endif /* configUSE_TASK_NOTIFICATIONS */\r
+/*-----------------------------------------------------------*/\r
+\r
 \r
 #ifdef FREERTOS_MODULE_TEST\r
        #include "tasks_test_access_functions.h"\r
index c7ab9023f007fb4f2a3083d398243985b806f724..0aef5ad71b5f6fb0e103f85a08e0d3959b94a19f 100644 (file)
@@ -178,6 +178,16 @@ PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL;
 \r
 /*-----------------------------------------------------------*/\r
 \r
+#if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+\r
+       /* If static allocation is supported then the application must provide the\r
+       following callback function - which enables the application to optionally\r
+       provide the memory that will be used by the timer task as the task's stack\r
+       and TCB. */\r
+       extern void vApplicationGetTimerTaskMemory( DummyTCB_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint16_t *pusTimerTaskStackSize );\r
+\r
+#endif\r
+\r
 /*\r
  * Initialise the infrastructure used by the timer service task if it has not\r
  * been initialised already.\r
@@ -240,6 +250,10 @@ static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseTy
 BaseType_t xTimerCreateTimerTask( void )\r
 {\r
 BaseType_t xReturn = pdFAIL;\r
+DummyTCB_t *pxTimerTaskTCBBuffer = NULL;\r
+StackType_t *pxTimerTaskStackBuffer = NULL;\r
+uint16_t usTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
+\r
 \r
        /* This function is called when the scheduler is started if\r
        configUSE_TIMERS is set to 1.  Check that the infrastructure used by the\r
@@ -249,16 +263,24 @@ BaseType_t xReturn = pdFAIL;
 \r
        if( xTimerQueue != NULL )\r
        {\r
+\r
+               #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+               {\r
+                       vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &usTimerTaskStackSize );\r
+               }\r
+               #endif /* configSUPPORT_STATIC_ALLOCATION */\r
+\r
+\r
                #if ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 )\r
                {\r
                        /* Create the timer task, storing its handle in xTimerTaskHandle so\r
                        it can be returned by the xTimerGetTimerDaemonTaskHandle() function. */\r
-                       xReturn = xTaskCreate( prvTimerTask, "Tmr Svc", ( uint16_t ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, &xTimerTaskHandle );\r
+                       xReturn = xTaskGenericCreate( prvTimerTask, "Tmr Svc", usTimerTaskStackSize, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, &xTimerTaskHandle, pxTimerTaskStackBuffer, pxTimerTaskTCBBuffer, NULL );\r
                }\r
                #else\r
                {\r
                        /* Create the timer task without storing its handle. */\r
-                       xReturn = xTaskCreate( prvTimerTask, "Tmr Svc", ( uint16_t ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, NULL);\r
+                       xReturn = xTaskGenericCreate( prvTimerTask, "Tmr Svc", usTimerTaskStackSize, NULL, ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, NULL, pxTimerTaskStackBuffer, pxTimerTaskTCBBuffer, NULL );\r
                }\r
                #endif\r
        }\r