Understanding the Basics of RTOS with Digi-Key

Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? | Digi-Key Electronics

Estimated read time: 1:20

    Learn to use AI like a Pro

    Get the latest AI workflows to boost your productivity and business performance, delivered weekly by expert consultants. Enjoy step-by-step guides, weekly Q&A sessions, and full access to our AI workflow archive.

    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo
    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo

    Summary

    In this introductory video by Digi-Key Electronics, we explore what a Real-Time Operating System (RTOS) is and how it differs from general-purpose operating systems. The discussion covers essential concepts such as tasks, threads, prioritization, memory management, and inter-task communication. Emphasis is placed on how RTOS can be beneficial for projects requiring strict timing deadlines like medical devices and engine controllers. The video also delves into the practicality of using RTOS in various projects, including those with microcontrollers like the ESP32. Furthermore, the benefits of FreeRTOS, a popular open-source RTOS, are highlighted, especially for IoT devices.

      Highlights

      • Discover the importance of Real-Time Operating Systems for critical applications. ⌛
      • Learn how RTOS ensures meeting timing deadlines for vital tasks through deterministic scheduling. 📅
      • FreeRTOS provides a platform for dividing processes into manageable tasks, especially useful in team projects. 🤝
      • Using RTOS can be a game-changer for working with wireless stacks on IoT devices. 📶
      • Understand how RTOS handles concurrent task processing on multi-core processors or single-core microcontrollers. 💡

      Key Takeaways

      • RTOS is crucial for applications requiring strict timing deadlines, unlike general-purpose OS. ⏱️
      • Tasks in RTOS can run concurrently, making it ideal for complex projects. 🤖
      • FreeRTOS is an open-source RTOS that's popular and easy to experiment with for IoT projects. 🌐
      • Using an RTOS like FreeRTOS on powerful microcontrollers like the ESP32 can enhance task management. 🖥️
      • RTOS can split CPU time among tasks, offering more efficient processing for large-scale projects. 🚀

      Overview

      In the first part of this series, Digi-Key Electronics introduces the concept of Real-Time Operating Systems (RTOS). Unlike ordinary operating systems, RTOS can ensure that tasks meet timing deadlines, which is crucial for applications like engine controllers where delays are unacceptable. By exploring tasks, threads, prioritization, memory management, and communication, the video sets a foundation for understanding how RTOS functions.

        The video emphasizes the strengths of RTOS, specifically FreeRTOS, in handling multiple tasks simultaneously on microcontrollers like the ESP32. With many tasks to manage, including user inputs, data storage, and hardware control, an RTOS allocates CPU time efficiently. It highlights FreeRTOS's popularity and practicality in IoT applications due to its open-source nature and ease of use.

          Throughout the video, viewers are encouraged to appreciate the power of RTOS in improving the performance of their projects. Although not every project demands an RTOS, it offers significant advantages when managing concurrent tasks and meeting precise timing requirements. The video concludes by discussing future content, including practical implementations of FreeRTOS concepts on devices like the ESP32.

            Chapters

            • 00:00 - 00:30: Introduction to Real-Time Operating Systems (RTOS) A real-time operating system (RTOS) is similar to other operating systems but with key differences. This chapter will discuss these differences, focusing on the use of FreeRTOS. It will cover topics such as tasks, threads, prioritization, memory management, and inter-task communication. The introduction sets the stage for understanding how RTOS operates uniquely compared to general-purpose operating systems.
            • 00:30 - 01:00: What is an Operating System? The chapter titled 'What is an Operating System?' explains the role of an operating system as a microcontroller that manages essential functions in computing devices. It is responsible for scheduling background tasks and user applications, allowing multiple processes to run simultaneously. The operating system ensures that time is efficiently allocated to each process, creating an illusion of concurrent operations across various applications on devices.
            • 01:00 - 01:30: General-Purpose vs Real-Time Operating Systems General-purpose operating systems, such as Windows, Mac OS, and Linux, manage virtual resources like files and folders, allowing applications and processes to access them as needed. They also handle device drivers, enabling the system to read from external disks, respond to inputs, and render graphics. Additionally, iOS and Android are considered general-purpose operating systems.
            • 01:30 - 02:00: Features of RTOS General-purpose operating systems prioritize human interaction, allowing for some occasional missed timing deadlines or lags in responsiveness. The scheduler is often non-deterministic, leading to unpredictability in task execution and duration.
            • 02:00 - 02:30: Task Scheduling in RTOS This chapter discusses the role of Real-Time Operating Systems (RTOS) in situations requiring strict timing deadlines, such as in medical devices or engine controllers. Missing a timing deadline in such scenarios can have disastrous consequences, such as failing to fire a spark plug in an engine. The chapter explains that RTOS can ensure tasks meet their timing deadlines by providing a scheduler designed specifically for this purpose. While RTOS offers many of the same functionalities as general-purpose operating systems, its key differentiator is its ability to guarantee task timing through its specialized scheduling capabilities.
            • 02:30 - 03:00: Super Loop Architecture The chapter titled 'Super Loop Architecture' delves into the realm of high-level device drivers, often associated with microcontrollers. It covers components like Wi-Fi and Bluetooth stacks and simple LCD drivers, and mentions minimal RTOS (Real-Time Operating System) setups that offer just a scheduler. In such a scenario, developers may need to import or build their own file systems and device drivers. While RTOS is typically associated with meeting timing deadlines, it also significantly aids in managing concurrent tasks.
            • 03:00 - 03:30: Real-Time Constraints and Interrupts The chapter discusses programming for microcontrollers, such as Arduino, focusing on real-time constraints and interrupts. It describes a typical program structure, where the program begins with initial setup functions, and thereafter executes tasks in a round-robin manner within an infinite loop. These tasks may include reading from sensors, performing calculations based on sensor data, and displaying results on an LED display. This simple programming architecture emphasizes the need to manage real-time tasks efficiently.
            • 03:30 - 04:00: When to Use RTOS The chapter discusses the concept of a 'super loop' in microcontroller programming. It highlights the ease of implementation and minimal overhead of using a super loop, which is particularly effective for managing a small number of tasks. The text argues that for many simple microcontroller projects, super loops are preferable because they conserve CPU cycles, use less memory, and are easier to debug compared to a real-time operating system (RTOS). The possibility of using interrupts to modify the flow within the super loop is also acknowledged.
            • 04:00 - 04:30: Choosing RTOS for Projects In the chapter titled 'Choosing RTOS for Projects', the discussion focuses on choosing between Real-Time Operating Systems (RTOS) and Interrupt Service Routines (ISR) based on task timing requirements. If strict timing for one or two tasks is crucial, and the deadlines are less than a millisecond, the author suggests that using ISRs might be more appropriate for precise timing control. For timing intervals of a few hundred nanoseconds, reliance on interrupts is also recommended.
            • 04:30 - 05:00: Conclusion and Next Steps In the final chapter titled 'Conclusion and Next Steps,' the discussion focuses on the limitations of the super loop architecture in handling tasks. A notable drawback is the inability to execute tasks concurrently, which can lead to performance issues such as lag. This problem is evident when task timing conflicts arise, for instance, when a lengthy Task 2 impacts Task 3, which handles display updates. The chapter also touches upon the challenges of polling for user inputs, suggesting scenarios where a faster processor or customized hardware like an FPGA may be necessary to enhance processing capabilities and efficiency.

            Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? | Digi-Key Electronics Transcription

            • 00:00 - 00:30 a real-time operating system or rtos is very much like any other operating system with a few important differences over the next few videos i'd like to talk about those differences and how to get started using free rtos we'll go over tasks threads prioritization memory management and inter-task communication let's get started [Music] an operating system is a piece of software that runs on a computer or
            • 00:30 - 01:00 microcontroller that accomplishes a number of important functions first it is in charge of scheduling background tasks and user applications in most operating systems dozens of background processes are executing at the same time and you probably have several applications open on your phone or computer right now the operating system figures out how to give slices of time to each of these processes so that everything appears to be happening concurrently second it manages a number
            • 01:00 - 01:30 of virtual resources like files libraries and folders allowing applications and processes to access them when needed third they can manage or provide device drivers for your system these drivers allow the system to read and write from an external disk respond to keyboard and mouse input or draw graphics on your monitor you're probably familiar with general purpose operating systems like windows mac os and linux ios and android also fall into
            • 01:30 - 02:00 this category most general purpose operating systems are designed with human interaction as the most important feature so the scheduler is designed to prioritize such tasks that may mean some timing deadlines can be missed or pushed back and a little lag in responsiveness especially if it's not really noticed by a human is acceptable additionally the scheduler is often non-deterministic which means we can't know exactly which task will execute when and for how long
            • 02:00 - 02:30 if you're making something that requires an os and strict timing deadlines like a medical device or engine controller missing a deadline to say fire a spark plug would be catastrophic this is where a real-time operating system or rtos can save the day most r tosses offer many of the same functions as general purpose operating systems but they are designed so that the scheduler can guarantee meeting timing deadlines on the tasks while some r-tosses might provide
            • 02:30 - 03:00 high-level device drivers you'll usually see things intended for microcontrollers like wi-fi and bluetooth stacks or simple lcd drivers you can also find bare bones r tosses that provide just a scheduler with these you'll need to import or write your own file systems and device drivers note that while most r tosses provide methods for meeting timing deadlines that's not the only reason to use an rtos in your project the ability to run multiple tasks concurrently can be a lifesaver as we'll
            • 03:00 - 03:30 see in a moment if you've written programs for microcontrollers including arduino you're probably familiar with this kind of structure when your program starts it performs some setup functions and then it executes your tasks in a round robin fashion inside a while forever loop these tasks might read from sensors perform some calculations based on those readings and then say display something on a gorgeous led display this type of simple programming architecture
            • 03:30 - 04:00 is known as a super loop it's incredibly easy to implement has very little overhead and is great when you only need to accomplish a handful of tasks on your microcontroller in fact there's nothing wrong with the super loop for the vast majority of simple microcontroller projects you're usually better off with this type of program flow as it saves on cpu cycles and memory and it's much easier to debug than using an rtos you might even have created a couple of interrupts to break the flow of
            • 04:00 - 04:30 execution to handle an external event like a button push or perform some action at specific timed intervals if you need to meet strict timing deadlines for one or two tasks you might be better off using just interrupt service routines to accomplish those tasks with precise timing in my experience if you need to meet a timing deadline of less than about one millisecond your best bet is an interrupt anyway if you're trying to do something with an interval of less than a few hundred nanoseconds you
            • 04:30 - 05:00 either need an incredibly fast processor or it's time to start looking at custom hardware like an fpga now the unfortunate thing about this super loop architecture is that you cannot execute tasks concurrently if task 2 starts taking a long time and task 3 is your update display task you'll start to experience some lag similarly if you're polling for user input like from a serial terminal or reading a sensor you
            • 05:00 - 05:30 might miss data if other tasks take too long to fix that we can use the concept of running multiple tasks at the same time on a multi-core processor this is actually physically possible however since many microcontrollers only have one core the cpu time needs to be split up among the tasks we can also give higher priority to some tasks so that they happen sooner or take more cpu time for example if we prioritize the user input task users will likely experience
            • 05:30 - 06:00 less lag but it might mean background tasks take longer to execute we'll talk more about time slicing and prioritization in a future video note the terminology used here a task is any piece of work we want to get done in code a thread is a unit of cpu utilization with its own program counter and set of memory a process is an instance of a computer program that's being executed usually a process will
            • 06:00 - 06:30 have one or more threads used to accomplish tasks threads within a process will often share resources like heap memory and can pass resources to each other you'll often find that an rtos is capable of handling only one process but a general purpose os can run many processes note that in free rtos the term task is used to mean something closer to a thread and you'll often see these terms used interchangeably because of this i will use the term task when
            • 06:30 - 07:00 referring to units of cpu utilization so that it makes sense within the free rtos ecosystem interrupts still work within an rtos so long as they have a higher priority than any of the tasks they will stop code execution for all tasks run your interrupt service routine and return execution to where it left off you can have more than one interrupt but we won't get into handling nested interrupts which can get nasty if you're writing code for a simple 8 or 16-bit
            • 07:00 - 07:30 microcontroller with 2 kilobytes of ram you're probably best sticking with the super loop approach and using the inexpensive controller to do only a handful of tasks while you can get a simple scheduler to run on such a device the memory and cpu overhead of switching tasks would not leave you with many resources left for your actual program people have ported free rtos to the arduino uno it's definitely a good way to tinker around with it but i don't know how ultimately useful it is as you move into more and more powerful
            • 07:30 - 08:00 microcontrollers it becomes much more viable to run in rtos as you've got clock cycles and memory to spare for things like a scheduler while you can still run a bare metal super loop on something like an esp32 i usually find that the whole reason i bought something with that much computing power is to run several concurrent tasks which brings me to the ultimate question of why would you want an rtos there are a number of reasons but the best one that comes to mind is for when you need to do several
            • 08:00 - 08:30 things concurrently an esp32 is capable of handling user input reading and writing to an sd card controlling hardware and crunching numbers all at the same time the big one for something like this is the wireless stack these libraries require large amounts of ram and processing power they also need to respond to events from the network in a short amount of time which means using an rtos can be a massive help in this case it can help you divide up these different features into individual tasks
            • 08:30 - 09:00 an rtos can be great if you're part of a team working on a larger project you can divide up the tasks among the team members knowing that each one will run concurrently there will be some overhead and debugging to make sure everything works together though over the next few videos i'll go over important rtos concepts like prioritization and resource management we'll practice these concepts by implementing small demo projects in free rtos on the esp32 the reason i chose freertos for this series is because it's currently the most
            • 09:00 - 09:30 popular real-time operating system for iot devices as shown by this 2018 survey from the eclipse foundation while linux still reigns supreme for most of these devices it and windows are general purpose operating systems with the exception of rt linux you can see that the bare metal super loop architecture is still quite popular and an acceptable solution to many problems free rtos is also free and open source making it easy for you to try out note that as of 2017
            • 09:30 - 10:00 amazon has taken over maintenance of the freertos project i also recommend keeping an eye on the zephyr project as it's a relative newcomer to the field backed by the linux foundation the esp32 is a powerful iot microcontroller that's packed with features also you can find inexpensive esp32 development boards any of them should work for this series as long as they have an associated arduino package i know some of you will balk at the idea of using arduino for our coding
            • 10:00 - 10:30 but hear me out most embedded programmers and electronics tinkerers will have some experience with arduino and if not it's easy to learn because of that it creates a level playing field for anyone wanting to try out rtos concepts i don't need to teach a vendor tool or chip specific libraries on top of trying to teach free rtos because the esp32 runs a modified version of free rtos out of the box there is hardly any setup involved in creating tasks in arduino almost every code example you
            • 10:30 - 11:00 see including task management semaphores mutexes and so on can easily be ported to your own build system i'll try to point out where the esp rtos differs from vanilla free rtos an rtos may not be the right answer to every firmware problem you run across but sometimes it is the right tool for the job especially when you need to do things like run concurrent tasks and meet timing deadlines at the end of most of these videos i'll issue you a challenge and i encourage
            • 11:00 - 11:30 you to try it out on your own esp32 or whatever device you're running free rtos on i'll then post a link to my solution so that you can see how your solution compares in the next video i'll show you how to get started with free rtos and create your own task to blink an led [Music]
            • 11:30 - 12:00 you