menu "FreeRTOS"

config DISABLE_FREERTOS
    bool "Disable FreeRTOS"
    default n
    help
        Enable this option, FreeRTOS will not be compiled and linked, and the user
        can user other OS platform.

config FREERTOS_ENABLE_REENT
    bool "Enable \"reent\" function"
    default n
    select NEWLIB_ENABLE
    help
        Enable "reent" function and FreeRTOS should use "reent" function of newlib.

        The configuration will enable newlib.

config FREERTOS_HZ
    int "Tick rate (Hz)"
    range 1 1000
    default 100
    help
        Select the tick rate at which FreeRTOS does pre-emptive context switching.

        The value must be the divisor of 1000, otherwise it may cause time mistake.

config FREERTOS_MAX_HOOK
    int "FreeRTOS hook max number"
    range 1 16
    default 2
    help
        configurate the max number of FreeRTOS hook function.

config FREERTOS_IDLE_TASK_STACKSIZE
    int "Idle Task stack size"
    range 1024 32768
    default 1024
    help
        The idle task has its own stack, sized in bytes. The default size is enough for most uses. Size can be reduced
        to 1024 bytes if no (or simple) FreeRTOS idle hooks are used and pthread local storage or FreeRTOS local storage
        cleanup callbacks are not used.

        The stack size may need to be increased above the default if the app installs idle or thread local storage
        cleanup hooks that use a lot of stack memory.

config FREERTOS_ISR_STACKSIZE
    int "ISR stack size"
    range 512 8192
    default 512
    help
        The interrupt handlers have their own stack. The size of the stack can be defined here.

config FREERTOS_EXTENED_HOOKS
    bool "Use FreeRTOS extened hooks"
    default n
    help
        By using the "esp_register_freertos_xxx_hook system", extened hook function offers a number
        of registerable hooks/callback functions that are called when a timer tick happens,
        the idle thread runs etc.

        Otherwise User can also use FreeRTOS raw hook functions "vApplicationIdleHook" and
        "vApplicationTickHook".

config FREERTOS_GLOBAL_DATA_LINK_IRAM
    bool "Link FreeRTOS global data to IRAM"
    default y
    depends on !LWIP_HIGH_THROUGHPUT
    depends on !SOC_FULL_ICACHE
    help
        Link FreeRTOS global data(.bss .data COMMON) from DRAM to IRAM.

config FREERTOS_CODE_LINK_TO_IRAM
    bool "Link FreeRTOS code to IRAM"
    default n
    help
        Link FreeRTOS code from Flash to IRAM.

config FREERTOS_TIMER_STACKSIZE
    int "Timer stack size"
    default 2048
    help
        The size of the stack used by the timer in FreeRTOS.

config TASK_SWITCH_FASTER
    bool "Task switch faster"
    default y
    help
        Enable this option, linking task switch function and its father functions to IRAM
        to speed up task switch. It is specific for faster I/O application and so on.

        But it may cost more 1KB IRAM, so user global heap may decrease 1KB.

config USE_QUEUE_SETS
    bool "Using Queue Sets"
    default n
    help
        Enable this option, the FreeRTOS macro "configUSE_QUEUE_SETS" in file "FreeRTOSConfig.h" will be set to be 1.

config ENABLE_FREERTOS_SLEEP
    bool "Enable FreeRTOS SLEEP"
    default n
    help
        Enable this option, FreeRTOS sleep module at idle task will be enable.
        
        The module is not working now, so if users want to make it work, they should do this themselves. 

config FREERTOS_USE_TRACE_FACILITY
    bool "Enable FreeRTOS trace facility"
    default n
    help
        If enabled, configUSE_TRACE_FACILITY will be defined as 1 in FreeRTOS.
        This will allow the usage of trace facility functions such as
        uxTaskGetSystemState().

config FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
    bool "Enable FreeRTOS stats formatting functions"
    depends on FREERTOS_USE_TRACE_FACILITY
    default n
    help
        If enabled, configUSE_STATS_FORMATTING_FUNCTIONS will be defined as 1 in
        FreeRTOS. This will allow the usage of stats formatting functions such
        as vTaskList().

config FREERTOS_GENERATE_RUN_TIME_STATS
    bool "Enable FreeRTOS to collect run time stats"
    default n
    select FREERTOS_USE_TRACE_FACILITY
    select FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
    help
        If enabled, configGENERATE_RUN_TIME_STATS will be defined as 1 in
        FreeRTOS. This will allow FreeRTOS to collect information regarding the
        usage of processor time amongst FreeRTOS tasks. Run time stats are
        generated using either the ESP Timer or the CPU Clock as the clock
        source (Note that run time stats are only valid until the clock source
        overflows). The function vTaskGetRunTimeStats() will also be available
        if FREERTOS_USE_STATS_FORMATTING_FUNCTIONS and
        FREERTOS_USE_TRACE_FACILITY are enabled. vTaskGetRunTimeStats() will
        display the run time of each task as a % of the total run time of all
        CPUs (task run time / no of CPUs) / (total run time / 100 )

choice FREERTOS_RUN_TIME_STATS_CLK
    prompt "Choose the clock source for run time stats"
    depends on FREERTOS_GENERATE_RUN_TIME_STATS
    default FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
    help
        Choose the clock source for FreeRTOS run time stats. Options are CPU0's
        CPU Clock or the ESP Timer. Both clock sources are 32 bits. The CPU
        Clock can run at a higher frequency hence provide a finer resolution
        but will overflow much quicker. Note that run time stats are only valid
        until the clock source overflows.

config FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
    bool "Use ESP TIMER for run time stats"
    help
        ESP Timer will be used as the clock source for FreeRTOS run time stats.
        The ESP Timer runs at a frequency of 1MHz regardless of Dynamic
        Frequency Scaling. Therefore the ESP Timer will overflow in
        approximately 4290 seconds.

config FREERTOS_RUN_TIME_STATS_USING_CPU_CLK
    bool "Use CPU Clock for run time stats"
    help
        CPU Clock will be used as the clock source for the generation of run
        time stats. The CPU Clock has a frequency dependent on
        ESP32_DEFAULT_CPU_FREQ_MHZ and Dynamic Frequency Scaling (DFS).
        Therefore the CPU Clock frequency can fluctuate between 80 to 240MHz.
        Run time stats generated using the CPU Clock represents the number of
        CPU cycles each task is allocated and DOES NOT reflect the amount of
        time each task runs for (as CPU clock frequency can change). If the CPU
        clock consistently runs at the maximum frequency of 240MHz, it will
        overflow in approximately 17 seconds.

endchoice

endmenu
