290 likes | 876 Views
Embedded Computer - Definition. When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves data through the use of sensors and interacts with the environment through the use of actuators.
E N D
Embedded Computer - Definition • When a microcomputer is part of a larger product, it is said to be an embedded computer. • The embedded computer retrieves data through the use of sensors and interacts with the environment through the use of actuators. • The software for this embedded computer is partitioned into functional sections. Each program being referred to as a task, and the overall system is called a multitasking system.
Real-time Operating System Software Characteristics • For simplification, the software is broken into two major parts, the operating system and it’s tasks. • Operating System: The software to handle interrupts, I/O devices, and the scheduling and control of the tasks. • Tasks: The programs that carry out the required functions of the computer.
Real-time Online System Examples • Online System: When a computer uses sensors to acquire data directly from the place where the data is generated. • Examples: • Microwave Ovens • Modern Electric Kitchen Ranges • Modern Touch-tone Telephone
Operating System Structure • System Tables • Dispatcher • Interrupt Service Routines (ISR) • System Services
Operating System Structure:System Tables • System Tables: • Task-Control-Blocks(TCB): These hold information necessary to run the tasks. • Device-Control-Blocks(DCB): These hold the information necessary for the operating system to use the I/O devices. Also, each device may have an additional table or buffer to hold I/O information as the I/O device operates. • Service-Control-Blocks(SCB): These specify the parameters for a request for the operating system to perform some function. • A complete system has one TCB for each task, one DCB for each I/O device, and many SCBs.
Operating System Structure:The Dispatcher • The dispatcher is a program module that determines which task will run next after something triggers the system to switch control to a new task.
Operating System Structure:Interrupt Service Routine(ISR) • For each I/O device, there is an associated ISR that is run when that I/O device sends triggers an interrupt in the system. The ISR contains the details of the I/O devices operation. • The ISR controls the device to provide data transfer between the outside world and the inside of the operating system. • ISR’s generally run with the interrupt system disabled, therefore the ISR should contain short program code in order to execute relatively quickly.
Operating System Structure:System Services • The operating system provides services to tasks. • The system services are implemented as ISR’s. • The tasks request service by causing a software interrupt using a SWI instruction. • After the the system service ISR carries out the requested service of the task, it will then return to the requesting task.
Tasks: In Depth • Tasks used with a multitasking operating system have characteristics similar to other programs. In particular, a task must have a stack for data storage and subroutine return addresses. • Since each task is a separate program, it must be assigned a stack for its use. The operating system must provide the multiple stacks required by the multiple tasks.
Tasks • Task States • Running State • Suspended State • Ready State • Task Scheduling • Multitasking Schemes • Cooperative Multitasking • Preemptive Multitasking • Scheduling Algorithms • Round-robin Scheduling • Priority Scheduling • The Background Task • Combination Scheduling • Task Switching • Hardware Context • Software State (Running, Suspended, and Ready States)
Task States • At various times, a task can be in one of three states: • Running State: The task that is currently running, that is, executing instructions, is in the running state. While in the running state, this program has control of the computer hardware and will retain control until it gives up control or control is taken away from it through an interrupt. • Suspended State: A task that doesn’t want to run or is unable to run because it is waiting for something is in the suspended state. The task could be waiting for an event to occur outside the computer, for time to pass, or for a resource to become available. Such a task is described as being blocked. At any particular time, several tasks may be in the suspended state. • Ready State: A task in the ready state wants to run, has all the resources to run, but is not running because the operating system has chosen another task to be the running task. At any particular time, several tasks may be in the ready state.
Task Scheduling:Multitasking Schemes • A multitasking operating system runs multiple tasks concurrently by “switching” between tasks. This makes it seem like all the tasks are being run at the same time. • Cooperative Multitasking: This scheme depends on the running task relinquishing control so that other tasks can run. If it doesn’t give up control, all other tasks may be permanently blocked from running. • Preemptive Multitasking: This scheme allows the operating system to take control away from a task without a request from the task by using interrupts. This scheme is generally desirable in real-time control systems so that one task cannot prevent all others from running.
Task Scheduling:Scheduling Algorithms • When appropriate, the dispatcher uses a scheduling algorithm to choose a task to be the next running task. Here are some common algorithms: • Round-robin Scheduling:Rotate control between all tasks. The dispatcher checks one task after another until it finds a ready task to run. When it gets to the end of the list of tasks, it starts over at the beginning of the list of tasks. All tasks are treated equally. • Priority Scheduling: A priority scheduling system assigns a priority to each task and continues down the list of tasks in priority order. The first task it finds that’s in the ready state is made the running task. This approach is called a strict priority scheduling algorithm.
The Background Task: This is the task that is always ready to run. Under the circumstance that no other task is ready to be run in the system, the scheduling algorithm will always find this task in the ready to run state. This task generally provides system information for maintaining and troubleshooting the system. • Combination Scheduling: This scheduling algorithm uses a combination of the algorithms discussed above. Each priority level of a priority system often has multiple tasks that rotate in round-robin fashion. Another approach is to rotate priorities so that tasks’ priorities change over time. Using this type of scheduling can ensure that all tasks have the opportunity to run sooner or later.
Task Switching:Hardware Context • While a task is running, it controls the computer’s resources. Because tasks run with interrupts enabled, an interrupt can take control away from the task. When an interrupt occurs, the interrupt system first saved the microprocessor’s status in the stack and then sends control to an ISR by placing the interrupt vector in the program counter. The microprocessor’s status includes the information in the microprocessor’s registers, excluding the stack pointer. • Each task must have it’s own stack. Therefore to save all the information about a task at an interrupt, the stack pointer must also be saved. Although the interrupt system hardware does most of the work, the stack pointer must be saved by program code in the 68HC11.
Task Switching:Software State • Running State:A task will continue running until it is preempted by the operating system by way of an interrupt, or by executing it’s own software interrupt, SWI, instruction. At this point it will go to the ready state. This task may also request a suspension or be looking for a resource that is already in use, therefore, at this point the task will switch to the suspended state. • Suspended State: A task in the suspended state may be blocked by another task, be waiting for a resource, or may be waiting for it’s slot in time to run as a delayed task. At this point the suspended task will switch to the ready state. • Ready State:A task in the ready state wants to run. The only reason a ready task is not running is that a higher-priority task also wants to run or is running. The higher-priority task gets use of the computer before the lower-priority task.
Common Operating System Services • Schedule A Task: A task may choose to ask the operating system to schedule it to run again at a later time. The time may be specified as a delay from now, or at a specified time-of-day. • Suspend A Task: A task may choose to stop running for various reasons. It may have finished its job for now, an error may have occurred, or it may want to wait until some external event starts once again. • Start A Task: One task may want to start another task because the other task carries out a needed function not in the running task. • Transmit and Receive Through a Serial Port: Serial communication to other devices and computers is common and practical. The SCI device in the 68HC11 is typical.
Read or Set The System Clock • Communicate With Another Task: In embedded systems one task often sends data numbers to another task. This transfer is quite difficult to accomplish because of the concurrency problem. The data transfer could get broken by an interrupt in the middle of the data transfer and end up sending bogus data to the receiving task.