CS3369: Real Time Computer Control Software Who I am: Dr. Lusheng WANG Dept. of Computer Science office: Y6429 phone: 2788 9820 e-mail: lwang@cs.cityu.edu.hk web site: http://www.cs.cityu.edu.hk/~lwang Page 1 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Suggested References: • D.M. Auslander and C.H. Tham, “Real-time software for control: Programming examples in C”, Prentice Hall, USA, 1990. • S. Bennett, “Real-time computer control: An introduction”, Prentice Hall, UK, 1988. • Babu Joseph, Real-time personal computing (for data acquisition and control), Prentice Hall, Englewood Cliffs, New Jersey, 1989. • P. Norton, P. Aitken, R. Wilton, “PC Programmer’s Bible”, 1993. • Turbo C, User Guide, ver. 2.0 Borland International, 1988 • Dr. James T. Smith, “Advance Turbo C”, McGraw-Hill Book Company, 1989. • H.M. Deitel and P. J. Deitel, “C++ How to program”, Prentice Hall, 1998. Page 2 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Four Parts of the Course: Introduction to real time systems and basic computer organization Real time scheduling Real time system development methodology Real time programming Page 3 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng What I Cover: some basic concepts in real time embedded systems computers organization programming in C++ interrupts and controls top down design requirements specification program testing Page 4 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Evaluation of the Course Course work: 40% Two Assignments. 20% each. I give you time in the labs to do the two assignments. Project: optional. 10% bonus for the course work. A final exam: 60%; Page 5 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng How to Teach Contents are divided into four classes 1. Basic part -- every body must understand in order to pass 2. Moderate part -- most of students should understand. Aim at B or above. 3. Hard part -- used to distinguish students. Aim at A or above. 4. Fun part -- just illustrate that some interesting things can be done if one works very hard. -- useful knowledge that will not be tested. Page 6 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng How to Learn 1. Attend every lecture and tutorial. (4 hours per week) 2. Try to go with me when I am talking 3. Ask questions immediately 4. Try to fix all problems during the 2 hours tutorial 5. Ask other students to help during the lab. Every student should be able to finish basic part in tutorial/lab. Most of students should be able to finish the moderate part in tutorial/lab. If you do the above, you should be able to get at least B+. Page 7 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Real Time Embedded Systems Computer systems that operate as an integral part of physical systems, and very often, react and readjust control variables quickly to the changes in physical systems. Functionality: • monitor equipment performance • timely control equipment operations • provide human-machine interfaces Page 8 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Three types of Real Time Embedded Systems Hard: Each job enters the system with a deadline before which it has to be served. Later response is not allowed. Soft: The average response time for the jobs is to be minimized. Firm: A combination of soft and hard real time requirements. Page 9 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Examples of Real Time Embedded Systems: Air-conditioning Control Elevator Control Traffic Light Control Video Games TV Remote Control Page 10 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Introduction to Computer Hardware We will learn the following: 1. Architecture of computer hardware 2. Execution of an instruction 3. Execution of a program Page 11 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Basic hardware components Central Processing Unit Memory Input/Output Sub-systems Buses Page 12 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Architecture of Computer Hardware cpu General Purpose Registers Arithmetic and Logic Unit Control Unit data/address/control buses Main Memory Input/Output Interfaces Peripherals Page 13 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng What Does a Computer Do? Do some computation according to users’ willing 1. Users tell computers what to do via programs. 2. A program is a sequence of instructions. 3. Instructions are the basic operations computers can do. 4. Examples of Instruction add 2, 3 (compute 2 + 3) sub 4, 2 (compute 4 - 2) Page 14 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng An Example of a Program The instructions are executed sequentially There are some instructions allow jump x=3*5+6-7; (High level language) x=3; x=x*5; x=x+6; x=x-7; (Low level language) (A set of instructions) Page 15 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Central Processing Unit (CPU) Execute program stored in the main memory by fetching their instructions, examining them and then executing them one after another Components of CPU 1.Arithmetic logical unit (ALU) – performs operations such as addition and boolean AND needed to carry out the instructions 2.Registers – high-speed memory used to store temporary results and certain control information used by the CPU. CPU registers such as program counter (PC), instruction registers (IR), status registers 3.Control unit (CU) – fetching instructions from main memory and determining their type Page 16 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Memory part of the computer where program and data are stored and to be processed by the processor Also called Main Memory, Random Access Memory (RAM) Bits - the basic unit of memory is the binary digit, a bit contains a "0" or "1". Memory contains many bits organised in linear order. Several bits form a “cell” containing a piece of information (data, instruction, integer, character, etc) The size of the cell can be a byte or several successive bytes. Each cell has a reference number, called its address, by which program can refer to. Page 17 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Buses Communication links allowing data, instructions and memory addresses to be referred between different components (CPU, main memory and I/O devices) in a computer system. Example: UNIBUS - Digital Computer Inc., PC Bus - Industrial Standard PC bus Peripheral Component Interconnect (PCI) Bus Page 18 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Input/Output Device Input Devices • Allows computer user to issue commands, asks for information, adds new data and programs to the computer. • The computer receives input from the press of a key or button, touch of a finger on a screen, optical scanners, spoken words and many sources. Output devices Display results to the user. Includes video display screen, printers, audio speakers. Page 19 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng General Purpose Registers Arithmetic and Logic Unit Control Unit data/address/control buses Main Memory real-time clock disk drive digital signals CD Drive pulse operations printer analog-to-digital conversion Key board digital-to- analog conversion 5/29/2016 Input/Output Interfaces …... CS3369 Real Time Control Software/WANG Lusheng Display Page 20 Execution of an Instruction Execution of an instruction is achieved by a sequence of commands issues by the control unit. Fetch the instruction from the memory Fetch the operands from the memory Perform the operation Update the program counter no Check interrupt yes Interrupt processing Next Instruction 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Page 21 Execution of a Program Fetch the instruction from the memory Fetch the operands from the memory Perform the operation Update the program counter A program is a sequence of instructions. no LOAD b, R1 Check interrupt yes Fetch the instruction from the memory Fetch the operands from the memory Perform the operation Update the program counter no Check interrupt yes ADD R1, 1 a = b + 1; Fetch the instruction from the memory Fetch the operands from the memory Perform the operation Update the program counter no 5/29/2016 STORE R1, a Check interrupt yes …... CS3369 Real Time Control Software/WANG Lusheng Page 22 Computer Languages Users use languages to write instructions and programs. There are lots of computer languages that can be classified into two categories -- low level and high level languages Low Level Languages: Machine language -binary code Assembly language Examples of Low Level Languages: ADD A3, D5 1101 101 001 001 011 Assembly instruction Machine language Page 23 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng High Level Computer Languages English-like languages -- easy to handle for users -- computers cannot directly understand Examples: C, C++, PASCAL, LISP, COBAL, etc Running a program written in high level languages: 1. Compile the program (translate the high level language into a machine language. Done automatically by a software called compiler.) 2. Execute the translated code. (executable code) 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Page 24 The First C Program #include<stdio.h> int main(void) { printf(“Hello, world! \n”); return 0; } Output: Hello, world! \n stand for “new line” It will not be shown on the screen Page 25 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng The First C++ Program #include<iostream.h> /* to include the file iostream.h */ int main(void) { cout <<“Hello, world! \n”; return 0; } /* part of every C++ program */ Output: Hello, world! /* { The beginning of main function */ /*print out Hello, world! On screen */ /* exit a function */ /*} The end of main function */ \n stand for “new line” It will not be shown on the screen Page 26 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng The first program for computation #include <iostream.h> int main(void) { int x,y;z; Note that, there are three variables x, y, and z. All are of type integer. Each integer variable can store an integer. The variable itself has an address, which is automatically assigned by the system (computer). x = 1; y = 2; z = x+ y; cout <<“The sum of x and y is” << z; return 0; } Page 27 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng The address of a variable In C, the address of a variable can be known by user. #include <iostream.h> int main (void) { int x; cout <<“The address of x is” << &x; return 0; } Output: -134219164 Note that, each execution gives a different address. Exercise: Try to run the program three times. What happens? Page 28 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Examples of C++ Programs We Intend to Deal with Print out a person that can move Some program about graphics (G1 and G2) Time Delay-- create movies (G3, also person) Move keys with interrupts (key) Page 29 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng Summary 1. Real time embedded systems. 2. Computer architecture 3. Memory 4. Execution of instructions and programs. 5. C++ Page 30 5/29/2016 CS3369 Real Time Control Software/WANG Lusheng