embedded systems lecture 0: introduction ian mccrumroom 5b18, tel: 90 366364 voice mail on 6 th ring...

27
Embedded Systems Lecture 0: Introduction Ian McCrum Room 5B18, Tel: 90 366364 voice mail on 6 th ring Email: [email protected] Web site: http://www.eej.ulst.ac.uk www.eej.ulst.ac.uk/~ian/ modules/EEE527 1

Upload: darrell-johns

Post on 26-Dec-2015

243 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 1

Embedded Systems

Lecture 0: Introduction

Ian McCrum Room 5B18, Tel: 90 366364 voice mail on 6th ringEmail: [email protected] Web site: http://www.eej.ulst.ac.uk

Page 2: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 2

What is an embedded system

• A computerised real world device where you do not get conventional access to the computer (console/screen/keypad/mouse)

• Usually runs a dedicated program – you switch it on and it “boots” direct to that program

• Embedded systems run forever (until switched off)

Page 3: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 3

Examples of embedded Systems

• Washing machines, devices in the kitchen• Central heating contollers, thermostats, timeswitches• ECG monitors (and most electronic/medical devices)• Printers, peripherals such as a standalone hard disk• Car Radio, cameras, televisions, music systems• Engine Management System• Any modern device!, we are starting to see “The

Internet of Things (IOT) – embedded systems with connectivity.

Page 4: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 4

Salient features of an embedded system

• It possesses a CPU that does something• It possesses input devices connected to

sensors – to allow Measurement • It possesses input devices to allow user input• It possesses output devices – to allow Control • It possesses output devices – to allow Display• May possess “storage” and “connectivity”• It interfaces with the real world.

Page 5: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 5

Range of embedded devices

• Simple single chip microprocessors = Microcontrollers, CPU,Memory + I/O

• SOC – System on a Chip – silicon with several distinct systems – bluetooth device + cpu

• More complex microcontrollers – CPU, Memory, I/O including complex peripherals on chip.

• Embedded computers – running embedded operating systems – to manage complex resources such as USB, WiFi (TCP/IP stacks), even bluetooth

Page 6: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 6

On chip complex peripherals• Parallel input and output ports – e.g 8 bit ports with a couple of

synchronised handshake lines for status and control of data flow.• Analogue to Digital Convertors• Timers• Chip to chip serial communications – I2C and SPI• Serial communications – RS232 (RS485)

• Specialised serial communications I2S, Canbus, Linbus, • Very specialised serial communications USB ( has 4 types of data transfer

and needs sophisticated software to discover and negotiate data transfer)• High speed communications – ethernet• Wireless communications – Wifi, Bluetooth, Zigbee (Zwave,Mifi) and point

to point devices.

Page 7: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 7

Software for Embedded Systems

• CPUs run on machine code – binary numbers.• Assembler source (english text) can be converted to

machine code. One line of source becomes one instruction

• Macros and pseudoinstructions to enhance the assembler, one macro may become more than one line of assembler, and hence several machine instructions

• High level languages – usually a subset of the language. C or Java possible, C++ or Python in larger processors.

Page 8: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 8

C• An extremely popular systems programming language, first

used to write an operating system – designed to allow access to the machine.

• Very portable, efficient (fast and low memory footprint)• C++ is a superset of C, suits bigger programs but may be

slower• Java draws heavily on C++• C is “portable Assembler”• Some academics describe C as a low level language• Knowledge of C is vital – most modern language compilers are

written in C and/or access Libraries that have been written in C• Libraries are important – don’t reinvent the wheel

Page 9: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 9

C

• Fundamental Data Types• Operators• Controlling Program Flow• Compound Data Types (arrays and Structs)• Programming with Functions (sub programs)• Pointers• Controlling I/O devices – registers of the

machine.

Page 10: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 10

Learning C

http://www.mindviewinc.com/ThinkingInC/Download.php

Bruce Eckel provides public and private training and consulting in programming languages and software system design. He has published over 150 articles and seven books. Details can be found at www.BruceEckel.com.

Page 11: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 11

Download the C course and review Chapters 1 through 7

Page 12: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 12

Page 13: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 13

Page 14: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk
Page 15: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk
Page 16: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk
Page 17: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk
Page 18: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

The manual contradicts itself and states in 6.4.1 that by default chars are signed!You should ALWAYS prefix char declarations with the keyword unsigned.

Page 19: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk
Page 20: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk
Page 21: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk
Page 22: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk
Page 23: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 27

Integer Types

Page 24: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 28

Needed C skills• Be able to write simple C programs• Be able to use and write simple control

statements, if, for, do, while, switch/case, ?:• Be able to use simple data types and one

