Commit Graph

187 Commits

Author SHA1 Message Date
Darian Leung
7b4dba4ffd refactor(freertos/idf): Move vTaskSetThreadLocalStoragePointerAndDelCallback()
This commit moves vTaskSetThreadLocalStoragePointerAndDelCallback() from
`tasks.c`/`task.h` to `freertos_tasks_c_additions.h`/`idf_additions.h`.
2023-09-05 16:20:59 +08:00
Darian Leung
5de6a9aff6 refactor(freertos/idf): Move compatibility functions
This function moves ulTaskNotifyTake()/xTaskNotifyWait() from IDF FreeRTOS
`tasks.c` to `freertos_compatibility.c`. These functions were kept for
pre-compiled library compatibilty. Move them reduces the kernel source code
difference when compared to upstream FreeRTOS.
2023-09-05 16:20:59 +08:00
Darian Leung
0db40f9e6c refactor(freertos/idf): Move IDF task utility functions to API addition headers
This commit combines various task utility API additions in IDF FreeRTOS and with
their Amazon SMP FreeRTOS addition counterparts. The folloiwng functions have
been moved to freertos_tasks_c_additions.h and idf_additions.h as these API
are considered public:

- xTaskGetCurrentTaskHandleForCPU()
- xTaskGetIdleTaskHandleForCPU()
- xTaskGetAffinity()
- pxTaskGetStackStart()

Also fixed in missing #if macros when vTaskCoreAffinityGet() is called in
Amazon SMP FreerTOS tests.
2023-09-05 16:20:59 +08:00
Darian Leung
db9d9658f9 refactor(freertos/idf): Move xTaskIncrementTickOtherCores() to IDF additition headers
This commit moves xTaskIncrementTickOtherCores() to freertos_tasks_c_additions.h
and freertos_idf_additions_priv.h (as API is private). This reduces the code
differences cmpared to upstream FreeRTOS.
2023-09-05 16:20:59 +08:00
Darian Leung
8825c8dda9 refactor(freertos/idf): Move critical section API to IDF addition headers
- The following IDF API additions are moved to freertos_tasks_c_additions.h
(implementation) and freertos_idf_additions_priv.h (declaration) as APIs are
private. This reduces the source code difference from upstream.
    - prvENTER_CRITICAL_OR_SUSPEND_ALL()
    - prvEXIT_CRITICAL_OR_RESUME_ALL()
    - prvENTER_CRITICAL_OR_MASK_ISR()
    - prvEXIT_CRITICAL_OR_UNMASK_ISR()
    - vTaskTakeKernelLock()
    - vTaskReleaseKernelLock()
- Rename vTask[Take/Release]KernelLock() to prv[Take/Release]KernelLock() to
indicate that the this API is private.
2023-09-05 16:20:59 +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
Darian
bd9d6b82ab Merge branch 'bugfix/freertos_private_critical_section_macro' into 'master'
fix(freertos): Fixed bug with prvENTER/EXIT_CRITICAL_OR_MASK_ISR() macro

See merge request espressif/esp-idf!25705
2023-09-04 14:18:11 +08:00
Sudeep Mohanty
62ee4135e0 Merge branch 'bugfix/freertos_incorrect_xPortCanYield' into 'master'
fix(freertos): Corrected xPortCanYield() for esp32p4

See merge request espressif/esp-idf!25679
2023-09-04 09:33:25 +08:00
Darian Leung
75a3c99581 fix(freertos): Fixed bug with prvENTER/EXIT_CRITICAL_OR_MASK_ISR() macro
Fixed an undiscovered bug with prvENTER_CRITICAL_OR_MASK_ISR() and
prvEXIT_CRITICAL_OR_MASK_ISR() where the `uxInterruptStatus` argument was not
used.

