1 / 27

Embedded Systems

Embedded Systems. Lecture 0: Introduction. Ian McCrum Room 5B18, Tel: 90 366364 voice mail on 6 th ring Email: IJ.McCrum@Ulster.ac.uk Web site: http://www.eej.ulst.ac.uk. What is an embedded system.

jaimie
Download Presentation

Embedded Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Embedded Systems Lecture 0: Introduction Ian McCrum Room 5B18, Tel: 90 366364 voice mail on 6th ring Email: IJ.McCrum@Ulster.ac.uk Web site: http://www.eej.ulst.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) 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. 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. 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 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. 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. 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 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. www.eej.ulst.ac.uk/~ian/modules/EEE527

  10. Learning C 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. http://www.mindviewinc.com/ThinkingInC/Download.php www.eej.ulst.ac.uk/~ian/modules/EEE527

  11. Download the C course and review Chapters 1 through 7 www.eej.ulst.ac.uk/~ian/modules/EEE527

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

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

  14. 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.

  15. Integer Types www.eej.ulst.ac.uk/~ian/modules/EEE527

  16. 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. www.eej.ulst.ac.uk/~ian/modules/EEE527

  17. C Syntax Aide Memoire (cog sheet!) • White space doesn’t matter, case does – most C is lower case. • Commenting can be /* a block with start and stop comment symbols */ or a single line // text…<cr> • Names must begin with a letter or underscore, but don’t use underscores, the libraries use them. • Names should not contain funny symbols other than underscores. Use sensible names! • Use #define for symbols used throughout your code, you need only edit them in one place • Arithmetic uses +, -, *, / also % for remainders and &, | and ^ for AND, OR and XORs of the bits. • ++ and -- increment and decrement. It is so common to write x=x+c; you can write x+=c; //or -,*,/ etc • You can shift left and right using << and >>, you can do a one’s complement with ~ but be careful! • Types are char, int, float. You can declare a variable as a const type, it can’t change. • You can have signed and unsignedints and chars, short or longints and floats can be doubles. • Variables need declared before use, inside functions they’re local, outside they’re global • Casting forces the complier to convert a variable’s type in an expression, y=(float)x /z;//e.g x was int • Functions need declared before use, give their return type and the types in their parameter list. • Simple variables in a parameter list only have their value, a number, passed to the function. • 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. • Conditional tests. Use == as an equality test, also !=,for not equal, <, less than etc… <=, >,>=. • You can OR,AND and NOT tests with ||,&& and ! Use brackets! E.gif( (x == 9) && (y != 5) ){… • if( test is true){do these statements;} // the simple if statement, if there is one statement omit the { } • if( test is true){do these statements;}else{do these statements;} // note no semicolon after ) www.eej.ulst.ac.uk/~ian/modules/EEE527

  18. C Syntax Aide Memoire (cog sheet!) • Conditional expression is rarely used c = (do a test) ? Assign this if true :assign this if false; • switch(test an int){ case value1: do this; break;casevalue2:dothis; break; default:do this;} •  Loops; there are 3 of these, note carefully while is used twice, with or without a semicolon • do{these statements;}while(test is true); // there IS a semicolon after the while conditional test • while(test is true){do these statements;} // NO semicolon after while conditional test • for(initialisation;test;increment){do these statements;} // test done at top, increment at bottom • 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 items • 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 code • char s[ ]=”OK”; // note s[0]=’O’, s[1]=’K’ and s[2]=0x00 (can be written as ‘\0’) strings end in a zero • float f[ ]={42.0, 42.99, 69}; // this declares 3 elements. •  Pointers and addresses; get the address of a variable by using &, e.ga = &x; orscanf(“%d”,&x); • Declare a pointer by appending a  to the type (better style to move it near the variable name) • intptr1; or char ptr2; Note we often use pointers to move inside strings and arrays • To use the contents of what a pointer is pointing at use the indirection operator, also a  • e.gif(ptr2 == 0x00){… //ptr2 is pointing at a memory location or variable containing zero • You can declare a void pointer and later “cast” it to the right type. (see how to use malloc() ) • String functions use #include <string.h> then you get strlen, strcmp, strcpy, strstr,sprint see libc.pdf • malloc allocates memory, e.g to get somewhere for strings or buffers to live, if they are not declared. E.gp = (int *)malloc (sizeof(int) * BUFSIZE); // if p is an int pointer… note use of sizeof() • ++ -- + += - -= / /= * *= % %= | |= & &= ^ ^= = == != < <= > >= << <<= >> >>= ~ && || . , ; ? : ( ) [ ] { } /* */ // \ “ ‘ -> ! www.eej.ulst.ac.uk/~ian/modules/EEE527

  19. ++ -- + += - -= / /= * *= % %= | |= & &= ^ ^= = == != < <= > >= << <<= >> >>= ~ && || . , ; ? : ( ) [ ] { } /* */ // \ “ ‘ -> ! You should know enough C to know what each of the above is used for Now try lecture 1 to see how C is converted into machine code www.eej.ulst.ac.uk/~ian/modules/EEE527

More Related