DACCON 7 DACCON 6 DACC ON 5 DACC

  • Slides: 35
Download presentation

DACCON. 7 DACCON. 6 DACC ON. 5 DACC ON. 4 DACC ON. 3 DACC

DACCON. 7 DACCON. 6 DACC ON. 5 DACC ON. 4 DACC ON. 3 DACC ON. 2 DACC ON. 1 DAC CON. 0 MODE RNG 1 RNG 0 CLR 1 CLR 0 SYNC *PD 1 *PD 0

一、实时操作系统概述 操作系统是一种管理计算机硬件的程序,为应用程序提供了基本的运行条件,在计 算机用户和计算机硬件之间扮演着中介的角色。 The operating system (OS) is the main program that controls how

一、实时操作系统概述 操作系统是一种管理计算机硬件的程序,为应用程序提供了基本的运行条件,在计 算机用户和计算机硬件之间扮演着中介的角色。 The operating system (OS) is the main program that controls how your computer system functions. The OS manages the computer’s hardware, including the processor, memory, and storage devices, as well as peripheral devices. It is responsible for the management, scheduling, and interaction of tasks. Your first interaction with the OS is the user interface. Four categories: Real-Time (RTOS) Single-User, Single-Task Single-User, Multitask Multiuser

WHAT THE OS DOES Provides user interface Manages the CPU Manages memory and storage

WHAT THE OS DOES Provides user interface Manages the CPU Manages memory and storage Manages hardware and peripheral devices Coordinates application software with the CPU The operating systems provides a way for the user to interact with the computer, manages the processor (CPU), manages the memory and storage, manages the computer system’s hardware and peripheral devices, and provides a consistent means for software applications to work with the CPU.

THE USER INTERFACE Enables you to interact with the computer Types of interfaces: Command-driven

THE USER INTERFACE Enables you to interact with the computer Types of interfaces: Command-driven interface Menu-driven interface Graphical user interface (GUI)

PROCESSOR MANAGEMENT Controls the timing of events the processor works on Interrupts Interrupt handler

PROCESSOR MANAGEMENT Controls the timing of events the processor works on Interrupts Interrupt handler Interrupt table Stack

MEMORY AND STORAGE MANAGEMENT The operating system allocates space in RAM for instructions and

MEMORY AND STORAGE MANAGEMENT The operating system allocates space in RAM for instructions and data

HARDWARE AND PERIPHERAL DEVICE MANAGEMENT Device drivers Programs that enable the operating system to

HARDWARE AND PERIPHERAL DEVICE MANAGEMENT Device drivers Programs that enable the operating system to communicate with peripheral devices Provided by the manufacturer of the device Plug and Play Hardware and software standard Facilitates the installation of new hardware

FILE MANAGEMENT The operating system provides an organizational structure for the computer’s contents Hierarchical

FILE MANAGEMENT The operating system provides an organizational structure for the computer’s contents Hierarchical structure of directories Drives Folders v Subfolders Files

REAL-TIME OPERATING SYSTEMS

REAL-TIME OPERATING SYSTEMS

REAL-TIME OPERATING SYSTEMS – Multiple events handled by a single processor – Events may

REAL-TIME OPERATING SYSTEMS – Multiple events handled by a single processor – Events may occur simultaneously – Processor must handle multiple, often competing events – Wide range of RTOS systems Systems with a specific purpose and a certain result Uses include: Industrial machines Robotic equipment Automobiles Video game consoles Home appliances

REAL-TIME OPERATING SYSTEMS 1、Task A task is a program running on the CPU core

REAL-TIME OPERATING SYSTEMS 1、Task A task is a program running on the CPU core of a microcontroller. A real-time operating system allows the execution of multiple tasks on a single CPU. All tasks execute as if they completely "owned" the entire CPU. Without a multitasking kernel (an RTOS), only one task can be executed by the CPU at a time. This is called a single-task system.