However, all calls of this macro provide a local `uxSavedInterruptStatus`
variable, leading to this bug being hidden.
2023-09-02 02:27:09 +08:00
Sudeep Mohanty
d9a3e3bb86 fix(freertos): Corrected xPortCanYield() for esp32p4
This commit updates the xPortCanYield() for esp32p4 by correcting the
return condition. Previously, the API would return true if an ISR of
priority 1 was received which is incorrect.
2023-08-31 17:45:17 +08:00
Omar Chebib
8ca191e4c1 fix(esp32p4): Fixed interrupt handling to use the CLIC controller 2023-08-31 12:16:08 +08:00
Sudeep Mohanty
ec4cd2bb19 docs(freertos): Updated FreeRTOS documentation for ESP32-P4 2023-08-28 10:07:43 +08:00
Darian
ede131ce73 Merge branch 'refactor/freertos_tslfcb_and_coproc_cleanup' into 'master'
refactor(freertos): Remove portCLEAN_UP_COPROC() and TLSP deletion callback kernel changes from IDF FreeRTOS

See merge request espressif/esp-idf!25481
2023-08-25 15:34:40 +08:00
Marius Vikhammer
e07023292a Merge branch 'feature/p4_spinlocks' into 'master'
esp32p4: support spinlocks

Closes IDF-7771

See merge request espressif/esp-idf!25036
2023-08-25 11:43:38 +08:00
Darian Leung
57eb41ce83 refactor(freertos): Call TLSP deletion callback from portCLEAN_UP_TCB()
Previously, TLSP deletion callbacks were...

- Stored in a seprate TCB member "pvThreadLocalStoragePointersDelCallback"
- Called separately via multipole prvDeleteTLS() insertions in tasks.c

This commit refactors how TLSP deletion callbacks are stored and called:

- TLSP deletion callbacks are now stored in "pvThreadLocalStoragePointers"
directly. configNUM_THREAD_LOCAL_STORAGE_POINTERS is doubled in size so that
the deletion callbacks are stored in the latter half of the array

- The callbacks are now called via "portCLEAN_UP_TCB()". As such, the
prvDeleteTLS() additions are no longer needed and the function can be removed

- Removed some legacy TLSP tests using the old method of storing the callback
pointers.

This commit reduces the source code diff between IDF FreeRTOS and upstream
vanilla FreeRTOS, in preparation for v10.5.1 upgrade.
2023-08-24 19:32:06 +08:00
Darian Leung
5f2443b7d1 refactor(freertos): Remove portCLEAN_UP_COPROC()
portCLEAN_UP_COPROC() was an IDF specific addition to FreeRTOS, where the
macro was called from prvDeleteTCB() to clean up the coprocessor context of a
deleted task.

This commit removes portCLEAN_UP_COPROC(). The coprocessor cleanup routine
(i.e., vPortCleanUpCoprocArea()) is now called via portCLEAN_UP_TCB()->
vPortTCBPreDeleteHook().

This removes a minor code difference between IDF FreeRTOS and upstream.
2023-08-24 19:32:06 +08:00
Marius Vikhammer
0d9f9e6816 feat(core-systems): add support for spinlock/compare and set on esp32p4 2023-08-24 10:30:25 +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
Sudeep Mohanty
4e51c6b049 feat(freertos): Added changes for multi-core RISC-V port for FreeRTOS
This commit updates the FreeRTOS port layer for multi-core RISC-V targets.
2023-08-22 15:35:15 +08:00
Darian Leung
1620d97299 change(freertos): Optimized xTaskRemoveFromEventList()
This commit optimizes xTaskRemoveFromEventList() by removing the
listLIST_IS_EMPTY() check from single core builds. The scenario of the event
list being empty when the function is called can only occur on multi-core
builds.
2023-08-09 16:43:52 +08:00
Darian Leung
5947314431 fix(freertos): Fix vTaskRemoveFromUnorderedEventList()
This commit fixes and optimizes vTaskRemoveFromUnorderedEventList() in the
following ways:

