Real-Time Processing: How It Works
Introduction
A realtime processing systems ensure the execution time can be completed within certain interval with minimal variability. This is important because from time crtical systems such as a audio playback, if the processor does not feed the audio driver with ontime data, the user will experience sudden audio cracking and interruptions affecting user experiences, which can separate winner from low quality products.
Background:
Realtime system requires low software overhead and ensure that the execution time is deterministic. This dictates that both embedded os and the hardware microtechture needs to complie to this.
Real-time systems are often implemented on microcontrollers with RTOS (real-time operating systems). RTOSes provide a number of features that make them well-suited for real-time applications, such as:
Task scheduling: RTOSes can schedule tasks to be executed at specific times or intervals. This ensures that real-time tasks are executed on time, even if other tasks are running.
Interrupt handling: RTOSes can handle interrupts from hardware devices, such as sensors and actuators. This ensures that real-time tasks are not interrupted by unexpected events.
Resource management: RTOSes can manage the resources of the microcontroller, such as memory and processor time. This ensures that real-time tasks have the resources they need to meet their deadlines.
One can also implementing a realtime processing such as audio on a general purposed SoC by configuring the operating system task schedulers with right priority settings.
Example:
Real-Time Audio Playback on RTOS using MicroController
A real-time system is one that must guarantee that certain tasks are completed within a specific time interval. Audio playback is an example of a real-time system, as the audio data must be played back at a constant rate to avoid choppy or distorted sound.
One way to implement real-time audio playback on a microcontroller with RTOS is to use the RTOS to schedule the audio playback task to be executed at a specific interval. The RTOS can also handle interrupts from the audio device, so that the audio playback task is not interrupted by unexpected events.
Real-Time Execution on General Purpose CPUs
General purpose CPUs can be used for a variety of tasks, including real-time audio playback. However, in order to ensure that real-time data is processed within a specific time interval, the OS task scheduler must be able to distinguish realtime data from other background program activities.
This is achieved by increasing the affinity (i.e. level of importance) of the real-time execution thread. For example, the audio playback thread in the audio OS framework can be set to the highest affinity, so that it is guaranteed to be executed on time.
However, it is important to note that CPUs have limited resources, so not all tasks can be given the highest affinity. If too many tasks are given high affinity, the CPU may not be able to execute all of them, which can lead to poor user experience.
Detailed Breakdown of two types of realtime systems
Microcontroller with RTOS is an audio playback system.
Real-time system: A system that must guarantee that certain tasks are completed within a specific time interval.
Microcontroller: A small computer that is used to control electronic devices.
RTOS: A real-time operating system that is designed to meet the timing requirements of real-time systems.
Audio playback system: A system that plays back audio data.
The audio playback system must ensure that the audio data is played back at a constant rate.
Constant rate: The audio data must be played back at a consistent speed, so that the sound does not become choppy or distorted.
Audio data: The digital representation of sound waves.
This is achieved by using the RTOS to schedule the audio playback task to be executed at a specific interval.
RTOS task: A task is a unit of work that is executed by the RTOS.
Scheduling: The process of determining when tasks will be executed.
Interval: The amount of time between the execution of two tasks.
The RTOS also handles interrupts from the audio device, so that the audio playback task is not interrupted by unexpected events.
Interrupt: An event that causes the CPU to stop what it is doing and execute a specific piece of code.
Audio device: A device that produces sound.
Realtime Excustion on general purpose CPU such as ARM A class SoC:
The OS task scheduler must be able to distinguish realtime data vs other background program activities.
General purpose CPU: A CPU that can be used for a variety of tasks.
ARM A class SoC: A type of SoC (system on a chip) that uses ARM A class cores.
SoC: A chip that integrates all the components of a computer system, such as the CPU, memory, and peripherals.
Task scheduler: The part of the RTOS that schedules tasks to be executed.
Realtime data: Data that must be processed within a specific time interval.
Background program activities: Tasks that are not critical and can be interrupted if necessary.
This is achieved by increasing the affinity (i.e. level of importance) of the real-time execution thread.
Affinity: The priority of a task.
Real-time execution thread: A task that is responsible for executing real-time data.
For example, setting audio playback thread in the audio OS framework to the highest.
Audio OS framework: The software that implements the audio playback system.
However, one thing to notice, that all CPU has limited resources, so one cannot set all tasks to be high affinity, or else the operating system and all its program will stall inducing poor user experience.
Limited resources: CPUs have a limited amount of processing power, memory, and other resources.
Stall: A situation where the CPU is unable to execute any tasks.
Poor user experience: A situation where the user is not satisfied with the performance of the system.
How to Design a Real-Time Processing Device
There are a few key things to consider when designing a real-time processing device:
The type of application. The timing requirements of different applications will vary. For example, an audio playback system will have different timing requirements than a control system.
The available hardware resources. The processing power, memory, and other resources of the hardware will affect the design of the real-time processing device.
The RTOS. The RTOS must be able to meet the timing requirements of the application and the available hardware resources.
Summary
Real-time audio playback is an important application that requires careful design and implementation. By using the RTOS to schedule the audio playback task and handle interrupts from the audio device, it is possible to ensure that the audio data is played back at a constant rate and meets the timing requirements of the application.
Conclusion
Real-time processing systems are used in a wide variety of applications, including audio playback, video streaming, and control systems. The design of a real-time processing system must take into account the specific requirements of the application, the available hardware resources, and the timing requirements.
Further Reading:
Real-Time Systems: https://en.wikipedia.org/wiki/Real-time_system
Real-Time Operating Systems: https://en.wikipedia.org/wiki/Real-time_operating_system
ARM Architecture: https://en.wikipedia.org/wiki/ARM_architecture