Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Definition of Context Switch in RTOS?

Posted by Ivan on March 22, 2011
Hi there,

I am new to FreeRTOS and the concepts of RTOS in general. I was wondering, in this situation:

When a RTOS is running and an interrupt arrives, which subsequently invokes a yeidlFromISR() function, does that constitute a "context switch" as per in the normal Time sharing desktop systems ?

I have been looking around for awhile but have yet to find the definitive answer on this. To me, as long as an execution context is preempted and can be restored for execution subsequently is considered a context switch. Am I mistaken in my understanding?

Thanks alot in advance, any help in understanding is appreciated :)

Cheers!

RE: Definition of Context Switch in RTOS?

Posted by MEdwards on March 22, 2011
“When a RTOS is running and an interrupt arrives, which subsequently invokes a yeidlFromISR() function, does that constitute a "context switch" as per in the normal Time sharing desktop systems ?”


Calling portYIELD_FROM_ISR() from an interrupt context switches the context of the task that was interrupted, to the task that should run when the interrupt completes. That means, the interrupt interrupts one task, but potentially returns to another. The task that was interrupted will run again, but only when it is the highest priority ready state task. So yes, that is a context switch, but the context switch does not switch the interrupt context but the task context. I don't know how that relates to your question about time sharing desktop systems though.

Does that answer your question?

RE: Definition of Context Switch in RTOS?

Posted by Ivan on March 22, 2011
Oh yes! That was a great answer. Yes, I see what you mean now and that makes so much more sense!

Thanks alot! Cheers :)

RE: Definition of Context Switch in RTOS?

Posted by Ivan on March 23, 2011
Hi,

I didn't want to start a new thread and flood the forum so I decided to continue off from here.

I am new to FreeRTOS and the concepts of RTOS in general. I am wondering, if this is what happens during the execution of the Kernel on a Renesas RSK RX62N or any other MCUs in general:

1) Kernel is running and sets the Interrupt Priority Level(IPL) to configKERNEL_INTERRUPT_PRIORITY. (Other than the times where the Kernel is accessing Kernel data and needs to disable all interrupts by setting the IPL to configMAX_SYSCALL_INTERRUPT_PRIORITY)

2) When an interrupt arrives, the MCU will check against the current IPL levels to check if the interrupt is allowed to be accepted.

3) If interrupt is accepted: Kernel is preempted and the MCU will switch to the Interrupt Stack Pointer. When the interrupt handler completes, the PC and the Processor Status Word (PSW) is popped off the interrupt stack and finally, Kernel continues executing from where it left of.

Is my understanding correct?

Thanks loads guys :) Cheers!


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS