Commit Graph

122 Commits

Author SHA1 Message Date
Marius Vikhammer
6cbee5c7f6 Merge branch 'contrib/github_pr_13578' into 'master'
Make FreeRTOS configUSE_TIMERS optional in KConfig (GitHub PR)

Closes IDFGH-12576

See merge request espressif/esp-idf!32576
2024-08-13 10:06:51 +08:00
Sudeep Mohanty
0db5d725ef fix(freertos): Fixed critical section macro in vTaskPlaceOnEventListRestricted()
The vTaskPlaceOnEventListRestricted() did not use the correct macro when
exiting a kernel cirtical section. This does not affect the HW targets
but on the Linux port, this caused an issue as the critical nesting
count became negative, leading to deadlocks. This commit fixes the bug
and updates the linux port to prevent the nesting count from going
negative.
2024-08-09 08:45:23 +02:00
Marius Vikhammer
0bcee8518b fix(freertos): split idf_additions.c event groups to separate file 2024-08-09 11:19:40 +08:00
Konstantin Kondrashov
0bdf675992 fix(linux): Fix warnings for Linux target when COMPILER_STATIC_ANALYZER=y 2024-07-31 11:23:54 +03:00
Sudeep Mohanty
c3da2ace27 fix(freertos): Fixed memory leak issue in vTaskDeleteWithCaps()
vTaskDeleteWithCaps() leaked memory when a task uses the API to delete
itself. This commit adds a fix to avoid the memory leak.

Closes https://github.com/espressif/esp-idf/issues/14222
2024-07-26 16:58:18 +02:00
Sudeep Mohanty
1012172436 fix(freertos): Incorrect assert in FreeRTOS port layer when not in ISR context
This commit fixes an issue where in the FreeRTOS port layer would cause
the portASSERT_IF_IN_ISR() assert check to fail even when the system is
not in an interrupt context.
2024-07-25 12:06:19 +02:00
Darian Leung
5d75bfdb3c
feat(freertos/smp): Update SMP FreeRTOS files to V11.1.0
This commit updates the source files of Amazon SMP FreeRTOS to upstream
V11.1.0 (https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/V11.1.0).

This version contains some new features and bugfixes. See upstream V11.1.0
release notes for more details.