REAL-TIME OPERATING SYSTEMS a、Single-task systems (superloop) A superloop application is basically a program that

REAL-TIME OPERATING SYSTEMS a、Single-task systems (superloop) A superloop application is basically a program that runs in an endless loop, calling OS functions to execute the appropriate operations (task level). No real-time kernel is used, so interrupt service routines (ISRs) must be used for real-time parts of the software or critical operations (interrupt level). This type of system is typically used in small, uncomplex systems or if real-time behavior is not critical.

REAL-TIME OPERATING SYSTEMS void main (void) { int counter = 0; while (1) /*

REAL-TIME OPERATING SYSTEMS void main (void) { int counter = 0; while (1) /* repeat forever */ {check_serial_io (); /* check for serial input */ process_serial_cmds (); /* process serial input */ check_kbd_io (); /* check for keyboard input */ process_kbd_cmds (); /* process keyboard input */ adjust_ctrlr_parms (); /* adjust the controller */ counter++; /* increment counter */ } }

REAL-TIME OPERATING SYSTEMS b、COOPERATIVE MULTITASKING Cooperative multitasking expects cooperation of all tasks. Tasks can

REAL-TIME OPERATING SYSTEMS b、COOPERATIVE MULTITASKING Cooperative multitasking expects cooperation of all tasks. Tasks can only be suspended by calling a function of the operating system. If they do not, the system “hangs”, which means that other tasks have no chance of being executed by the CPU while the first task is being carried out.

REAL-TIME OPERATING SYSTEMS

REAL-TIME OPERATING SYSTEMS

REAL-TIME OPERATING SYSTEMS c、PREEMPTIVES MULTITASKING A real-time operating system needs a regular timerinterrupt to

REAL-TIME OPERATING SYSTEMS c、PREEMPTIVES MULTITASKING A real-time operating system needs a regular timerinterrupt to interrupt tasks at defined times and to perform task-switches if necessary. The highestpriority task in the READY state is therefore always executed, whether it is an interrupted task or not. If an ISR makes a higher priority task ready, a task switch will occur and the task will be executed before the interrupted task is returned to.

REAL-TIME OPERATING SYSTEMS

REAL-TIME OPERATING SYSTEMS

REAL-TIME OPERATING SYSTEMS 1、Scheduling There are different algorithms that determine which task to execute,

REAL-TIME OPERATING SYSTEMS 1、Scheduling There are different algorithms that determine which task to execute, called schedulers. All schedulers have one thing in common: they distinguish between tasks that are ready to be executed (in the READY state) and the other tasks that are suspended for any reason (delay, waiting for mailbox, waiting for semaphore, waiting for event, and so on). The scheduler selects one of the tasks in the READY state and activates it (executes the program of this task). The task which is currently executing is referred to as the active task.

REAL-TIME OPERATING SYSTEMS a、ROUND-ROBIN SCHEDULING ALGORITHM With round-robin scheduling, the scheduler has a list

REAL-TIME OPERATING SYSTEMS a、ROUND-ROBIN SCHEDULING ALGORITHM With round-robin scheduling, the scheduler has a list of tasks and, when deactivating the active task, activates the next task that is in the READY state. Round-robin can be used with either preemptive or cooperative multitasking. It works well if you do not need to guarantee response time, if the response time is not an issue, or if all tasks have the same priority. All tasks are on the same level; the possession of the CPU changes periodically after a predefined execution time. This time is called timeslice, and may be defined individually for every task.

REAL-TIME OPERATING SYSTEMS b、PRIORITY-CONTROLLED SCHEDULING ALGORITHM In real-world applications, different tasks require different response

REAL-TIME OPERATING SYSTEMS b、PRIORITY-CONTROLLED SCHEDULING ALGORITHM In real-world applications, different tasks require different response times. For example, in an application that controls a motor, a keyboard, and a display, the motor usually requires faster reaction time than the keyboard and display. While the display is being updated, the motor needs to be controlled. This makes preemptive multitasking a must. Round-robin might work, but because it cannot guarantee a specific reaction time.

