]> granicus.if.org Git - esp-idf/commitdiff
freertos: Add config parameters to customize FreeRTOS behaviour.
authorDaniel Campora <daniel@pycom.io>
Mon, 20 Mar 2017 21:32:01 +0000 (22:32 +0100)
committerAngus Gratton <angus@espressif.com>
Wed, 22 Mar 2017 07:21:38 +0000 (15:21 +0800)
The options are:
    - SUPPORT_STATIC_ALLOCATION
    - ENABLE_STATIC_TASK_CLEAN_UP_HOOK
    - TIMER_TASK_PRIORITY
    - TIMER_TASK_STACK_DEPTH
    - TIMER_QUEUE_LENGTH

Merges #444 https://github.com/espressif/esp-idf/pull/444

components/freertos/Kconfig
components/freertos/include/freertos/FreeRTOSConfig.h
components/freertos/tasks.c

index b4bcfc3fe13daffb93a0103bc48f957daf06998d..dd9a95b0649ecf2f1e2c79a67a254099193ec2a5 100644 (file)
@@ -197,6 +197,81 @@ config FREERTOS_MAX_TASK_NAME_LEN
 
         For most uses, the default of 16 is OK.
 
+config SUPPORT_STATIC_ALLOCATION
+    bool "Enable FreeRTOS static allocation API"
+    default n
+    help
+        FreeRTOS gives the application writer the ability to instead provide the memory
+        themselves, allowing the following objects to optionally be created without any
+        memory being allocated dynamically:
+
+            - Tasks
+            - Software Timers
+            - Queues
+            - Event Groups
+            - Binary Semaphores
+            - Counting Semaphores
+            - Recursive Semaphores
+            - Mutexes
+
+        Whether it is preferable to use static or dynamic memory allocation is dependent on
+        the application, and the preference of the application writer. Both methods have pros
+        and cons, and both methods can be used within the same RTOS application.
+
+        Creating RTOS objects using statically allocated RAM has the benefit of providing the
+        application writer with more control: RTOS objects can be placed at specific memory locations.
+        The maximum RAM footprint can be determined at link time, rather than run time.
+        The application writer does not need to concern themselves with graceful handling of memory allocation failures.
+        It allows the RTOS to be used in applications that simply don't allow any dynamic memory allocation
+        (although FreeRTOS includes allocation schemes that can overcome most objections).
+
+config ENABLE_STATIC_TASK_CLEAN_UP_HOOK
+    bool "Enable static task clean up hook"
+    depends on SUPPORT_STATIC_ALLOCATION
+    default n
+    help
+        Enable this option to make FreeRTOS call the static task clean up hook when a task is deleted.
+
+        Bear in mind that if this option is enabled you will need to implement the following function:
+
+            void vPortCleanUpTCB ( void *pxTCB ) {
+                // place clean up code here
+            }
+
+config TIMER_TASK_PRIORITY
+    int "FreeRTOS timer task priority"
+    range 1 25
+    default 1
+    help
+        The timer service task (primarily) makes use of existing FreeRTOS features, allowing timer
+        functionality to be added to an application with minimal impact on the size of the application's
+        executable binary.
+
+        Use this constant to define the priority that the timer task will run at.
+
+config TIMER_TASK_STACK_DEPTH
+    int "FreeRTOS timer task stack size"
+    range 1536 32768
+    default 2048
+    help
+        The timer service task (primarily) makes use of existing FreeRTOS features, allowing timer
+        functionality to be added to an application with minimal impact on the size of the application's
+        executable binary.
+
+        Use this constant to define the size (in bytes) of the stack allocated for the timer task.
+
+config TIMER_QUEUE_LENGTH
+    int "FreeRTOS timer queue length"
+    range 5 20
+    default 10
+    help
+        FreeRTOS provides a set of timer related API functions. Many of these functions use a standard
+        FreeRTOS queue to send commands to the timer service task. The queue used for this purpose is
+        called the 'timer command queue'. The 'timer command queue' is private to the FreeRTOS timer
+        implementation, and cannot be accessed directly.
+
+        For most uses the default value of 10 is OK.
+
 menuconfig FREERTOS_DEBUG_INTERNALS
     bool "Debug FreeRTOS internals"
     default n
index 4f403303983ab60032ec2c66cece268711ee4868..250879f30648f99883889914dff04ce1299a12eb 100644 (file)
 #define configUSE_NEWLIB_REENTRANT             1
 
 #define configSUPPORT_DYNAMIC_ALLOCATION    1
+#define configSUPPORT_STATIC_ALLOCATION CONFIG_SUPPORT_STATIC_ALLOCATION
+
+#ifndef __ASSEMBLER__
+#if CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK
+extern void vPortCleanUpTCB ( void *pxTCB );
+#define portCLEAN_UP_TCB( pxTCB )           vPortCleanUpTCB( pxTCB )
+#endif
+#endif
 
 /* Test FreeRTOS timers (with timer task) and more. */
 /* Some files don't compile if this flag is disabled */
 #define configUSE_TIMERS                    1
-#define configTIMER_TASK_PRIORITY           1
-#define configTIMER_QUEUE_LENGTH            10
-#define configTIMER_TASK_STACK_DEPTH        configMINIMAL_STACK_SIZE
+#define configTIMER_TASK_PRIORITY           CONFIG_TIMER_TASK_PRIORITY
+#define configTIMER_QUEUE_LENGTH            CONFIG_TIMER_QUEUE_LENGTH
+#define configTIMER_TASK_STACK_DEPTH        CONFIG_TIMER_TASK_STACK_DEPTH
 
 #define INCLUDE_xTimerPendFunctionCall      1
 #define INCLUDE_eTaskGetState               1
index b37e5925497cb0525640be1bcc5b18b02b1609de..145554a740ce1511e1e53d9c36c502affd8364cb 100644 (file)
@@ -3763,11 +3763,6 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
 
        static void prvDeleteTCB( TCB_t *pxTCB )
        {
-               /* This call is required specifically for the TriCore port.  It must be
-               above the vPortFree() calls.  The call is also used by ports/demos that
-               want to allocate and clean RAM statically. */
-               portCLEAN_UP_TCB( pxTCB );
-
                /* Free up the memory allocated by the scheduler for the task.  It is up
                to the task to free any memory allocated at the application level. */
                #if ( configUSE_NEWLIB_REENTRANT == 1 )
@@ -3806,6 +3801,7 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
                                /* Neither the stack nor the TCB were allocated dynamically, so
                                nothing needs to be freed. */
                                configASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB     )
+                               portCLEAN_UP_TCB( pxTCB );
                                mtCOVERAGE_TEST_MARKER();
                        }
                }