On Exit of vSoftwareInterruptHandler() p. 97

joe0x7f wrote on Saturday, December 29, 2012:

I am very curious to know what would happen if a line like vPrintString(“xyz\n”); was added right after the portEND_SWITCHING_ISR( xHigherPriorityTaskWoken ); line in the vSoftwareInterruptHandler() function on page 97 of the “Using The FreeRTOS Real Time Kernel, NXP LPC17xx Edition” 2nd edition book?

Would “xyz” be printed out if xHigherPriorityTaskWoken is pdTRUE?
Would “xyz” be printed out if xHigherPriorityTaskWoken is pdFALSE?

Thanks!!!

joe0x7f wrote on Saturday, December 29, 2012:

I found the answer. It prints out “xyz” in either case. The ISR ( vSoftwareInterruptHandler() ) is not interrupted or cut short by the
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken ); line.

rtel wrote on Saturday, December 29, 2012:

First, vPrintString() must not be called from an interrupt if it is using a critical section, locking the scheduler, or using any non ISR safe FreeRTOS function.  As a general rule console IO is too slow for interrupts whatever the method.

I think your question relates more to the sequence of execution than printing in any case.  On the Cortex-M3 based LPC17xx all context switches are performed in the PendSV interrupt, and the PendSV interrupt is always the lowest priority interrupt so will not itself interrupt the vSoftwareInterruptHandler() function.

If xHigherPriorityTaskIsWoken is pdTRUE then portEND_SWITCHING_ISR() will pend the PendSV interrupt, then any code that appears after the call to portEND_SWITCHING_ISR() macro will execute before the vSoftwareInterruptHandler() function exits.  When the function exits the interrupt is complete and the PendSV interrupt handler can and will execute to perform the context switch before any task level code executes.

If xHigherPriorityTaskIsWoken is pdFALSE then portEND_SWITCHING_ISR() will not pend the PendSV interrupt, then any code that appears after the call to portEND_SWITCHING_ISR() macro will execute before the vSoftwareInterruptHandler() function exits.

This is true for the Cortex-M port, but not all the FreeRTOS ports.

Regards.