Trying to understand context switching at low level

Hi,

I’m working with a RiscV CPU with FreeRTOS (esp32c3). I’m trying to understand what is happening in context switching.

Code: esp idf code on github
components/freertos/FreeRTOS-Kernel/portable/riscv/port.c

I found the followings
Call hierarchy for ‘create the task’
xTaskCreatePinnedToCore
prvInitialiseNewTask
pxPortInitialiseStack
uxInitialiseStackFrame (vPortTaskWrapper): this is the main_task. Im trying to
figure out how the main_task code will be called

Call hierarchy for ‘scheduler call’
vTaskStartScheduler
xPortStartScheduler
vPortYield
esp_crosscore_int_send_yield: this will send the crosscore IT

ISR will be : crosscore IT
uxInitialiseStackFrame adds a new stack frame to the stack top

But who will POP and how will the code executed? ISR has own handling routine.

In our port, xPortStartScheduler calls xPortStartFirstTask which pops this context.

Your question seems to about Espressif’s port and I am not familiar with that. Reading your description, I’d assume that the ISR handler pops this context before returning. I’d suggest to reach out to Espressif for a definitive answer.