0% found this document useful (0 votes)
32 views

Program Flow in Embedded Applications

The document discusses different methods for program flow in embedded applications, including polling, interrupt-driven, and using a real-time operating system (RTOS). Polling involves waiting for data and processing it in a loop, but can be inefficient. Interrupt-driven uses interrupts to wake the processor when service is needed. An RTOS allows executing multiple tasks concurrently through time slicing and context switching between tasks. The best method depends on the complexity of the application.

Uploaded by

Nihal Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Program Flow in Embedded Applications

The document discusses different methods for program flow in embedded applications, including polling, interrupt-driven, and using a real-time operating system (RTOS). Polling involves waiting for data and processing it in a loop, but can be inefficient. Interrupt-driven uses interrupts to wake the processor when service is needed. An RTOS allows executing multiple tasks concurrently through time slicing and context switching between tasks. The best method depends on the complexity of the application.

Uploaded by

Nihal Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Program Flow in Embedded Applications

Source: The Definitive Guide to


ARM Cortex-M3 and Cortex-M4 Processors, 3rd Edition
by Joseph Yiu
Dr Usman Zabit
CHAPTER 2: Introduction to
Embedded Software Development
2.5 Software flow
• There are many ways to construct program flow for an embedded
application.
• Here we will cover some of the basic concepts.
2.5.1 Polling
• For very simple applications, the processor can wait until there is data
ready for processing, process it, and then wait again.
• This is very easy to setup and works fine for simple tasks.
• Figure 2.7 shows a simple polling program flow chart.
2.5.1 Polling
• In most cases, a microcontroller will have to serve multiple interfaces and
therefore be required to support multiple processes.
• The polling program flow method can be expanded to support multiple
processes easily (Figure 2.8).
• This arrangement is sometimes called a “super-loop”.
• “Super-loop”
2.5.1 Polling (Disadvantages)
• The polling method works well for simple applications, but it has several
disadvantages.
• For example, when the application gets more complex, the polling loop
design might get very difficult to maintain.
• Also, it is difficult to define priorities between different services using polling
and you might end up with poor responsiveness, where a peripheral
requesting service might need to wait a long time while the processor is
handling less important tasks.
• Another main disadvantage of the polling method is that it is not energy
efficient.
• Lots of energy is wasted during the polling when service is not required.
2.5.2 Interrupt driven
• To solve this problem, almost all microcontrollers have some sort of sleep
mode support to reduce power, in which the peripheral can wake up the
processor when it requires a service (Figure 2.9).
• This is commonly known as an interrupt-driven application.
2.5.2 Interrupt driven Design with Polling
• In some cases, the processing of data from peripheral services can be
partitioned into two parts:
• the first part needs to be done quickly, and
• the second part can be carried out a little bit later.
• In such situations we can use a mixture of interrupt-driven and polling
methods to construct the program.
• When a peripheral requires service, it triggers an interrupt request as in an
interrupt-driven application.
• Once the first part of the interrupt service is carried out, it updates some
software variables so that the second part of the service can be executed
in the polling-based application code (Figure 2.10).
• FIGURE 2.10: Application with both
polling method and interrupt-driven
arrangement

• Using this arrangement, we can


reduce the duration of high-priority
interrupt handlers so that lower
priority interrupt services can get
served quicker.
• At the same time, the processor can
still enter sleep mode to save power
when no servicing is needed.
2.5.3 Multi-tasking systems
• When the applications get more complex, a polling and interrupt-driven
program structure might not be able to handle the processing requirements.
• E.g, some tasks that can take a long time to execute might need to be
processed concurrently (note that concurrent execution is not parallel execution).
• This can be done by dividing the processor’s time into a number of time slots
and allocating the time slots to these tasks.
• While it is technically possible to create such an arrangement by manually
partitioning the tasks and building a simple scheduler to handle this, it is often
impractical to do this in real projects as it is time consuming and can make the
program much harder to maintain and debug.
• In these applications, a Real-Time Operating System (RTOS) can be used to
handle the task scheduling (Figure 2.11).
Concurrent Execution: illusion of running multiple tasks

Image from
Embedded Systems Architecture, A Comprehensive Guide for Engineers and Programmers
by Tammy Noergaard
2.5.3 Multi-tasking systems (contd.)
• An RTOS allows multiple processes to be executed concurrently, by dividing
the processor’s time into time slots and allocating the time slots to the
processes that require services.
• A timer is needed to handle the timekeeping for the RTOS, and
• at the end of each time slot, the timer generates a timer interrupt, which
triggers the task scheduler, and
• It decides if context switching should be carried out.
• (click here for a detailed example of context switching)
• If yes, the current executing process is suspended and the processor
executes another process.
• Besides task scheduling, RTOSs also have many other features such as
semaphores, queues, message passing, etc.
• There are many RTOSs developed for the Cortex-M processors, and many
of them are completely free of charge (e.g. FreeRTOS).

You might also like