dimensional arrays• Be able to use and write Functions• Be able to split a large file into a number of files• Be able to access other peoples libraries• Understand how C is turned into machine code.

(try lecture 1 now!)

Unlikely to need complicated structs (collections of data of different types)Will be using function pointers when using FreeRTOS.

Page 25: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 29

C Syntax Aide Memoire (cog sheet!)

1. White space doesn’t matter, case does – most C is lower case.2. Commenting can be /* a block with start and stop comment symbols */ or a single line // text…<cr>3. Names must begin with a letter or underscore, but don’t use underscores, the libraries use them.4. Names should not contain funny symbols other than underscores. Use sensible names!5. Use #define for symbols used throughout your code, you need only edit them in one place6. Arithmetic uses +, -, *, / also % for remainders and &, | and ^ for AND, OR and XORs of the bits.7. ++ and -- increment and decrement. It is so common to write x=x+c; you can write x+=c; //or -,*,/ etc8. You can shift left and right using << and >>, you can do a one’s complement with ~ but be careful! 9. Types are char, int, float. You can declare a variable as a const type, it can’t change.10. You can have signed and unsigned ints and chars, short or long ints and floats can be doubles.11. Variables need declared before use, inside functions they’re local, outside they’re global 12. Casting forces the complier to convert a variable’s type in an expression, y=(float)x /z;//e.g x was int13. Functions need declared before use, give their return type and the types in their parameter list.14. Simple variables in a parameter list only have their value, a number, passed to the function.15. Declare functions before use, use them in main for example like y=sqrt(x); and list their body after

main (or before if you like, but adopt a consistent style). Give no semicolon when defining body.16. Conditional tests. Use == as an equality test, also !=,for not equal, <, less than etc… <=, >,>=. 17. You can OR,AND and NOT tests with ||,&& and ! Use brackets! E.g if( (x == 9) && (y != 5) ){…

18. if( test is true){do these statements;} // the simple if statement, if there is one statement omit the { }19. if( test is true){do these statements;}else{do these statements;} // note no semicolon after )

Page 26: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 30

C Syntax Aide Memoire (cog sheet!)20. Conditional expression is rarely used c = (do a test) ? Assign this if true : assign this if false; 21. switch(test an int){ case value1: do this; break; case value2: dothis; break; default: do this;}  Loops; there are 3 of these, note carefully while is used twice, with or without a semicolon22. do{these statements;}while(test is true); // there IS a semicolon after the while conditional test23. while(test is true){do these statements;} // NO semicolon after while conditional test24. for(initialisation;test;increment){do these statements;} // test done at top, increment at bottom25. You can exit a loop prematurely using break; , or go back to the beginning of a loop with

continue; Arrays use square brackets, you can give its size as a number or string, or list of items26. int x[4]; // i.e x[0] to x[3] note 4 elements it is a mistake to refer otherwise use x[4] in your code27. char s[ ]=”OK”; // note s[0]=’O’, s[1]=’K’ and s[2]=0x00 (can be written as ‘\0’) strings end in a

zero28. float f[ ]={42.0, 42.99, 69}; // this declares 3 elements. Pointers and addresses; get the address of a variable by using &, e.g a = &x; or scanf(“%d”,&x);29. Declare a pointer by appending a to the type (better style to move it near the variable name)30. int ptr1; or char ptr2; Note we often use pointers to move inside strings and arrays31. To use the contents of what a pointer is pointing at use the indirection operator, also a 32. e.g if(ptr2 == 0x00){… //ptr2 is pointing at a memory location or variable containing zero33. You can declare a void pointer and later “cast” it to the right type. (see how to use malloc() )39. String functions use #include <string.h> then you get strlen, strcmp, strcpy, strstr, sprint see

libc.pdf40. malloc allocates memory, e.g to get somewhere for strings or buffers to live, if they are not

declared. E.g p = (int *)malloc (sizeof(int) * BUFSIZE); // if p is an int pointer… note use of sizeof()

41. ++ -- + += - -= / /= * *= % %= | |= & &= ^ ^= = == != < <= > >= << <<= >> >>= ~ && || . , ; ? : ( ) [ ] { } /* */ // \ “ ‘ -> !

Page 27: Embedded Systems Lecture 0: Introduction Ian McCrumRoom 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: @Ulster.ac.uk

www.eej.ulst.ac.uk/~ian/modules/EEE527 31

++ -- + += - -= / /= * *= % %= | |= & &= ^ ^= = == != < <= > >= << <<= >> >>= ~ && || . , ; ? : (

) [ ] { } /* */ // \ “ ‘ -> !You should know enough C to know what each of the above is used forNow try lecture 1 to see how C is converted into machine code