re real ti time operating systems r rtos
play

Re Real-Ti Time Operating Systems (R (RTOS) 01204322 Embedded - PowerPoint PPT Presentation

Re Real-Ti Time Operating Systems (R (RTOS) 01204322 Embedded System Chaipo Chaiporn J n Jaik aikae aeo Department of De f Computer Engineering Kasetsart Unive versity Revised 2020-02-16 Materials partially taken from Lecture Slides


  1. Re Real-Ti Time Operating Systems (R (RTOS) 01204322 Embedded System Chaipo Chaiporn J n Jaik aikae aeo Department of De f Computer Engineering Kasetsart Unive versity Revised 2020-02-16 Materials partially taken from Lecture Slides by Prof. King

  2. Ou Outline • Embedded operating systems • Real-time operating systems (RTOS) • RTOS characteristics • RTOS implementations • Hands-on activity with Mbed OS 2

  3. Op Operating g Systems • The collection of software that manages a system’s hardware resources User ◦ File system, a GUI, and other components • Often times, a kernel is the crucial part Application of such a collection • Characteristics Operating System ◦ Resource management ◦ Interface between application and hardware Hardware ◦ Library of functions for the application 3

  4. Embedded O Embedded Oper perating ing S Systems ems • The OS and application logic are combined into a single unit • Characteristics: User ◦ Resource management Operating System + ◦ Primary internal resources Application ◦ Less overhead ◦ Code of the OS and the Hardware application mostly reside in ROM 4

  5. De Desktop op vs Embedded OS OS Desktop OS Embedded OS Applications are compiled Application is compiled and separately from the OS linked together with the OS User User Operating System + Application Application Application Application Operating System Hardware Hardware 5

  6. Ch Characteri ristics of of Embedded OS OS • Embedded OS needs to be configurable: ◦ No single OS fit all needs à install only those needed ◦ e.g., conditional compilation using #if and #ifdef • Device drivers often not integrated into kernel ◦ Embedded systems often application-specific à specific devices à move devices out of OS to application tasks Embedded OS Standard OS Application Application Middleware Middleware Middleware Middleware Middleware Device driver Device driver Kernel kernel Device driver Device driver Kernel Hardware Hardware 6

  7. Ch Characteri ristics of of Embedded OS OS • Protection is often optional ◦ Embedded systems are typically designed for a single purpose, untested programs rarely loaded, and thus software is considered reliable ◦ Privileged I/O instructions not necessary and tasks can do their own I/O • Real-time capability ◦ Many embedded systems are real-time (RT) systems ◦ Hence, the OS used in these systems must be real-time operating systems (RTOSs) 7

  8. Wh What t is a Real-Ti Time System? • Real-time systems: Those systems in which the correctness of the system depends not only on the logical result of the computation, but also on the time at which the results are produced J. Stankovic, “Misconceptions about Real-Time Computing,” IEEE Computer , 21(10), October 1988. 8

  9. Job Job Scheduling g in RTOS OS General-Purpose OS Real-Time OS https://www.digikey.com/en/maker/projects/getting-started-with-stm32-introduction-to-freertos/ad275395687e4d85935351e16ec575b1 9

  10. Re Real-Ti Time Ch Characteri ristics • Sensors and actuators all controlled by a processor ◦ The big difference is their timing constraints (deadlines) • Tasks can be broken into three categories ◦ Periodic tasks : time-driven ◦ An air monitoring system taking a sample every 10 seconds ◦ Aperiodic tasks : event-driven ◦ The airbag of a car having to react to an impact ◦ Background/idle tasks: non-time-critical ◦ Compress data on SD card timer event sensor event Background processing Sensor event Timer event handler handler 10

  11. Soft Soft, F , Fir irm an and H Har ard De Dead adlin lines • The instant at which a result is needed is called a deadline • If the result has utility even after the deadline has passed, the deadline is classified as soft , otherwise it is firm • If a catastrophe could result if a firm deadline is missed, the deadline is hard 11

  12. Go Goals o als of an R f an RTOS • Manage to meet real-time deadlines • Also ◦ Tasks stay out of each others’ way ◦ Normally through memory protection ◦ Device drivers already written (and tested!) for us ◦ Portable—runs on a huge variety of systems ◦ Nearly no overhead so we can use a small device! ◦ That is a small memory and CPU footprint 12

  13. Func Functiona nality o of R f RTOS K Kernel ernel • Processor management • Memory management resource management • Timer management • Task management (resume, wait, etc.) • Inter-task communication ◦ E.g., message queues • Task synchronization ◦ E.g., mutex and semaphores 13

  14. Task Scheduling Ta • Preemtive multitasking • Cooperative multitasking ◦ Running task is preempted by kernel ◦ Tasks cooperatively give control back to kernel event event Ready Blocked Ready Blocked schedule schedule wait wait preempt yield Running Running terminate terminate terminate terminate create create terminate create terminate create Inactive Inactive (job = task = thread) 14

  15. Ty Typical RTOS Memory Allocation end Stack (for main app and IRQs) Free memory Heap for RTOS Queue Stack of Task A Task B Task A Task Control Block Heap (for main app) (TCB) start Data memory 15

  16. ARM ARM CMSIS Ar Arch chitect cture • CMSIS – C ortex M icrocontroller S oftware I nterface S tandard https://developer.arm.com/tools-and-software/embedded/cmsis 16

  17. Som Some R RTOS O S Option ions f for or C Cor ortex-M • RTOS kernels ◦ FreeRTOS (now under stewardship of Amazon) ◦ CMSIS-RTOS RTX by Keil • APIs ◦ Native FreeRTOS ◦ ARM’s CMSIS-RTOS v1/v2 ◦ ARM Mbed RTOS API 17

  18. Fr FreeR eeRTOS • Designed to be small and simple ◦ Mainly focuses on task management • Ported to 40+ MCU architectures ◦ E.g., ARM Cortex-M, Tensilica Xtensa, PIC, AVR • Free and open source ◦ Distributed under the MIT license • Supports both cooperative and preemptive task scheduling • Bundled with STM32CubeIDE 18

  19. Fr FreeR eeRTOS in in S STM32CubeIDE • STM32CubeIDE supports CMSIS-RTOS v2 API on top of FreeRTOS 19

  20. ARM ARM Mb Mbed OS OS • Designed specifically for ARM microcontrollers • Large collection of hardware abstraction APIs ◦ Similar to Arduino • Mbed OS 5 comes with CMSIS-RTOS RTX • Free and open source ◦ Distributed under the Apache 2.0 license • Collaborative online environment and community ◦ Online IDE ◦ Code repositories 20

  21. Mb Mbed Development Environments • Cloud-based IDE ◦ Online ARM C/C++ Compiler ◦ Code is easily shared with other developers • Mbed studio / Mbed CLI ◦ Offline development ◦ Built-in ARM C/C++ Compiler • Other development environments ◦ Eclipse ◦ Visual Studio Code ◦ System Workbench for STM32 21

  22. Mbed OS Architecture Mb 22

  23. Th Thread Scheduling in in Mb Mbed OS OS • Low-latency preemtive scheduler https://os.mbed.com/docs/mbed-os/v5.15/apis/rtos.html 23

  24. Su Suppor ortin ing R g Real al-Ti Time Operations • CMSIS-RTOS RTX (RTOS used by Mbed) utilizes SysTick, SVC, and PendSV interrupts to implement a low-latency preemptive scheduler configured to the lowest priority https://www.keil.com/pack/doc/CMSIS/RTOS2/html/theory_of_operation.html 24

  25. Ha Hands nds-on on Activi vity: Ge Getting St ing Start arted w d wit ith h Mb Mbed ed OS OS

  26. Ci Circuit and Wiri ring • Connect a switch to pin D3 and GND ◦ D3 is connected to STM32L432KC’s pin PB0 26

  27. Mb Mbed On Online IDE DE • Launch a browser and go to https://ide.mbed.com • Login or sign up as a new user • Click “Compiler” to launch the IDE 27

  28. Register a Platform Re • Click “No device selected” box on the top right corner • Click “Add Board” button 28

  29. Ad Add NUCLEO-L4 L432KC B Boar ard • In the search box, type NUCLEO-L432KC and click Search ◦ NUCLEO-L432KC should appear as the first result • Click on the board and click “Add to your Mbed Compiler” 29

  30. Se Sele lect Pla Platfor orm f for or C Com ompile iler • Back to the IDE page, click “No device selected” again • Select NUCLEO-L432KC and click “Select Platform” button 30

  31. Creating First Proje Cr ject • Create an empty program, named rtos-demo 31

  32. Impo Import Mb Mbed-OS OS Library • Right-click the project name and add Mbed-OS URL ◦ https://github.com/ARMmbed/mbed-os 32

  33. Add Program File Ad • Right-click the project name and add main.cpp to the project 33

  34. Fi First T Task sk: He Heart art B Beat at • Flash LED shortly every second #include "mbed.h" void task_heartbeat () { DigitalOut led3(PB_3); while (1) { led3 = 1; wait(0.1); led3 = 0; wait(0.9); } } int main () { printf("Program started...\n"); task_heartbeat(); } 34

  35. Co Compiling and Down wnloading • Click the Compile button ◦ If there is no error, the browser will start downloading firmware binary from the IDE ◦ Notes: first compilation will take a long time 35

  36. Fi Firm rmware U e Upl pload • Plug in the board • Drag the downloaded firmware and drop into the drive/folder representing the board (i.e., NODE_L432KC) ◦ The firmware should start automatically ◦ If not, you may need to press the reset button or unplug/replug the board • Observe the on-board LED 36

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend