2024-03-20 09:21 AM
Hi Folks
I am porting some code from an old project where i was using FreeRTOS 10 to AzureRTOS.
At the end of an ISR callback i used to call portYIELD_FROM_ISR(yield) to give back to the OS(Scheduler) the control on the next valid tick.
Is there any equivalent for AzureRTOS ? I tried to search but i found nothing relevant.
Regards
Davide
Solved! Go to Solution.
2024-04-26 02:59 AM
Hello @Davide Dalfra
Azure RTOS ThreadX, which is the real-time operating system for AzureRTOS, has a similar concept but uses different APIs. In ThreadX, the equivalent functionality is achieved using a combination of tx_interrupt_control and tx_thread_resume or tx_event_flags_set depending on the situation.
Here's how you can signal that a thread should be resumed (or an event flag should be set) from an ISR in ThreadX:
VOID my_isr(VOID)
{
// ... ISR code ...
// Resume the thread.
tx_thread_resume(&my_thread);
// ... ISR code ...
}
VOID my_isr(VOID)
{
// ... ISR code ...
// Set the event flag.
tx_event_flags_set(&my_event_flags_group, FLAGS_TO_SET, TX_OR);
// ... ISR code ...
}
Yielding from an ISR: If an ISR makes a higher-priority thread ready to run, ThreadX's scheduler will automatically perform a context switch to that thread when the ISR completes. There is no need to explicitly yield from the ISR as you would in FreeRTOS.
However, if you need to force a context switch from an ISR in a more controlled manner, you can use tx_thread_system_resume or tx_thread_system_suspend to manage thread readiness and the scheduler will take care of the context switch.
Remember that in ThreadX, the system is designed to be preemptive, and the scheduler will automatically yield to the highest-priority ready thread after an ISR completes, assuming that the ISR code has made a higher-priority thread ready to run.
2024-04-26 02:59 AM
Hello @Davide Dalfra
Azure RTOS ThreadX, which is the real-time operating system for AzureRTOS, has a similar concept but uses different APIs. In ThreadX, the equivalent functionality is achieved using a combination of tx_interrupt_control and tx_thread_resume or tx_event_flags_set depending on the situation.
Here's how you can signal that a thread should be resumed (or an event flag should be set) from an ISR in ThreadX:
VOID my_isr(VOID)
{
// ... ISR code ...
// Resume the thread.
tx_thread_resume(&my_thread);
// ... ISR code ...
}
VOID my_isr(VOID)
{
// ... ISR code ...
// Set the event flag.
tx_event_flags_set(&my_event_flags_group, FLAGS_TO_SET, TX_OR);
// ... ISR code ...
}
Yielding from an ISR: If an ISR makes a higher-priority thread ready to run, ThreadX's scheduler will automatically perform a context switch to that thread when the ISR completes. There is no need to explicitly yield from the ISR as you would in FreeRTOS.
However, if you need to force a context switch from an ISR in a more controlled manner, you can use tx_thread_system_resume or tx_thread_system_suspend to manage thread readiness and the scheduler will take care of the context switch.
Remember that in ThreadX, the system is designed to be preemptive, and the scheduler will automatically yield to the highest-priority ready thread after an ISR completes, assuming that the ISR code has made a higher-priority thread ready to run.