Note: ESP-IDF specific changes to the source file have been preserved
2024-06-03 03:13:58 +08:00
Konstantin Kondrashov
66e6a48efd feat(freertos): Runtime Counter support
Closes https://github.com/espressif/esp-idf/issues/13120
2024-04-18 10:26:38 +03:00
Alexey Lapshin
40be44f827 feat(system): refactor linker scripts
- move .tbss to NOLOAD section
- remove xtensa-specific entities from riscv scripts
- explicit eh_frame terminator instead of "align magic"
- 80 characters line length limit
- refactor comments
- discard .rela sections (the rela data will go to relates sections)
2024-03-19 13:27:11 +04:00
Darian Leung
83c686c744
feat(freertos/smp): Update ports to support Amazon FreeRTOS v11.0.1
- vTaskPreemptionDisable()/vTaskPreemptionEnable() are no longer available in
single-core builds.
- xTaskIncrementTick() calls must now be wrapped by critical section
- Minimal Idle Task renamed to Passive Idle Task
- Port critical section APIs updated
2024-03-05 15:44:12 +08:00
Darian Leung
888678d102
feat(freertos/smp): Add ESP-IDF specific modifications
- Add ESP-IDF specific modifications to FreeRTOS-Kernel-SMP source code
- Update IDF addition source files to support V11 kernel
2024-03-05 15:44:12 +08:00
Darian Leung
421dab29fa
feat(freertos/smp): Update SMP FreeRTOS files to V11.0.1
This commit updates the source files of Amazon SMP FreeRTOS to upstream
V11.0.1 (https://github.com/FreeRTOS/FreeRTOS-Kernel/tree/V11.0.1).

This version contains SMP support.
2024-03-05 15:44:11 +08:00
Alexey Lapshin
824c8e0593 feat(esp_system): allow .bss to spill over into L2MEM above 0x4ff40000
This commit introduce SOC_MEM_NON_CONTIGUOUS_SRAM flag (that enebled for
esp32p4). If SOC_MEM_NON_CONTIGUOUS_SRAM is enabled:

- LDFLAGS+=--enable-non-contiguous-regions
- ldgen.py replaces "arrays[*]" from sections.ld.in with objects under
  SURROUND keyword. (e.g. from linker.lf: data -> dram0_data SURROUND(foo))
- "mapping[*]" - refers to all other data

If SOC_MEM_NON_CONTIGUOUS_SRAM, sections.ld.in file should contain at
least one block of code like this (otherwise it does not make sense):

  .dram0.bss (NOLOAD) :
  {
    arrays[dram0_bss]
    mapping[dram0_bss]
  } > sram_low

  .dram1.bss (NOLOAD) :
  {
    /* do not place here arrays[dram0_bss] because it may be splited
     * between segments */
    mapping[dram0_bss]
  } > sram_high
2024-02-28 19:41:25 +04:00
Erhan Kurubas
029a0582e1 feat(coredump): improve the probability of accessing healthy TCBs 2024-01-22 00:18:28 +08:00
Omar Chebib
102d5bbf72 refactor(riscv): added a new API for the interrupts 2024-01-18 16:36:53 +08:00
Omar Chebib
5cdf145f55 refactor(riscv): refactor crosscore interrupt 2024-01-18 16:27:36 +08:00
Darian Leung
a5d5ee7445 change(xtensa): Deprecate ".../xtensa_context.h" include path
This commit deprecates the "freertos/xtensa_context.h" and "xtensa/xtensa_context.h"
include paths. Users should use "xtensa_context.h" instead.

- Replace legacy include paths
- Removed some unnecessary includes of "xtensa_api.h"
- Add warning to compatibility header
2023-11-30 21:58:52 +08:00
Darian Leung
2204c8e137 change(xtensa): Deprecate ".../xtensa_api.h" include path
This commit deprecates the "freertos/xtensa_api.h" and "xtensa/xtensa_api.h"
include paths. Users should use "xtensa_api.h" instead.

- Replace legacy include paths
- Removed some unnecessary includes of "xtensa_api.h"
- Replaced some calls with "esp_cpu_..." equivalents
- Add warning to compatibility header
2023-11-30 21:58:52 +08:00
Sudeep Mohanty
d507a86285 feat(freertos): Exposed Kconfig option for configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES
This commit exposes the FreeRTOS List integrity check option
configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES via menuconfig.
2023-11-09 14:54:13 +01:00
Omar Chebib
a8b1475fe7 feat(riscv): implement coprocessors save area and FPU support
This commit mainly targets the ESP32-P4. It adds supports for coprocessors on
RISC-V based targets. The coprocessor save area, describing the used coprocessors
is stored at the end of the stack of each task (highest address) whereas each
coprocessor save area is allocated at the beginning of the task (lowest address).
The context of each coprocessor is saved lazily, by the task that want to use it.
2023-10-23 11:10:28 +08:00
KonstantinKondrashov
25c7a59e31 fix(freertos): Use INTERRUPT_CURRENT_CORE_INT_THRESH_REG for esp32p4 2023-09-07 15:25:35 +08:00
Darian Leung
6c66018d5b refactor(freertos/smp): Move vTaskStartSchedulerOtherCores() to API additions to headers
- Move vTaskStartSchedulerOtherCores()
    - implementation to freertos_tasks_c_additions.h
    - declaration to freertos_idf_additions_priv.h as API is private
- Rename vTaskStartSchedulerOtherCores() -> prvStartSchedulerOtherCores() to
indicate that the function is private.
2023-09-05 16:19:42 +08:00
Darian Leung
5227616e57 refactor(freertos/idf): Implicitly include idf_additions.h from FreeRTOS.h
This commit adds an implicit inclusion of `idf_additions.h` to `FreeRTOS.h` in
preparation for moving some IDf specific API to `idf_additions.h`.

This implict inclusion allows existing code to be continue using these
relocated APIs without any changes in header inclusions.

Also removed "#pragma once" directive from "freertos_tasks_c_additions.h" since
that header is included as a source file.
2023-09-05 16:19:42 +08:00
Omar Chebib
8ca191e4c1 fix(esp32p4): Fixed interrupt handling to use the CLIC controller 2023-08-31 12:16:08 +08:00
Darian Leung
39cf3638ae change(freertos): Deprecate usage of vPortCleanUpTCB() by applications
Previously, if CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP was enabled, users
would provide a definition for a vPortCleanUpTCB() hook function that is called
right before a task's memory is freed in prvDeleteTCB(). However,
vPortCleanUpTCB() will be reclaimed by ESP-IDF for internal use in v6.0.

This commit introduces the following changes...

Introduced a new CONFIG_FREERTOS_TASK_PRE_DELETION_HOOK option:

- Provides the same pre-deletion hook functionality. But users now define
vTaskPreDeletionHook() instead.
- CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP still exists, but is marked as
deprecated. This is to maintain compatibility with existing applications
that already define vPortCleanUpTCB().
- Removed redundant --wl --wrap workaround with vPortCleanUpTCB()
- Added todo notes to remove support for user defined vPortCleanUpTCB()
completely in v6.0.
- Updated test cases to use new CONFIG_FREERTOS_TASK_PRE_DELETION_HOOK option

Freed up portCLEAN_UP_TCB() to call a new internal vPortTCBPreDeleteHook():

- vPortTCBPreDeleteHook() now replaces the previous "wrapped" implementation
of vPortCleanUpTCB().
- vPortTCBPreDeleteHook() is an internal task pre-delete hook for IDF FreeRTOS
ports to inject some pre-deletion operations.
- Internal pre-delete hook now invokes user provided vTaskPreDeletionHook()
if enabled.
- Relocated vPortTCBPreDeleteHook() to correct section in port.c
2023-08-23 17:50:08 +08:00
Darian Leung
6fc935e584 refactor(freertos): Refactor usage of portBASE_TYPE to BaseType_t
portBASE_TYPE is an internal macro defined by the porting layer. This commit
changes all references to BaseType_t which is the official type exposed by
FreeRTOS.
2023-07-31 17:10:34 +02:00
Darian Leung
1e51387222 refactor(freertos): Refactor usage of portSTACK_TYPE to StackType_t
portSTACK_TYPE is an internal macro defined by the porting layer. This commit
changes all references to StackType_t which is the official type exposed by
FreeRTOS.
2023-07-31 16:59:41 +02:00
Alexey Lapshin
4df3ff619e feat(esp_system): implement hw stack guard for riscv chips
- add hardware stack guard based on assist-debug module
- enable hardware stack guard by default
- disable hardware stack guard for freertos ci.release test
- refactor rtos_int_enter/rtos_int_exit to change SP register inside them
- fix panic_reason.h header for RISC-V
- update docs to include information about the new feature
2023-07-01 16:27:40 +00:00
Darian Leung
66499f17a5 freertos: Refactor component structure
This commit refactors the "freertos" component's structure as follows:

- "FreeRTOSConfig.h" related files moved to "./config" directory
- Refactored CMakeLists.txt file in preparation for v10.5.1 upgrade
    - Grouped list appends based on component organization
    - Removed some unecessarily public "include_dirs"
- Removed FreeRTOS-openocd.c
    - uxTopUsedPriority has been added back to tasks.c since v10.4.2
    - Thus the workaround in FreeRTOS-openocd.c is no longer needed and can
      be removed.
2023-05-08 18:40:03 +08:00
Darian Leung
76d4c9f592 freertos: Refactor port_systick
This commit refactors port_systick.c so that all ports (RISC-V vs Xtensa) of
all FreeRTOS implementations (IDF vs Amazon SMP FreeRTOS) use the same set of
tick interrupt functions. Thus, these funcitons are now common:

- vPortSetupTimer() to setup the tick interrupt's timer
- xPortSysTickHandler() that is called on each tick interrupt
2023-04-28 23:03:00 +08:00
Jakob Hasse
550ecbe37a feat(freertos): added POSIX/Linux simulator port to FreeRTOS SMP
* Added a POSIX/Linux simulator that is compatible with the Amazon
  FreeRTOS SMP API. Note that the simulator itself is still
  single core, like the IDF FreeRTOS POSIX/Linux simulator.
2023-04-25 13:58:57 +08:00
Darian Leung
5fde889a3d xtensa: Remove OS agnostic files from Amazon SMP FreeRTOS port
The previous commit moved the OS agnostic files from the IDF FreeRTOS port to
the xtensa component, thus can be accessed by both IDF and Amazon SMP FreeRTOS.

This commit removes the redudant copies in the Amazon SMP FreeRTOS port.
2023-04-18 15:51:38 +08:00
Darian Leung
478e041ce5 freertos: Add GetStaticBuffer functions
This commit adds the various ...GetStaticBuffer() functions from upstream
FreeRTOS. See https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/641 for more
details.
2023-04-12 11:45:06 +08:00
Darian Leung
902d8f392d freertos: Fix idf_additions.h include order error
When building for CONFIG_FREERTOS_SMP, "idf_additions.h" was previously
implicitly included by "task.h" so that other ESP-IDF components still have
access to IDF API additions without needing to include "idf_additions.h"
directly.

However, some FreeRTOS headers (e.g., queue.h) will include task.h before
declaring any types (e.g., QueueHandle_t). Thus if any of those types are used
in idf_additions.h, we get a missing type error.

This commit moves the implicity include of idf_additions.h to FreeRTOS.h
2023-04-12 11:45:06 +08:00
Darian Leung
6895e92fd2 freertos: Combine Amazon SMP FreeRTOS and IDF FreeRTOS config files
This commit merges the "FreeRTOSConfig_smp.h" file into the "FreeRTOSConfig.h".
The configurations for all FreeRTOS implementations are now stored in a single
file.
2023-03-22 16:32:29 +08:00
Darian Leung
4f8c6c6277 freertos: Remove xTaskRemoveFromUnorderedEventList compatibility define
xTaskRemoveFromUnorderedEventList is a scheduler internal function, thus will
never be called by users. Therefore, the compatbility define is not necessary.
2023-03-17 20:15:13 +08:00
Darian Leung
29ec3fbacf xtensa: Move default vectors back into xtensa_vectors.S
The default implementation of some xtensa vectors were previously moved to
"xtensa_vector_defaults.S" as weak functions so that they could be overriden.

This commit moves these default vectors back into "xtensa_vectors.S" in
preparation for further refactoring of the xtensa component.
2023-03-10 13:59:01 +08:00
Darian Leung
e21ab0332b freertos(IDF): Refactor port heap functions
Vanilla FreeRTOS expects applications to use one of the heap implementations
provided by FreeRTOS (i.e., heap_x.c), where functions such as pvPortMalloc()
and vPortFree() are defined in the heap implementation.

However, ESP-IDF already provides its own heap implementation
(i.e., esp_heap_caps.h). Thus, the pvPortMallc()/vPortFree() functions were
previously overriden by macro to call esp_heap functions directly.

This commit refactors the FreeRTOS port's heap as such:

- Added a heap_idf.c that implements all of the heap related functions required
  by FreeRTOS source
- All dynamic memory allocated by FreeRTOS is from internal memory. Thus, the
  FreeRTOS heap is the internal memory subset of the ESP-IDF heap.
- Removed some old macros to reduce diff from upstream source code.
2023-03-06 16:00:29 +08:00
Alexey Lapshin
d1214aef8c freertos: riscv: fix vPortTaskWrapper for clang 2023-02-20 13:09:42 +08:00
morris
6c1d98d556 systimer: assign counter and alarm in esp_hw_support 2023-01-10 17:05:49 +08:00
Darian Leung
92bbf85350 freertos: Fix clang-tidy warning on pxPortInitialiseStack() 2022-12-23 15:29:17 +08:00
Darian Leung
9300bef9b8 freertos(SMP): Refactor FPU handling on the Xtensa port of Amaazon SMP FreeRTOS
This commit refactors the FPU handling code on the Xtensa port of Amazon SMP
FreeRTOS in the following ways:

Auto-pinning via XT_RTOS_CP_EXC_HOOK
------------------------------------

The "_xt_coproc_exc" exception would previously automatically pin a task that
uses the FPU to the current core (to ensure that we can lazy save the task's FPU
context). However, this would mean that "xtensa_vectors.S" would need to be
OS-aware (to read the task's TCB structure).

This is now refactored so that "_xt_coproc_exc" calls a CP exception hook
function ("XT_RTOS_CP_EXC_HOOK") implemented in "portasm.S", thus allowing
"xtensa_vectors.S" to remain OS agnostic.

Using macros to acquire owner spinlock
--------------------------------------

The taking and relasing of the "_xt_coproc_owner_sa_lock" is now mostly
abstracted as the "spinlock_take" and "spinlock_release" macro. As a result,
"_xt_coproc_release" and "_xt_coproc_exc" are refactored so that:

- They are closer to their upstream (original) versions
- The spinlock is only taken when building for multicore
- The spinlock held region is shortened (now only protects the instructions
  that access the "_xt_coproc_owner_sa" array

Other Changes
-------------

- Updated placing and comments of various "offset_..." constants used by
  portasm.S
- Update description of "get_cpsa_from_tcb" assembly macro
- Tidied up some typos in the ".S" files
2022-12-23 15:29:17 +08:00
Darian Leung
fd48daf278 freertos(SMP): Fix SMP FreeRTOS Xtensa port FPU/Coproccessor bugs
This commit fixes the following FPU/Coprocessor bugs in the Xtensa port of
Amazon SMP FreeRTOS:

- vPortCleanUpCoprocArea() does not calculate the correct pointer to the
task's CPSA (located on the task's stack). This can result in
    - _xt_coproc_release() not releasing the task's CP ownership
    - The next coprocessor exception will write the current CP owner (i.e., the
      deleted task's CPSA) leading to memory corruption
- _xt_coproc_release() writes xCoreID instead of 0 when clearing a CP owner.
  This results in the next CP exception trying to load the CP owner's CPSA at
  the address of "xCoreID", leading to a double exception.
2022-12-23 15:29:17 +08:00
Darian Leung
486cc33fb3 freertos: Refactor port common functions
This commit refactors port_common.c so that it only contains implementation of
FreeRTOS port functions that are common to all FreeRTOS ports (i.e., on all
architectures and on all FreeRTOS implementations).
2022-12-08 01:57:30 +08:00
Darian Leung
09690906e7 freertos: Refactor OS startup functions
This commit refactors the OS startup functions as follows:

- Moved the OS/app startup functions listed below to "app_startup.c". Their
    implementations are now common to all ports (RISC-V and Xtensa) of all
    FreeRTOS implementations (IDF and Amazon SMP).
    - esp_startup_start_app()
    - esp_startup_start_app_other_cores()
- Removed esp_startup_start_app_common() as app startup functions are now
    already common to all ports.
- Added extra logs to "main_task" to help with user debugging

Note: Increased startup delay on "unity_task". The "unity_run_menu()" is non
blocking, thus if the main task or other startup tasks have not been freed
by the time "unity_run_menu()" is run, those tasks will be freed the next time
"unity_task" blocks. This could cause some tests to have a memory leak, thus
the "unity_task" startup delay has increased.
2022-12-08 01:57:30 +08:00
Marius Vikhammer
ea249dc3a6 freertos: add missing header include for esp_chip_info.h to port.c
Closes https://github.com/espressif/esp-idf/issues/10310
2022-12-06 11:31:15 +08:00
Omar Chebib
6fe563163c RISC-V: fix PC not saved when using backtrace 2022-11-18 15:07:38 +08:00
Omar Chebib
d580f6b076 RISC-V: Create a wrapper around FreeRTOS Tasks to detect the ones returning 2022-11-18 15:07:32 +08:00
Darian Leung
623f20d2b5 freertos(SMP): Fix SMP FreeRTOS RISC-V statement expression macro
Macros that need to reteurn a value should use GCC statement expression macro
syntax. This commit fixes the portTRY_ENTER_CRITICAL() in the RISC-V port of
SMP FreeRTOS to be a statement expression macro.
2022-11-16 17:51:10 +08:00
Jakob Hasse
cce1f9dee4 Merge branch 'feature/freertos_task_notification_configurable' into 'master'
freertos: make num of task notifications configurable

Closes IDFGH-7819

See merge request espressif/esp-idf!20880
2022-11-16 17:11:03 +08:00