- Fixed bug in single core builds where the unblocked task would be placed on
xPendingReadyList.
    - If an ISR occurs while accessing xPendingReadyList, and the ISR also
      accesses the xPendingReadyList, xPendingReadyList would be corrupted.
    - In single core builds, this function is only called from event groups with
      the scheduler suspended. Thus the function should have exclusive access to
      pxReadyTasksLists instead of xPendingReadyList.
    - The function's single core logic has now been updated to match upstream
      behavior, by always placing the unblocked task on pxReadyTasksLists.

- Optimized the function for single core builds by removing the
taskCAN_BE_SCHEDULED() check.
    - In single core builds, given that the function is always called with the
      scheduler suspended
    - Thus, the taskCAN_BE_SCHEDULED (and the subsequent routine to place the
      unblocked task on the xPendingReadyList) is not necessary for single core
      builds.
    - The function now matches upstream behavior in single core builds.

Closes https://github.com/espressif/esp-idf/issues/11883
2023-08-09 16:43:52 +08:00
Darian Leung
fdcab76128 fix(freertos): taskCAN_BE_SCHEDULED macro parenthesis
This commit adds missing parenthesis around the taskCAN_BE_SCHEDULED macro so
that it can properly used with a negation operator.
2023-08-09 15:54:14 +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
Armando
fd096c012d change(vector.S): port hw stack guard change to p4 2023-07-25 05:59:10 +00:00
Armando
5986e63c47 change(riscv): added fence after CLIC_INT_THRESH_REG is set 2023-07-25 05:59:10 +00:00
Armando
48ee1ba36e feat(freertos): base support on p4 2023-07-25 05:59:10 +00: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
Zim Kalinowski
54576b7528 Merge branch 'bugfix/freertos_fix_unordered_event_list' into 'master'
freertos: Updated vTaskRemoveFromUnorderedEventList() to consider scheduler state before adding task to ready list

Closes IDF-5785

See merge request espressif/esp-idf!23482
2023-05-10 01:48:47 +08:00
Sudeep Mohanty
abe5311a22 freertos: Updated vTaskRemoveFromUnorderedEventList() to consider scheduler state before adding task to ready list
vTaskRemoveFromUnorderedEventList() runs under the assumption that the
scheduler is suspended during the call. However, for IDF FreeRTOS, this
is not true. When dual-core system is active, this API call is made in
a critical section but without suspending the scheduler. This commit
updates the vTaskRemoveFromUnorderedEventList() function to now consider
the scheduler state on either cores before adding a task to the ready list.
2023-05-09 10:47:24 +02:00
Sudeep Mohanty
1acd2b5ce7 freertos-idf: Fixed incorrect scheduler suspension check in xTaskRemoveFromEventList()
This commit fixes a bug in xTaskRemoveFromEvenetList() where in the
check for scheduler suspension did not account for nested suspensions.
Additionally, this commit updates all checks for scheduler
suspension to follow a uniform way.
2023-05-09 10:28:02 +02:00
Darian Leung
cf595293af freertos: Move port_systick to common directory
This commit moves port_systick to a directory that ia accessible to both
IDF FreeRTOS and Amazon SMP FreeRTOS.
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
b2c074bb70 xtensa: Move Xtensa RTOS porting layer files to xtensa component
When porting an RTOS to the Xtensa architecture, there are a few files that
are common to all Xtensa RTOS ports. These files form the Xtensa RTOS porting
layer (e.g., "xtensa_vectors.S", "xtensa_context.S"). An Xtensa RTOS port is
expected to provide an RTOS specific "xtensa_rtos.h" header to interface with
the Xtensa RTOS porting layer.

Previously, the Xtensa RTOS porting layer files were placed in the FreeRTOS
component. This commit does the following:

1. Moves the Xtensa RTOS porting layer files from the `freertos` component to
the `xtensa` component. The following files were moved:

    - xtensa_asm_utils.h
    - xtensa_context.S
    - xtensa_loadstore_handler.S
    - xtensa_vectors.S

