Real Time Operating System
Download
Report
Transcript Real Time Operating System
04EI
Real Time Operating System
• Tasks
Widely independent operations, which should be executed as
simultaneously as possible
• Operating System
takes over the management and the coordination of the tasks.
Task 1
Task 2
Task 3
• Real Time
- reaction in time of incoming events as fast as possible,
- in best compliance with time requirements
12.08.2013
D
µ
Embedded Systems
page 1
04EI
Real Time Operating System
• Task Management
Creation of task
Terminatiation of tasks
Scheduler: examines, wheter waiting conditions are fulfilled
Dispatcher: decides which one of the waiting tasks will be executed
• Resource Management
Memory -management
I/O-management
File management
Protocole-Stacks, etc.
• Reliability
Error-detection, -handling
• Security
Access controle
Object Protection
12.08.2013
D
µ
Embedded Systems
Page 2
04EI
Task Concept
• Task
- Functional and structural unit of the operating system
- Program with appropriate closed environment
• Task Control Block
– Information about state and priority of the task
– CPU and System Context
• Task States
– ready, running (busy), waiting, suspended
12.08.2013
D
µ
Embedded Systems
page 3
04EI
Task states
suspended
ready
suspended:
the task doesn‘t take part on
what is goining on
ready:
the task is ready and waiting for the
assignment of the processor
running
running (busy):
the code of the task is executed
waiting
waiting:
the task is waiting for the
occurrence of an event
12.08.2013
D
µ
Embedded Systems
page 4
04EI
Task Management
tasks are
created
suspended
processor is
available
ready
ready
ready
ready
ready
ready
Dispatcher
running(busy)
RTX166tiny:
at the beginning task 0 is
excecuted, it activates all
needed further tasks
Waiting
condition
is fulffilled
waiting
12.08.2013
D
µ
Embedded Systems
page 5
04EI
Task Management
• Scheduler
provides the availability of the tasks (regarding to the priority of the task):
– Time slicing: Maximum time, which is available for the task
Round-Robin-Scheduling - preemptive scheduling
– Cooperative Scheduling: Task is waiting for the occurrance of an event
– non preemptive Scheduling
• Dispatcher
performs the correct switching to the provided task
• Synchronisation
Interprocess communication via:
– Signals
– Semaphore
– Mailboxes
– Messages
12.08.2013
D
µ
Embedded Systems
page 6
04EI
Task Interaction - Synchronisation
Asynchronous via
Mailbox
Sender
Task
12.08.2013
D
Receiver
Task
µ
Synchronous via
Message Passing
Sender
Task
Embedded Systems
Receiver
Task
page 7
04EI
Real Time Operating System RTX166
RTX166 Full
•
•
•
•
Task Switching
– Round Robin
– Cooperative
•
signal passing
message passing with mailbox system
semaphores
256 Tasks max.
128 task priorities
"os_wait" function
12.08.2013
D
µ
interrupt
timeout
signal from task or interrupt
message from task or interrupt
semaphore
Embedded Systems
page 8
04EI
Real Time Operating System RTX166
RTX166 Tiny
•
Task Switching
•
signal passing
– Round Robin
– Cooperative
•
32 tasks max.
"os_wait" function
12.08.2013
D
µ
interval
timeout
signal from task or interrupt
Embedded Systems
page 9
04EI
Real Time Operating System RTX166
Single Task Program
int counter;
void main (void) {
counter = 0;
while (1) { /* repeat forever */
counter++; /* increment counter */
}
}
12.08.2013
D
µ
Embedded Systems
page 10
04EI
Real Time Operating System RTX166
Round-Robin Task Switching
#include <rtx166t.h>
…
int counter0, counter1; /* global variables */
os_create_task (1); /* Mark task 1 as "ready" */
os_create_task (2); /* Mark task 2 as "ready" */
void job0 (void) _task_ 0 {
while (1) {
/* Endless loop */
counter0++;
/* Increment counter 0 */
}
}
void job1 (void) _task_ 1 {
while (1) {
/* Endless loop */
counter1++; /* Increment counter 1 */
}
}
Rtx_1
19.3.2010
D
µ
Embedded Systems
Seite 11
04EI
Real Time Operating System RTX166
Cooperative Task Switching: Wait for Timeout
#include <rtx166t.h>
…
int counter0, counter1;
void job0 (void) _task_ 0 {
os_create_task (1);
while (1) {
counter0++;
os_wait (K_TMO, 3, 0);
}
}
void job1 (void) _task_ 1 {
while (1) {
counter1++;
os_wait (K_TMO, 5, 0);
}
}
12.08.2013
D
µ
/* Increment counter 0 */
/* Wait 3 timer ticks */
/* Increment counter 1 */
/* Wait 5 timer ticks */
Embedded Systems
Rtx_1
page 12
04EI
Real Time Operating System RTX166
Cooperative Task Switching: Wait for Signal
#include <rtx166t.h>
…
int counter0, counter1;
os_create_task (1);
os_create_task (2);
void job0 (void) _task_ 0 {
while (1) {
os_wait (K_TMO, 1000, 0);/* Wait 1000 timer ticks (1s)*/
if (++counter0 == 0) {
/* On counter 0 overflow*/
os_send_signal(1); /* Send signal to task 1*/
}
}
}
void job1 (void) _task_ 1 {
while (1) {
os_wait (K_SIG, 0, 0);/* Wait for signal; no timeout */
counter1++;
/* Increment counter 1 */
}
Rtx_1
}
12.08.2013
D
µ
Embedded Systems
page 13