Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Call Function with External Stack
Overview
--------

A given function can be executed with a user-allocated stack space which is independent of current task stack. This mechanism can be used to save stack space wasted by tasks which call a common function with intensive stack usage such as ``printf``. The given function can be called inside the shared stack space, which is a callback function deferred by calling :cpp:func:`esp_execute_shared_stack_function`, passing that function as a parameter.
A given function can be executed with a user-allocated stack space which is independent of current task stack. This mechanism can be used to save stack space wasted by tasks which call a common function with intensive stack usage such as ``printf``. The given function can be executed on the shared stack space by calling :cpp:func:`esp_execute_shared_stack_function` and passing it as a parameter.

.. warning::

Expand All @@ -27,12 +27,12 @@ Usage

:cpp:func:`esp_execute_shared_stack_function` takes four arguments:

- a mutex object allocated by the caller, which is used to protect if the same function shares its allocated stack
- a pointer to the top of stack used for that function
- a mutex object allocated by the caller, which is used to protect the shared stack space
- a pointer to the stack used for that function
- the size of stack in bytes
- a pointer to the shared stack function

The user-defined function is deferred as a callback and can be called using the user-allocated space without taking space from current task stack.
The user-defined function is executed immediately as a callback using the user-allocated space without taking space from current task stack.

The usage may look like the code below:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
概述
--------

执行某个给定函数时,可以使用用户分配的堆栈空间,且该堆栈空间独立于当前任务的堆栈。这一机制能够节省在调用常用函数时浪费大量堆栈空间,例如 ``printf`` 函数。具体而言,将给定函数作为参数传入 :cpp:func:`esp_execute_shared_stack_function` 中,给定函数便会在共享堆栈空间内作为回调函数延迟执行
执行某个给定函数时,可以使用用户分配的堆栈空间,且该堆栈空间独立于当前任务的堆栈。如果有多个任务需要调用同一个使用大量堆栈空间的函数,如 ``printf``,这一机制能够节省各个任务的堆栈空间。具体而言,将给定函数作为参数传入 :cpp:func:`esp_execute_shared_stack_function` 中,给定函数便会在共享堆栈空间内执行

.. warning::

:cpp:func:`esp_execute_shared_stack_function` 只会为所提供的共享堆栈内存做最基础的设置。传递给该函数以在共享堆栈空间上执行的函数,或调用该函数的任何函数,都不应执行以下任何操作:
:cpp:func:`esp_execute_shared_stack_function` 只会为所提供的共享堆栈内存做最基础的设置。传递给该函数以在共享堆栈空间上执行的函数,或该函数调用的任何函数,都不应执行以下任何操作:

.. list::

Expand All @@ -19,20 +19,20 @@
:esp32p4: - 使用 AI 协处理器
- 调用 vTaskDelete(NULL) 删除当前运行的任务

此外,从共享堆栈上运行的函数或调用该函数的任何函数来调用回溯,回溯信息都可能不正确。这方面的限制十分严格,因此将来 :cpp:func:`esp_execute_shared_stack_function` 可能会被弃用。如有用例必须使用 :cpp:func:`esp_execute_shared_stack_function` 函数才能实现,请提交 `GitHub Issue <https://github.com/espressif/esp-idf/issues>`_。
此外,共享堆栈上运行的函数,或该函数调用的任何函数中调用回溯,回溯信息都可能不正确。这方面的限制十分严格,因此将来 :cpp:func:`esp_execute_shared_stack_function` 可能会被弃用。如有用例必须使用 :cpp:func:`esp_execute_shared_stack_function` 函数才能实现,请提交 `GitHub Issue <https://github.com/espressif/esp-idf/issues>`_。


使用方法
--------

:cpp:func:`esp_execute_shared_stack_function` 需要四个参数:

- 由调用者分配的互斥锁,防止同一函数共享分配的堆栈
- 指向分配的堆栈顶部的指针
- 由调用者分配的互斥锁,用于保护共享堆栈
- 指向分配的堆栈的指针
- 以字节为单位的堆栈的大小
- 指向需要共享堆栈的函数的指针
- 指向需要使用共享堆栈的函数的指针

通过这一功能,用户指定的函数被作为回调函数延迟执行,并在用户分配的空间中调用,无需从当前任务堆栈中获取空间。
通过这一功能,用户指定的函数被作为回调函数立即执行,并在用户分配的空间中调用,无需从当前任务堆栈中获取空间。

该函数的使用方式如下所示:

Expand Down