REAL-TIME OPERATING SYSTEMS In priority-controlled scheduling, every task is assigned a priority. The order

REAL-TIME OPERATING SYSTEMS In priority-controlled scheduling, every task is assigned a priority. The order of execution depends on this priority. The scheduler activates the task that has the highest priority of all tasks in the READY state. This means that every time a task with higher priority than the active task gets ready, it immediately becomes the active task.

REAL-TIME OPERATING SYSTEMS 2、Communication between tasks In a multitasking (multithreaded) program, multiple tasks work

REAL-TIME OPERATING SYSTEMS 2、Communication between tasks In a multitasking (multithreaded) program, multiple tasks work completely separately. Because they all work in the same application, it will sometimes be necessary for them to exchange information with each other. a、GLOBAL VARIABLES The easiest way to do this is by using global variables. In certain situations, it can make sense for tasks to communicate via global variables, but most of the time this method has various disadvantages. For example, if you want to synchronize a task to start when the value of a global variable changes, you have to poll this variable, wasting precious calculation time and power, and the reaction time depends on how often you poll.

REAL-TIME OPERATING SYSTEMS b、COMMUNICATION MECHANISMS When multiple tasks work with one another, they often

REAL-TIME OPERATING SYSTEMS b、COMMUNICATION MECHANISMS When multiple tasks work with one another, they often have to: ● exchange data, ● synchronize with another task, or ● make sure that a resource is used by no more than one task at a time. a) Signals represent the simplest and fastest form of task communication. No actual information is exchanged - only a stimulus is activated for a task. These can always be used when a pure task synchronisation is required without data exchange. b) MAILBOXES AND QUEUES A mailbox is basically a data buffer managed by the RTOS and is used for sending a message to a task. A queue works in a similar manner, but handle larger messages than mailboxes, and every message may have a individual size.

REAL-TIME OPERATING SYSTEMS c) SEMAPHORES In a multi-tasking system there is often competition for

REAL-TIME OPERATING SYSTEMS c) SEMAPHORES In a multi-tasking system there is often competition for resources. When several tasks can use the same portion of memory, the same serial I/O channel or another system resource, you have to find a way to keep the tasks out of each other‘s way. The semaphore is a protocol mechanism, which is used primarily to control access to shared resources (mutual exclusion). By means of the semaphore concept, resources can be shared free of conflicts between the individual tasks.

RTX 51 多任务实时操作系统 Advantages in using a Real-Time Multitasking Executive: ● A program can

RTX 51 多任务实时操作系统 Advantages in using a Real-Time Multitasking Executive: ● A program can be more easily implemented, tested and maintained by breaking down the problem to be solved into individual, easily comprehensible tasks. ● The modular approach allows individual tasks to be used in other projects. ● Since the real-time and multitasking problems which occur are already solved the time required for creating programs and testing is considerably reduced. Advantages of RTX-51: ● Simple use of RTX-51 by integration in the Keil C 51 development system. ● Complete support of all C 51 features such as floating-point operations, reentrant functions and interrupt functions. ● User-friendly configuration of RTX-51 for all members of the 8051 family. ● Flexibility - only requires a few system resources and can also be applied for time-critical applications

RTX 51 多任务实时操作系统 RTX 51 Tiny系统资源需求: Parameter Limits Maximum Number of Defined Tasks 16

RTX 51 多任务实时操作系统 RTX 51 Tiny系统资源需求: Parameter Limits Maximum Number of Defined Tasks 16 Maximum Number of Active Tasks 16 Required CODE Space 900 Bytes Max Required DATA Space 7 Bytes Required STACK Space 3 Bytes/Task Required XDATA Space 0 Bytes Timer 0 System Clock Divisor 1, 000 -65, 535 Interrupt Latency 20 Cycles or Less Context Switch Time 100 -700 Cycles

