Your SlideShare is downloading. ×
Rtos
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Rtos

1,027
views

Published on

Published in: Technology, Business

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,027
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
78
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Real-Time OS (RTOS) Copyright © 2012 Embedded Systems Committee
  • 2. Agenda • • • • • • Basic Definitions Introduction to RTOS Scheduling Algorithms Reentrancy Shared Resources RTOS APIs Copyright © 2012 Embedded Systems Committee
  • 3. Agenda • • • • • • Basic Definitions Introduction to RTOS Scheduling Algorithms Reentrancy Shared Resources RTOS APIs Copyright © 2012 Embedded Systems Committee
  • 4. Basic Definitions • What are the Real-Time systems? – “Those systems in which the correctness of system depends not only on the logical result of the computation, but also on the time at which the results are produced” Copyright © 2012 Embedded Systems Committee
  • 5. Basic Definitions • Specifications of a Real-Time system include both: – Logical: Produces correct outputs. – Temporal: Produces outputs at the right time. Copyright © 2012 Embedded Systems Committee
  • 6. Basic Definitions • Types of Real-Time requirements are: – Hard: Failure to meet constraint is fatal. – Soft: Late completion degrades software quality. Copyright © 2012 Embedded Systems Committee
  • 7. Basic Definitions • Misconceptions: – “Real-Time computing is equivalent to fast computing” – Truth is:“Real-Time computing is equivalent to predictable computing” Copyright © 2012 Embedded Systems Committee
  • 8. Basic Definitions • Misconceptions: – “Real-Time programming assembly coding” – Truth is: “It is better to automate (as much as possible) Real-Time system design, instead of relying on a clever hand-crafted code” Copyright © 2012 Embedded Systems Committee
  • 9. Basic Definitions • Misconceptions: – “Real-Time means performance engineering” – Truth is: “In Real-Time computing, timeliness is always more important than performance. Copyright © 2012 Embedded Systems Committee
  • 10. Basic Definitions • Misconceptions: – RTOS introduce considerable amount of overhead on CPU – Truth is: An RTOS typically only require between 1% to 4% of a CPU time. Copyright © 2012 Embedded Systems Committee
  • 11. Basic Definitions Real-Time Embedded Systems Embedded Systems Real-Time Systems Copyright © 2012 Embedded Systems Committee
  • 12. Agenda • • • • • • Basic Definitions Introduction to RTOS Scheduling Algorithms Reentrancy Shared Resources RTOS APIs Copyright © 2012 Embedded Systems Committee
  • 13. Introduction to RTOS Copyright © 2012 Embedded Systems Committee
  • 14. Introduction to RTOS • Basic Services provided by OS: – – – – – Task Management. Intertask Communication & synchronization. Timers. Device I/O Supervision. Dynamic Memory Allocation. Copyright © 2012 Embedded Systems Committee
  • 15. Introduction to RTOS • What are tasks? - A task─ an independent process. - No task can call another task. unlike the normal C function which can call another function. void task(void) { /*Some Initialization Code*/ for(;;) { /*Task Code*/ } } Copyright © 2012 Embedded Systems Committee
  • 16. Introduction to RTOS • What is multitasking? Copyright © 2012 Embedded Systems Committee
  • 17. Introduction to RTOS • What is context? PC ROM RAM SP Copyright © 2012 Embedded Systems Committee CPU Registers
  • 18. Introduction to RTOS • What is context? ROM Task 1CPU Registers RAM Task2 Stack Task1 Control Block Task1 Stack Task2 Control Block Copyright © 2012 Embedded Systems Committee Task 2CPU Registers
  • 19. Introduction to RTOS • What is context? Copyright © 2012 Embedded Systems Committee
  • 20. Introduction to RTOS • Task Life Cycle: Copyright © 2012 Embedded Systems Committee
  • 21. Introduction to RTOS • What is the difference between RTOS & GPOS? Task Switching Time GPOS RTOS Number of Tasks That Can Be Scheduled Copyright © 2012 Embedded Systems Committee
  • 22. Introduction to RTOS • Characteristics of an RTOS? – – – – – Reliability Predictability Performance Compactness Scalability Copyright © 2012 Embedded Systems Committee
  • 23. Agenda • • • • • • Basic Definitions Introduction to RTOS Scheduling Algorithms Reentrancy Shared Resources RTOS APIs Copyright © 2012 Embedded Systems Committee
  • 24. Scheduling Algorithms • What is a scheduler? – It is part of the kernel which decides which task can run when. – There are many algorithms for scheduling & they can be categorized into two main categories. Copyright © 2012 Embedded Systems Committee
  • 25. Scheduling Algorithms • Non-preemptive (Suppose it is priority based): Task1 Time Copyright © 2012 Embedded Systems Committee
  • 26. Scheduling Algorithms • Non-preemptive: Task1 Time ISR Copyright © 2012 Embedded Systems Committee
  • 27. Scheduling Algorithms • Non-preemptive: Task1 Time ISR Task2 is Ready Copyright © 2012 Embedded Systems Committee
  • 28. Scheduling Algorithms • Non-preemptive: Task1 Time ISR Task2 is Ready Task1 Copyright © 2012 Embedded Systems Committee
  • 29. Scheduling Algorithms • Non-preemptive: Task1 Time ISR Task2 is Ready Task1 Although task2 is higher in priority than task1, task 1 gets to finish before task2 gets to start. Copyright © 2012 Embedded Systems Committee Task2
  • 30. Scheduling Algorithms • Preemptive (Suppose it is priority based): Task1 Time Copyright © 2012 Embedded Systems Committee
  • 31. Scheduling Algorithms • Preemptive: Task1 Time ISR Copyright © 2012 Embedded Systems Committee
  • 32. Scheduling Algorithms • Preemptive: Task1 Time ISR Copyright © 2012 Embedded Systems Committee
  • 33. Scheduling Algorithms • Preemptive: Task1 Time ISR Task2 Copyright © 2012 Embedded Systems Committee
  • 34. Scheduling Algorithms • Preemptive: Task1 Time ISR Task2 Task1 Copyright © 2012 Embedded Systems Committee
  • 35. Agenda • • • • • • Basic Definitions Introduction to RTOS Scheduling Algorithms Reentrancy Shared Resources RTOS APIs Copyright © 2012 Embedded Systems Committee
  • 36. Reentrancy C char x; void foo1(void) { x++; } Task1 /*Some Code*/ foo1(); /*Some Code*/ Assembly char x; foo1: mov R1,x; add R1,1; mov x,R1; Task2 /*Some Code*/ foo1(); /*Some Code*/ Copyright © 2012 Embedded Systems Committee
  • 37. Reentrancy x=1 Task 1: R1=0 Task 2: R1=0 Copyright © 2012 Embedded Systems Committee
  • 38. Reentrancy x=1 Task 1: R1=1 Task 2: R1=0 mov R1,x; Copyright © 2012 Embedded Systems Committee
  • 39. Reentrancy x=1 Task 1: R1=2 Task 2: R1=0 mov R1,x; add R1,1; Copyright © 2012 Embedded Systems Committee
  • 40. Reentrancy x=2 Task 1: R1=2 Task 2: R1=0 mov R1,x; add R1,1; mov x,R1; Copyright © 2012 Embedded Systems Committee
  • 41. Reentrancy x=2 Task 1: R1=2 Task 2: R1=0 mov R1,x; add R1,1; mov x,R1; Context Switching Task2 is ready Copyright © 2012 Embedded Systems Committee
  • 42. Reentrancy x=2 Task 1: R1=2 Task 2: R1=2 mov R1,x; add R1,1; mov x,R1; mov R1,x; Copyright © 2012 Embedded Systems Committee
  • 43. Reentrancy x=2 Task 1: R1=2 Task 2: R1=3 mov R1,x; add R1,1; mov x,R1; mov R1,x; add R1,1; Copyright © 2012 Embedded Systems Committee
  • 44. Reentrancy x=3 Task 1: R1=2 Task 2: R1=3 mov R1,x; add R1,1; mov x,R1; mov R1,x; add R1,1; mov x,R1; Copyright © 2012 Embedded Systems Committee
  • 45. Reentrancy (Another Scenario) x=1 Task 1: R1=0 Task 2: R1=0 Copyright © 2012 Embedded Systems Committee
  • 46. Reentrancy x=1 Task 1: R1=1 Task 2: R1=1 mov R1,x; Copyright © 2012 Embedded Systems Committee
  • 47. Reentrancy x=1 Task 1: R1=1 Task 2: R1=1 mov R1,x; Context Switching Task2 is ready Copyright © 2012 Embedded Systems Committee
  • 48. Reentrancy x=1 Task 1: R1=1 Task 2: R1=1 mov R1,x; mov R1,x; Copyright © 2012 Embedded Systems Committee
  • 49. Reentrancy x=1 Task 1: R1=1 Task 2: R1=2 mov R1,x; mov R1,x; add R1,1; Copyright © 2012 Embedded Systems Committee
  • 50. Reentrancy x=2 Task 1: R1=1 Task 2: R1=2 mov R1,x; mov R1,x; add R1,1; mov x,R1 Copyright © 2012 Embedded Systems Committee
  • 51. Reentrancy x=2 Task 1: R1=1 Task 2: R1=2 mov R1,x; mov R1,x; add R1,1; mov x,R1; Context Switching Task2 is back to waiting Copyright © 2012 Embedded Systems Committee
  • 52. Reentrancy x=2 Task 1: R1=2 Task 2: R1=2 mov R1,x; add R1,1; mov R1,x; add R1,1; mov x,R1; Copyright © 2012 Embedded Systems Committee
  • 53. Reentrancy x=2 Task 1: R1=2 Task 2: R1=2 mov R1,x; add R1,1; mov x,R1; mov R1,x; add R1,1; mov x,R1; Copyright © 2012 Embedded Systems Committee
  • 54. Reentrancy • When to doubt your function reentrancy? – When your function accesses a global variable while this variable is accessed in: • ISR • Another task • Hardware module. Copyright © 2012 Embedded Systems Committee
  • 55. Reentrancy • How to make a non-reentrant function reentrant? – Either using critical section or any task synchronization services provided by the OS. Copyright © 2012 Embedded Systems Committee
  • 56. Reentrancy • Critical Section: – Context Switching always happens after an interrupt. – If I disabled interrupts during the time I don’t want the schedule nor any ISR interrupts the running task then this part of code is reentrant. char x; void foo1(void) { DI; x++; EI; } Copyright © 2012 Embedded Systems Committee
  • 57. Agenda • • • • • • Basic Definitions Introduction to RTOS Scheduling Algorithms Reentrancy Shared Resources RTOS APIs Copyright © 2012 Embedded Systems Committee
  • 58. Shared Resources • Tasks always race each other for resources. • Resources could be many thing like HW modules, memory & even CPU time. • We have to control the tasks resources access to avoid data corruption or basically any undesirable behavior. • Semaphores are just one methods of controlling resources access. Copyright © 2012 Embedded Systems Committee
  • 59. Shared Resources • Semaphore vs. mutex Copyright © 2012 Embedded Systems Committee
  • 60. Intertask Communication • global variable RAM Task 1 write X X Task 2 read X Copyright © 2012 Embedded Systems Committee
  • 61. Intertask Communication • Mailboxes - Any task can send a message to a mailbox and any task can receive a message from a mailbox Copyright © 2012 Embedded Systems Committee
  • 62. Intertask Communication • Message Queues Copyright © 2012 Embedded Systems Committee
  • 63. Agenda • • • • • • Basic Definitions Introduction to RTOS Scheduling Algorithms Reentrancy Shared Resources RTOS APIs Copyright © 2012 Embedded Systems Committee
  • 64. RTOS APIs “uCOS-III” • • • • • • • • • OSTaskCreate (Task ptr, arg, prio, stack size) OSSemCreate (Sem ptr, counter) OSSemPost (Sem ptr) OSSemPend (Sem ptr,Timeout) OSTmrCreate (Tmr ptr, period, callback) OSTmrStart, OSTmrStop (Tmr ptr) OSMemCreate (mem ptr, block size, n blocks) OSMemPut (mem ptr, blk ptr) OSMemGet (mem ptr) Copyright © 2012 Embedded Systems Committee
  • 65. References • uC/OS-II, Jean Labrosse • Operating Systems: Design & Implementation, Andrew Tanenbaum • Embedded.com Copyright © 2012 Embedded Systems Committee
  • 66. Website: www.escommittee.net Contact Us: info@escommittee.net FB: Embedded Systems Committee Copyright © 2012 Embedded Systems Committee