2. Refactored xtensa component include paths to separate Xtensa RTOS porting
layer headers.

- Xtensa HAL headers included via `#include <xtensa/...h>`
- Xtensa RTOS porting layer headers included via `#include <...h>`

Note: The xtensa files in the Amazon SMP FreeRTOS port are not moved/deleted in
this commit to ensure the moved files retain a clean diff history.
2023-04-18 15:28:05 +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
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
05bda6595d freertos: Move FreeRTOSConfig_arch.h
This commit moves the FreeRTOSConfig_arc.h to the "esp_additions" directory
so that they can also be used for SMP FreeRTOS builds.
2023-03-22 16:32:29 +08:00
Sudeep Mohanty
9b81e2b189 freertos: Schedule tasks unblocked by an ISR on a core with scheduler running if core affinity matches
FromISR APIs would put an unblocked task on the pending ready list if
the scheduler is suspended on the current core, irrespective of the
task's core affinity and the state of the scheduler on the other core.
This commit updates this behavior by allowing tasks to get scheduled on
a core which has the scheduler running as long as the task's core
affinity allows it.
2023-03-15 07:43:33 +00:00
Darian
a8948eb130 Merge branch 'refactor/xtensa_default_vectors' into 'master'
Xtensa: Move default vectors back into xtensa_vectors.S

Closes IDF-7022

See merge request espressif/esp-idf!20512
2023-03-11 01:00:48 +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
77ca79a5e9 Merge branch 'refactor/freertos_check_scheduler_suspend_asserts' into 'master'
FreeRTOS(IDF): Refactor configASSERTs for scheduler suspension

Closes IDF-5889

See merge request espressif/esp-idf!22576
2023-03-09 20:19:57 +08:00
Darian Leung
353b25410a freertos: Refactor configASSERTs for scheduler suspension
This commit adds a common macro for the differing configASSERT() calls that
check if the scheduler is suspended outside a critical section. This macro
allows vanilla behavior to be restored for single core builds. Also added
comments explaining why xTaskGetSchedulerState() is called instead when
building for SMP.
2023-03-07 18:12:15 +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
Jakob Hasse
9991862a10 fix(linux): fix build errors and warnings, remove ignore file 2023-01-18 09:24:28 +08:00
morris
f7c3d791a2 Merge branch 'feature/systimer_support_esp32h2' into 'master'
systimer: assign counter and alarm in esp_hw_support

Closes IDF-6484, IDF-5323, and IDF-6230

See merge request espressif/esp-idf!21984
2023-01-12 11:01:17 +08:00
morris
6c1d98d556 systimer: assign counter and alarm in esp_hw_support 2023-01-10 17:05:49 +08:00
Jakob Hasse
83afda922b style(freertos/linux): improved docs and coding style 2022-12-29 12:05:15 +08:00
Darian Leung
92bbf85350 freertos: Fix clang-tidy warning on pxPortInitialiseStack() 2022-12-23 15:29:17 +08:00
Darian Leung
45badf864f freertos(IDF): Allow cross-core freeing of task memory when deleting tasks
Previously, IDF FreeRTOS would restrict the clean up of task memory (done by
vTaskDelete() or the Idle task) to only tasks pinned to the current core or
unpinned tasks. This was due to the need to clear the task's coprocessor
ownership on the other core (i.e., "_xt_coproc_owner_sa"). But this restriction
can be lifted by simply protecting access of "_xt_coproc_owner_sa" with a
spinlock.

This commit implements a "_xt_coproc_owner_sa_lock" to protect the access of
"_xt_coproc_owner_sa", thus vTaskDelete() and prvDeleteTCB() can now delete
tasks pinned to the other core so long as that task is not currently running.

Note: This fix was copied from the Xtensa port of Amazon SMP FreeRTOS
2022-12-23 15:29:17 +08:00