enrico_adelco wrote on Tuesday, November 11, 2008:
Here follow a patch to apply FreeRTOS 5.1.0 to have STACK and TCB as static and not dynamic memory. It needs following macros:
#define configUSE_STATIC_STACK 1
#define configUSE_STATIC_TCB 1
#if (configUSE_STATIC_TCB == 1)
#define configMAX_TASK_NUMBER 4
#endif
Patch is:
— D:/FreeRTOS_5.1.0/Source/tasks.c Fri Oct 24 18:57:34 2008
+++ D:/FreeRTOS/Source/tasks.c Tue Nov 11 14:43:36 2008
@@ -146 +146,3 @@
-
+#if (configUSE_STATIC_TCB == 1)
+static tskTCB tasks[configMAX_TASK_NUMBER];
+#endif
@@ -364,0 +367,3 @@
+#if (configUSE_STATIC_STACK == 1)
+ pxNewTCB->pxStack = (portSTACK_TYPE *)pvParameters;
+#endif
@@ -396 +401,7 @@
- pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pvTaskCode, pvParameters );
+ pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pvTaskCode,
+#if (configUSE_STATIC_STACK == 1)
+ 0
+#else
+ pvParameters
+#endif
+ );
@@ -963 +974,3 @@
-
+#if (configUSE_STATIC_STACK == 1)
+static portSTACK_TYPE idleStack[tskIDLE_STACK_SIZE];
+#endif
@@ -969 +982,7 @@
- xReturn = xTaskCreate( prvIdleTask, ( signed portCHAR * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
+ xReturn = xTaskCreate( prvIdleTask, ( signed portCHAR * ) "IDLE", tskIDLE_STACK_SIZE, ( void * )
+#if (configUSE_STATIC_STACK == 1)
+ idleStack
+#else
+ NULL
+#endif
+ , tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
@@ -1784,0 +1804,3 @@
+#if (configUSE_STATIC_TCB == 1)
+ pxNewTCB = &tasks[uxCurrentNumberOfTasks];
+#else
@@ -1787,0 +1810 @@
+#endif
@@ -1788,0 +1812 @@
+#if (configUSE_STATIC_STACK == 0)
@@ -1807,0 +1832 @@
+#endif
When you create a new task, you have to pass, on pvParameters, pointer to portSTACK_TYPE array of number of elements equal to usStackDepth. For example:
#define MY_STACK_SIZE 100
static portSTACK_TYPE myStack[MY_STACK_SIZE];
…
xTaskCreate(task1, "Task1", MY_STACK_SIZE, myStack, TASK_PRIORITY, NULL);
Make sure that configMAX_TASK_NUMBER is more or equal than xTaskCreate calls.
NOTES:
- Tested on ARM7 LPC2000 porting (LPC2478 w/external memory and LCD)
- No support for vTaskDelete!!! TCB location are not free’d
- No check for array of TCB insufficient
These changes are very useful if you use dynamic allocation (malloc/free) in HEAP located on external memory. After these changes, my application duplicated speed on widgets drawing