FreeRTOS / FreeRTOS-Kernel

FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
https://www.FreeRTOS.org
MIT License
2.51k stars 1.05k forks source link

Add vPortGenerateSimulatedInterruptFromWindowsThread in MSVC port #1044

Closed chinglee-iot closed 2 months ago

chinglee-iot commented 2 months ago

Add vPortGenerateSimulatedInterruptFromWindowsThread in MSVC port

Description

In the MSVC port of FreeRTOS, native Windows threads execute concurrently with FreeRTOS tasks and simulated interrupt handlers. Calling a FreeRTOS API from within a native Windows thread can lead to race conditions due to the concurrent execution. One way to enable synchronization between native Windows threads and FreeRTOS tasks is to make use of simulated interrupts. When a native Windows thread needs to invoke a FreeRTOS API, it generates a simulated interrupt and calls the FromISR API within the interrupt service routine (ISR).

The existing vPortGenerateSimulatedInterrupt function is designed to be called from within a FreeRTOS task, and it references the current thread structure. To facilitate calling FreeRTOS APIs from native Windows threads, this pull request introduces a new API function, vPortGenerateSimulatedInterruptFromWindowsThread. This function allows native Windows threads to generate simulated interrupts and subsequently call FreeRTOS APIs through the FromISR API, ensuring proper synchronization with FreeRTOS tasks.

Existing tick timer is an example of generating simulated interrupt from native windows thread. Another example is the cellular comm interface in this commit. Comm interface can generate simulated interrupt to notify FreeRTOS task when UART RX data is received.

In this PR

Test Steps

N/A

Checklist:

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud