Commit graph

3649 commits

Author SHA1 Message Date
Sudeep Mohanty
66c04c0bde
Merge e850728909 into fed39c5ea7 2025-12-03 10:28:26 +00:00
Sudeep Mohanty
e850728909 feat(freertos-smp): Add support for queue direct transfer buffer in task TCB
This commit adds support for queue direct transfer buffer being owned by
the task's TCB. This inherently solves some design issues with the
buffer being owned by the queue's object. On the flip side, this adds
memory cost to the task's TCB.
2025-12-03 15:58:07 +05:30
Saiiijchan
fed39c5ea7
Refine comments related to taskYIELD in queue.h (#1333)
Replace taskYIELD with portYIELD_FROM_ISR

Signed-off-by: wangfei_chen <wangfei_chen@realsil.com.cn>
Co-authored-by: wangfei_chen <wangfei_chen@realsil.com.cn>
2025-11-12 13:51:08 +05:30
Saiiijchan
439af33c52
riscv: refine vector context layout on stack (#1329)
Vector general register layout:

Before:
+--------------+  <-- High Address
|      v7      |
+--------------+
|      v6      |
+--------------+
|      ...     |
+--------------+
|      v0      |
+--------------+  <-- v0 - v7
|      v15     |
+--------------+
|      v14     |
+--------------+
|      ...     |
+--------------+
|      v8      |
+--------------+  <-- v8 - v15
|      ...     |
+--------------+
|      v24     |
+--------------+  <-- Low address

After:
+--------------+  <-- High Address
|      v31     |
+--------------+
|      v30     |
+--------------+
|      ...     |
+--------------+
|      v1      |
+--------------+
|      v0      |
+--------------+ <-- Low Address

Signed-off-by: wangfei_chen <wangfei_chen@realsil.com.cn>
Co-authored-by: wangfei_chen <wangfei_chen@realsil.com.cn>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
2025-11-04 08:44:16 -08:00
Gaurav-Aggarwal-AWS
c8d31ddcff
Use saved mstatus for FPU/VPU state determination (#1330)
According to the RISC-V Privileged Architecture Specification (20211203),
writing Initial or Clean to the FS field of mstatus may result in the FS
value getting set to Dirty in some implementations. This means we cannot
rely on reading back the same FS value after writing to mstatus.

Previously, the context restore code would:
1. Write an FS value to mstatus
2. Read mstatus again at a later point
3. Use the read FS value to determine FPU status

This change updates the context restore code to use the mstatus value
from the saved context instead of re-reading mstatus after writing to
it. This required chaning the location of the mstatus slot in the
context.

Fixes: https://github.com/FreeRTOS/FreeRTOS-Kernel/issues/1327

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
2025-11-03 12:32:08 +05:30
Sudeep Mohanty
53a44909aa feat(freertos-smp): Add support for queue direct transfer
This commit adds support for direct transfer for queue operations. A ew
config option configQUEUE_DIRECT_TRANSFER is introduced to enable this
option. With this feature, we enable directly copying data to a waiting
task's buffer and avoid copying data to the queue buffer. This helps in
avoiding priority inversions where a lower priority task can steal
a data from a higher priority task blocked on the queue. This also
reduces a copy operation and helps with the queue performance.
2025-10-30 16:44:48 +08:00
Sheng Tai
8b63f94d8d
Fix: Propagate PICO_SDK_VERSION_* to parent scope in RP2040 port (#1326) 2025-10-29 14:35:00 -07:00
Kody Stribrny
13074875c2 Prefer xTaskDelayUntil in config template
xTaskDelayUntil is more featured and should
be preferred by new users. This change was inspired by
https://forums.freertos.org/t/include-xtaskdelayuntil-vs-include-vtaskdelayuntil/24656.
2025-10-27 20:27:19 -07:00
Sudeep Mohanty
4ee717950d fix(freertos-smp): Stream Buffer task lists must be manipulated in critical sections
Stream buffer task lists (xTaskWaitingToSend and xTaskWaitingToReceive)
are updated without critical sections. These objects are shared objects
and can be updated from an ISR context as well. Hence, these lists must
always be updated in critical sections.
2025-10-14 12:46:56 +02:00
Sudeep Mohanty
a1cc3bda48 fix(freertos-smp): Update critical nesting count in prvLock/UnlockQueue
prvLockQueue() and prvUnlockQueue() helper functions now only take the
ISR locks because they are always called with the task lock already
taken. However, these functions must also increment and decrement the
critical nesting count as both locks get taken eventually. This commit
fixes it.
2025-10-14 12:46:38 +02:00
Sudeep Mohanty
1b91c544f9 fix(freertos-smp): Always take ISR locks in vTaskEnter/ExitCriticalFromISR 2025-10-13 10:34:02 +02:00
Sudeep Mohanty
5098b1ae26 feat(freertos-smp): Optimize prvLockQueue() and prvUnlockQueue() 2025-10-13 10:34:02 +02:00
Sudeep Mohanty
1585b157d5 feat(freertos-smp): Update queueUNLOCK() to receive yield status 2025-10-13 10:34:02 +02:00
Sudeep Mohanty
49b89b2f25 feat(freertos-smp): Use light weight locks for preemption disable/enable 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
f46aaa7a2b feat(freertos-smp): Reintroduce Light Weight Critical Sections 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
fbd37a219e feat(freertos-smp): Added xTaskRemoveFromEventListFromISR() 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
592177f42e remove(freertos-smp): Remove support for light-weight critical sections 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
9000208ecf feat(freertos-smp): Remove xTaskUnlockCanYield() and make it inline 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
829d8ba51a fix(freertos-smp): Remove scheduler suspension from event_groups.c
This commit removes the need for suspending the scheduler when calling
some event_groups.c APIs as the non-deterministic operations are
happening with the event group being locked and the preemption being
disabled from the current task.
2025-10-13 10:34:01 +02:00
Sudeep Mohanty
c5667e34d0 feat(freertos-smp): Update event groups unlock to use taskDATA_GROUP_UNLOCK() 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
1b14543e7d feat(freertos-smp): Create private function for task preemption enable 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
35025858cf fix(freertos-smp): Miscellaneous fixes for granular locks 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
e3d92dd5fd fix(freertos-smp): Fix yielding decisions based on preemption state of task 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
60bca5e8b2 fix(freertos-smp): Stop unconditional yielding in vTaskPreemptionEnable 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
4330d9073a fix(freertos-smp): Fixed Lightweight Critical Sections for deferred state change 2025-10-13 10:34:01 +02:00
Sudeep Mohanty
274fbb5beb feat(freertos-smp): Light Weight Preemption Disable Locks 2025-10-13 10:34:01 +02:00
Darian Leung
97ffa4c11f feat(freertos/smp): Add Granular Locking V4 proposal documents
Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Darian Leung
f2c560dad7 change(freertos/smp): Update timers.c locking
Updated timers.c to use granular locking

- Added xTaskSpinlock and xISRSpinlock
- Replaced critical section macros with data group critical section macros
such as taskENTER/EXIT_CRITICAL() with tmrENTER/EXIT_CRITICAL().
- Added vTimerEnterCritical() and vTimerExitCritical() to map to the
  data group critical section macros.

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Darian Leung
3e23312f35 change(freertos/smp): Update stream_buffer.c locking
Updated stream_buffer.c to use granular locking

- Added xTaskSpinlock and xISRSpinlock
- Replaced critical section macros with data group critical section macros
such as taskENTER/EXIT_CRITICAL/_FROM_ISR() with sbENTER/EXIT_CRITICAL_FROM_ISR().
- Added vStreambuffersEnterCritical/FromISR() and
  vStreambuffersExitCritical/FromISR() to map to the data group critical
section macros.
- Added prvLockStreamBufferForTasks() and prvUnlockStreamBufferForTasks() to suspend the stream
buffer when executing non-deterministic code.

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Darian Leung
1db6c7c7f1 change(freertos/smp): Update event_groups.c locking
Updated event_groups.c to use granular locking

- Added xTaskSpinlock and xISRSpinlock
- Replaced critical section macros with data group critical section macros
such as taskENTER/EXIT_CRITICAL/_FROM_ISR() with event_groupsENTER/EXIT_CRITICAL/_FROM_ISR().
- Added vEventGroupsEnterCritical/FromISR() and
  vEventGroupsExitCriti/FromISR() functions that map to the data group
critical section macros.
- Added prvLockEventGroupForTasks() and prvUnlockEventGroupForTasks() to suspend the event
group when executing non-deterministic code.
- xEventGroupSetBits() and vEventGroupDelete() accesses the kernel data group
directly. Thus, added vTaskSuspendAll()/xTaskResumeAll() to these fucntions.

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Darian Leung
9212425270 change(freertos/smp): Update queue.c locking
Updated queue.c to use granular locking

- Added xTaskSpinlock and xISRSpinlock
- Replaced  critical section macros with data group critical section macros
such as taskENTER/EXIT_CRITICAL/_FROM_ISR() with queueENTER/EXIT_CRITICAL_FROM_ISR().
- Added vQueueEnterCritical/FromISR() and vQueueExitCritical/FromISR()
  which map to the data group critical section macros.
- Added prvLockQueueForTasks() and prvUnlockQueueForTasks() as the granular locking equivalents
to prvLockQueue() and prvUnlockQueue() respectively

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Darian Leung
c08a323b9f change(freertos/smp): Update tasks.c locking
Updated critical section macros with granular locks.

Some tasks.c API relied on their callers to enter critical sections. This
assumption no longer works under granular locking. Critical sections added to
the following functions:

- `vTaskInternalSetTimeOutState()`
- `xTaskIncrementTick()`
- `vTaskSwitchContext()`
- `xTaskRemoveFromEventList()`
- `vTaskInternalSetTimeOutState()`
- `eTaskConfirmSleepModeStatus()`
- `xTaskPriorityDisinherit()`
- `pvTaskIncrementMutexHeldCount()`

Added missing suspensions to the following functions:

- `vTaskPlaceOnEventList()`
- `vTaskPlaceOnUnorderedEventList()`
- `vTaskPlaceOnEventListRestricted()`

Fixed the locking in vTaskSwitchContext()

vTaskSwitchContext() must aquire both kernel locks, viz., task lock and
ISR lock. This is because, vTaskSwitchContext() can be called from
either task context or ISR context. Also, vTaskSwitchContext() must not
alter the interrupt state prematurely.

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Darian Leung
6850d88529 feat(granular_locks): Add granular locking functions
- Updated prvCheckForRunStateChange() for granular locks
- Updated vTaskSuspendAll() and xTaskResumeAll()
    - Now holds the xTaskSpinlock during kernel suspension
    - Increments/decrements xPreemptionDisable. Only yields when 0, thus allowing
    for nested suspensions across different data groups

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Darian Leung
2c86281b40 feat(freertos/smp): Add granular locking port macros checks
Adds the required checks for granular locking port macros.

Port Config:

- portUSING_GRANULAR_LOCKS to enable granular locks
- portCRITICAL_NESTING_IN_TCB should be disabled

Granular Locking Port Macros:

- Spinlocks
        - portSPINLOCK_TYPE
        - portINIT_SPINLOCK( pxSpinlock )
        - portINIT_SPINLOCK_STATIC
- Locking
        - portGET_SPINLOCK()
        - portRELEASE_SPINLOCK()

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Darian Leung
0926574228 feat(freertos/smp): Allow vTaskPreemptionEnable() to be nested
Changed xPreemptionDisable to be a count rather than a pdTRUE/pdFALSE. This
allows nested calls to vTaskPreemptionEnable(), where a yield only occurs when
xPreemptionDisable is 0.

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Darian Leung
2129e55344 refactor(freertos/smp): Move critical sections inside xTaskPriorityInherit()
xTaskPriorityInherit() is called inside a critical section from queue.c. This
commit moves the critical section into xTaskPriorityInherit().

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2025-10-13 10:34:01 +02:00
Pascal Reich
e5987bbdb2
Remove Unused Code and Preprocessor Directives in RP2040 Port (#1324)
* Remove redundant code and preprocessor directives

* Remove more redundant code and directives
2025-10-08 18:06:45 +05:30
Ths.quiniou
a1f6e1f64f
fix[RL78 Port] incorrect register image for pvParameters in FAR model (#1316) (#1317)
In the RL78 FAR data model, pxPortInitialiseStack() did not initialize
the register image for the task parameter (pvParameters) correctly.
A:DE registers were saved with dummy values instead of the actual pointer.

Effect: on first context restore the function prologue read a corrupted
parameter. NEAR builds were not affected.

This patch aligns the FAR path with the calling convention and compiler
version:
 - IAR V2: pass pvParameters via registers → DE = low 16 bits, A = high 8
 - IAR V1 (fallback): keep legacy stack write
Also keeps the original stack-frame layout and updates the comment to
reflect that pointer sizes depend on __DATA_MODEL__.

Result: tasks in FAR receive the correct parameter at entry; NEAR remains
unchanged.

Co-authored-by: Thomas Quiniou <tquiniou@fdi-access.com>
2025-10-06 18:37:11 +05:30
Ahmed Ismail
a8ae21c88e
armv8-r: Add Arm Cortex-R82 non-MPU port (#1289)
The goal of this commit is to add the GCC/ARMClang non-MPU
port variant for ARM Cortex-R82 processor which is
ARMv8-R AArch64 based.
The work done is inspired by the GCC ARM_AARCH64 FreeRTOS port.

This port has the following features:
* Uses single security state (non TrustZone).
* Supports SMP (Symmetric multi-processing).
* Doesn't support Hypervisor (EL2).
* Doesn't support neither PMSA (MPU) nor VMSA (MMU).

Signed-off-by: Ahmed Ismail <Ahmed.Ismail@arm.com>
2025-09-29 20:10:22 +05:30
mathiasgredal
3d44975181
RP2040: Fix use of deprecated volatile semantics for C++20 (#1318) (#1319)
Co-authored-by: Mathias Gredal <matg@universal-robots.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
2025-09-17 12:44:14 +05:30
razrbro
692c4b070f
Fix: avoid set but unused variable warning in pxPortInitialiseStack (#1320) 2025-09-17 11:19:04 +05:30
Ahmed Ismail
44ae6cf61a
cortex-M ports: Clarify hardware-saved exception frame size variable (#1314)
* cortex-M ports: Clarify hardware-saved exception frame size variable

- Rename ulStackFrameSize to ulHardwareSavedExceptionFrameSize to
reflect the hardware-saved exception frame (8 or 26 words based
on FPU/lazy stacking).
- Add comments explaining standard vs extended frames.
- Apply across Cortex-M ports.
- No functional change, improves readability.

Signed-off-by: Ahmed Ismail <Ahmed.Ismail@arm.com>
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>

* kernel-checker-script: Modify Arm copyright header regex

Arm's copyright header regex is modified with the following:

* Accept both single year copyright headers (e.g., "2024")
and year range copyright headers (e.g., "2024-2025").

* Accept both single-line copyright header and also
multi-line header.

* Add the escape backslash to accept only literal dot
not any character.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Signed-off-by: Ahmed Ismail <Ahmed.Ismail@arm.com>

---------

Signed-off-by: Ahmed Ismail <Ahmed.Ismail@arm.com>
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
2025-09-09 14:25:42 +08:00
Kim Lindberg Schwaner
ccabdec2f8
Fix risk of Win32 timer setup call getting ignored (#1311)
If a user configures the configASSERT macro to expand to nothing,
a call to the Win32 API SetWaitableTimer() doesn't get compiled.

This can happen if, for example, configASSERT(x) set defined as
assert(x) (from assert.h) which expands to nothing when NDEBUG is
set (common for "release" builds).
2025-08-15 11:09:28 -07:00
DuYicheng
386c1bca66
Change the macro from portMAX_DELAY to SIZE_MAX in order to initialize size_t-type variable correctly (#1310) 2025-08-15 12:37:23 +05:30
Ahmed Ismail
43947413b9
event-groups: Fix multiple definitions (#1307)
This commit does the following:
* Remove xEventGroupClearBitsFromISR and
xEventGroupSetBitsFromISR functions direct mapping
to xTimerPendFunctionCallFromISR in case the trace
facility is feature not set. This should match the
current implementation in which the application calling
xEventGroupClearBitsFromISR
without defining the trace macros
(i.e. traceENTER_xEventGroupClearBitsFromISR is
a blank function in this case) will end up calling
xTimerPendFunctionCallFromISR function directly.
This enhances the readability of the code by not
guarding the xEventGroup<Set/Clear>BitsFromISR
functions' declaration and definition based on
the trace facility macro (i.e. configUSE_TRACE_FACILITY).

* Refactor the guarding macros for MPU_xEventGroupClearBitsFromISR
and MPU_xEventGroupSetBitsFromISR functions to match the
change above.

The current implementation leads to redefinition warnings
as `event_groups.h`redefines xEventGroupClearBitsFromISR
and xEventGroupSetBitsFromISR based on
`configUSE_TRACE_FACILITY' after they have been defined based
on configUSE_MPU_WRAPPERS_V1 in `mpu_wrappers.h`. The
implemented changes should resolve these warnings.

Signed-off-by: Ahmed Ismail <Ahmed.Ismail@arm.com>
2025-08-14 10:40:59 -07:00
Dennis Lambe Jr.
c91ee8d724
Fix CMake build for GCC_ARM_CRx_MPU (#1308) (#1309)
Add GCC_ARM_CRX_MPU to the set of FREERTOS_PORT patterns that trigger
adding mpu_wrappers.c and mpu_wrappers_v2.c to freertos_kernel_port
target_sources.
2025-08-14 10:35:53 +05:30
creiter64
e9440d4079
Move windows headers to port.c (#1302)
* [MSVC-MingW] Move windows headers to port.c

This prevents the inclusion of windows.h. into all header files using
FreeRTOS.h and thus defining several macros conflicting with common
definitions.

* [MSVC-MingW] Include correct header for compiler intrinsics

---------

Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
2025-08-05 19:11:54 +08:00
Dennis Lambe Jr.
c5bec0e4b2
LLVM assembler compatibility for ARM_CRx_MPU (#1303)
GNU as makes unrecognized sections loadable and writable by default, but
LLVM's assembler requires specifying flags explicitly. Without them, the
linker generates "has non-ABS relocation" errors when trying to link the
resulting object files.
2025-08-05 16:02:03 +05:30
Gaurav-Aggarwal-AWS
2da35debfd
Add missing cast to BaseType_t (#1301)
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
2025-07-31 10:32:23 +08:00
Gaurav-Aggarwal-AWS
32e581636f
Delete thread key on process exit (#1297)
Previously, the shared thread key was deleted in xPortStartScheduler
after scheduler was ended. This created a race condition where
prvThreadKeyDestructor (responsible for freeing thread-specific heap
memory) would not be called if xPortStartScheduler deleted the key
before the last task deletion, as destructors are not invoked after key
deletion (see https://github.com/walac/glibc/blob/master/nptl/pthread_create.c#L145-L150).

Move thread key deletion to process exit to ensure all thread-specific
memory is properly freed.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
2025-07-24 11:07:27 +05:30