Embedded Talks Ep3 : Context Switching

Embedded Talks Ep3 : Context Switching

Context switching refers to the process where cpu halt program currently executing save its context and switch to another process,Thing that can trigger context switch can be

  • Hardware Interrupts

Context switching allows effectively run multiple tasks on a CPU allowing them to share, This effective switching gives illusion of running multiple process simultaneously at same time.

Process of Context Switch:

The process by which context is switched mainly involve saving information of general purpose register of currently executing program i.e Program counter, stack pointer etc and then restore when other job is finished, although seems simple it has to be optimized well for real time application

RTOS involvement:

Most embedded systems use a Real-Time Operating System (RTOS) to manage task scheduling and context switching, providing features like priority-based scheduling and cooperative multitasking.

Example scenario:

  • A microcontroller is running a task to read sensor data while simultaneously monitoring a timer interrupt.
  • When the timer interrupt occurs, the CPU saves the current state of the sensor reading task (its context).
  • The CPU then executes the timer interrupt service routine, which might involve updating a system timer or triggering another task based on the time elapsed.
  • After the interrupt service routine completes, the CPU restores the context of the sensor reading task and continues where it left off.

To view or add a comment, sign in

More articles by Isfandyar Qureshi

  • Embedded Talks Ep6 : Address Space, Vector Table ,Stack and Heap

    Address Space (Memory Space) The address space (also called memory space) is the entire range of memory that can be…

  • Embedded Talks Ep 5: Multi-Level Feedback Queue Scheduling

    In Episode 4, we discussed various scheduling algorithms and their trade-offs. However, a fundamental problem with…

  • Embedded Talks Ep 4: Scheduling Algorithms

    An operating system must provide an scheduler that is tasked with job of handling multiple process/tasks Before we dive…

  • Embedded Talks Ep2 : A Process/TASK/THREAD

    Concepts an embedded engineer must know: Process: A process is simply a running program; at any instant of in time…

  • Embedded Talk Ep.1

    Concepts an embedded software engineer must know Operating System: An operating system is a piece of software that…

  • WHY IT SUCKS TO BE EMBEDDED ENGINEER!!!!

    This article is a personal experience and observation over my 6-7 years as an electronics/embedded engineer. Your…

    69 Comments
  • Sending Struct on SPI?

    Another short article for embedded developers like me who are learning We all use structures in our C / C++ programing…

    3 Comments
  • Common Issue with SPI

    Spi is very common protocol and is used very often it has its perk of multiple sensors on common bus etc Hardware used…

    1 Comment
  • MOCKING THE MYSTERY IN UNIT TESTING

    Greeting everyone are you a software engineer making apps or are you an embedded iot developer. This article is for…

  • IS YOUR SPI GITCHY ?????

    #embeddedsystems #spi #embeddedengineer Have you even face a scenario where your spi run sometimes very well and…

    8 Comments

Insights from the community

Others also viewed

Explore topics