RTX 51 多任务实时操作系统 RTX-51 requires the following 8051 system resources: CODE Memory: Approx. 6

RTX 51 多任务实时操作系统 RTX-51 requires the following 8051 system resources: CODE Memory: Approx. 6 to 8 Kbytes, depending on the function scope used. Internal (DATA and IDATA) RAM: 40 to 46 bytes for system data (depending on the selected processor type). 20 to 200 bytes for the stack (can be configured by the user). Register bank 0 for standard tasks; register banks 1, 2 and 3 for fast tasks or C 51 interrupt functions. External (XDATA) RAM: Minimal 450 bytes. Timer 0, 1 or 2 for the system clock (can be configured by the user).

RTX 51 多任务实时操作系统 RTX-51 recognizes two classes of tasks: ● Fast tasks with especially

RTX 51 多任务实时操作系统 RTX-51 recognizes two classes of tasks: ● Fast tasks with especially short responses and interrupt times. Each fast task uses an individual register bank of the 8051 and contains its own stack area. RTX-51 supports a maximum of three fast tasks active at a time. ● Standard tasks that require somewhat more time for the task switching, therefore less internal memory than the fast tasks. All standard tasks share a register bank and a stack area; during a task change the current contents of registers and the stack are stored in the external RAM. RTX-51 supports a maximum of 16 standard tasks active at a time.

Task States Each RTX 51 Tiny task is always in exactly one state which

Task States Each RTX 51 Tiny task is always in exactly one state which tells the disposition of the task. State Description The task that is currently running is in the RUNNING State. Only one task at RUNNING a time may be in this state. The os_running_task_id returns the task number of the currently executing task. Tasks which are ready to run are in the READY State. Once the Running task has completed processing, RTX 51 Tiny selects and starts the next Ready task. A task may be made ready immediately (even if the task is READY waiting for a timeout or signal) by setting its ready flag using the os_set_ready or isr_set_ready functions. Tasks which are waiting for an event are in the WAITING State. Once the WAITING event occurs, the task is switched to the READY State. The os_wait function is used to place a task in the WAITING State. Tasks which have not been started or tasks which have been deleted are in DELETED the DELETED State. The os_delete_task routine places a task that has been started (with os_create_task) into the DELETED State. Tasks which were interrupted by a Round-Robin Time-Out are in the TIME-OUT State. This state is equivalent to the READY State for Round-Robin

RTX 51 多任务实时操作系统 Multi-Tasking Programs More sophisticated C programs may implement a pseudo-multitasking scheme

RTX 51 多任务实时操作系统 Multi-Tasking Programs More sophisticated C programs may implement a pseudo-multitasking scheme where several functions (or tasks) are called in a loop. For example: void main (void) { int counter = 0; while (1) /* repeat forever */ {check_serial_io (); /* check for serial input */ process_serial_cmds (); /* process serial input */ check_kbd_io (); /* check for keyboard input */ process_kbd_cmds (); /* process keyboard input */ adjust_ctrlr_parms (); /* adjust the controller */ counter++; /* increment counter */ } }

RTX 51 Tiny Programs void check_serial_io_task (void) _task_ 1 { /* This task checks

RTX 51 Tiny Programs void check_serial_io_task (void) _task_ 1 { /* This task checks for serial I/O */ } void process_serial_cmds_task (void) _task_ 2 { /* This task processes serial commands */ } void check_kbd_io_task (void) _task_ 3 { /* This task checks for keyboard I/O */ } void process_kbd_cmds_task (void) _task_ 4 { /* This task processes keyboard commands */ } void startup_task (void) _task_ 0 { os_create_task (1); /* Create serial_io Task */ os_create_task (2); /* Create serial_cmds Task */ os_create_task (3); /* Create kbd_io Task */ os_create_task (4); /* Create kbd_cmds Task */ os_delete_task (0); /* Delete the Startup Task */ }