FreeRTOS / FreeRTOS-Kernel-Partner-Supported-Ports

Other
9 stars 14 forks source link

[BUG] issue in implementation of vPortYieldFromISR() on AVR_AVRDx port #9

Closed francesco-gritti closed 9 months ago

francesco-gritti commented 1 year ago

as discussed on the FreeRTOS forum at https://forums.freertos.org/t/avr32-db-port-vportyieldfromisr-issue/17878 the current implementation of vPortYieldFromISR() is not usable on the AVR_AVRDx port.

considering the following interrupt handler>

ISR (i2c_VECT) {

    // do some checks and send data if needed

    if (all data have been sent) {
        xSemaphoreGiveFromISR(i2cSemaphore, NULL);
        vPortYieldFromISR ();
    }
}

with the current implementation, which is

portSAVE_CONTEXT();
vTaskSwitchContext();
portRESTORE_CONTEXT();
asm volatile ( "reti" );

this would bring to a context save on the task stack of the interrupt context, which is undesired

The current fix for this issue is to declare interrupt handlers in the following way

__attribute__((naked)) ISR (i2c_VECT) {
    portSAVE_CONTEXT();

     // do some checks and send data if needed

    if (all data have been sent) {
        xSemaphoreGiveFromISR(i2cSemaphore, NULL);
        vTaskSwitchContext();
        portRESTORE_CONTEXT();
        asm volatile ( "reti" );
    }

    portRESTORE_CONTEXT();
    asm volatile ("reti");
}
aggarg commented 1 year ago

@alexmchp Do you have any suggestion here? I think we should delete the following lines as these are not useful -

aggarg commented 10 months ago

@alexmhcp, do you plan to look at it?

AniruddhaKanhere commented 9 months ago

@aggarg can we make the above changes and fix the implementation? Or do we need a definitive answer from @alexmchp?

Skptak commented 9 months ago

Marking this issue as closed as #13 removed the incorrect function. Please feel free to raise a new issue or pull request to add the desired functionality to this port Thanks!