Slides created by: Professor Ian G. Harris Typical Embedded C Program #include main() { // initialization code while (1) { // main code }  #include is.

Slides:



Advertisements
Similar presentations
Introduction to HT-IDE3000 Micro-C development System Department.
Advertisements

Simulation executable (simv)
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Slides created by: Professor Ian G. Harris PIC Development Environment MPLAB IDE integrates all of the tools that we will use 1.Project Manager -Groups.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
9.0 EMBEDDED SOFTWARE DEVELOPMENT TOOLS 9.1 Introduction Application programs are typically developed, compiled, and run on host system Embedded programs.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Slides created by: Professor Ian G. Harris Inputs and Outputs PIC Vcc RA3 RA4 RA5  Make an LED toggle state when button is pressed  Need to read RA3,
MotoHawk Training Model-Based Design of Embedded Systems.
Embedded Systems Programming Introduction to cross development techniques.
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
1-1 Embedded Software Development Tools and Processes Hardware & Software Hardware – Host development system Software – Compilers, simulators etc. Target.
1 ECE 263 Embedded System Design Lessons 2, 3 68HC12 Hardware Overview, Subsystems, and memory System.
Railway Foundation Electronic, Electrical and Processor Engineering.
Software Development and Software Loading in Embedded Systems.
COP4020 Programming Languages
INTERRUPTS PROGRAMMING
Engineering 1040: Mechanisms & Electric Circuits Fall 2011 Introduction to Embedded Systems.
ATmega 2560 Datasheet Main features are listed
Programming & Development of Mobile & Embedded Systems Lin Zhong ELEC424, Fall 2010.
Introduction Purpose Objectives Content Learning Time
Cortex-M3 Debugging System
1 © Unitec New Zealand Embedded Hardware ETEC 6416 Date: - 10 Aug,2011.
Atmega32 Architectural Overview
Computer Organization
AVR Microcontrollers.
System Calls 1.
Slides created by: Professor Ian G. Harris Test and Debugging  Controllability and observability are required Controllability Ability to control sources.
Revised: Aug 1, ECE 263 Embedded System Design Lesson 1 68HC12 Overview.
Machine Instruction Characteristics
MICROPROCESSOR INPUT/OUTPUT
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Replay Compilation: Improving Debuggability of a Just-in Time Complier Presenter: Jun Tao.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Chapter 2 Introducing the PIC Mid-Range Family and the 16F84A The aims of this chapter are to introduce: The PIC mid-range family, in overview The overall.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
25 April 2000 SEESCOASEESCOA STWW - Programma Evaluation of on-chip debugging techniques Deliverable D5.1 Michiel Ronsse.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
Presented by Sadhish Prabhu
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Chapter Microcontroller
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose  This training course demonstrates the Project Generator function.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
AVR Architecture Prepared By: Avdhesh Soni ( ) Sarthak Patel ( ) Akshay Parekh ( ) Fenil Sachla ( ) Guided.
HJD Institute of Technical Education & Research- Kera(Kutch) The 8051 Microcontroller architecture PREPARED BY: RAYMA SOHIL( )
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
1 Chapter 1 Basic Structures Of Computers. Computer : Introduction A computer is an electronic machine,devised for performing calculations and controlling.
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
Popular Microcontrollers and their Selection by Lachit Dutta
Embedded Systems Programming
Chapter 3 General-Purpose Processors: Software
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
PROGRAMMABLE LOGIC CONTROLLERS SINGLE CHIP COMPUTER
Atmega32 Architectural Overview
AVR ATMEGA 8 MICRO-CONTROLLER
Microprocessor Systems Design I
System Programming and administration
UNIT – Microcontroller.
An Embedded Software Primer
The Arduino Microcontroller: Atmel AVR Atmega 328
Structures Collection of several variables under a single name
9.0 EMBEDDED SOFTWARE DEVELOPMENT TOOLS
Debugging Debug environments Debug via serial
Embedded System Development Lecture 13 4/11/2007
Presentation transcript:

Slides created by: Professor Ian G. Harris Typical Embedded C Program #include main() { // initialization code while (1) { // main code }  #include is a compiler directive to include (concatenate) another file  main is the function where execution starts

Slides created by: Professor Ian G. Harris Header Files  Files included at the top of a code file  Traditionally named with.h suffix  Include information to be shared between files Function prototypes extern s of global variables Global #define s  Needed to refer to libraries

Slides created by: Professor Ian G. Harris Function Calls  Functions enable simple code reuse  Control moves to function, returns on completion  Functions return only 1 value main() { int x; x = foo( 3, 4); printf(“%i\n”, x); } int foo(int x, int y) { return (x+y*3); }

Slides created by: Professor Ian G. Harris Function Call Overhead main() { int x; x = foo(2); printf(“%i\n”, x); } int foo(int x) { int y=3; return (x+y*3); }  Program counter value needs to be restored after call  Local variables are stored on the stack  Function calls place arguments and return address on the stack 20: 21: 22: 30: 31: 103: 3local var 102: 2argument 101: 21return addr 100: 2local var

Slides created by: Professor Ian G. Harris Variables  Static allocation vs. Dynamic allocation  Static dedicates fixed space on the stack  Dynamic (malloc) allocates from the heap at runtime  Type sizes depend on the architecture On x86, int is 32 bits On ATmega2560, int is 16 bits char is always 8 bits

Slides created by: Professor Ian G. Harris Variable Base Representation  Base 10 is default  Base can be specified with a prefix before the number  Binary is 0b, Hexadecimal is 0x Ex. char x = 0b ; char x = 0h33;  Binary is useful to show each bit value  Hex is compact and easy to convert to binary  1 hex digit = 4 binary digits

Slides created by: Professor Ian G. Harris Volatile Variables  The value of a volatile variable may change at any time, not just at an explicit assignment  Compiler optimizations are not applied to volatile variables  When can variables change without an explicit assignment? 1. Memory-mapped peripheral registers 2. Global variables modified by an interrupt service routine 3. Global variables accessed by multiple tasks within a multi- threaded application

Slides created by: Professor Ian G. Harris Volatile Example. while (*periph != 1); // wait until data transfer. // is complete.  periph is the mapped address of the peripheral status info  *periph is assigned by peripheral directly  Compiled code will move memory contents to a register  Memory will only be moved once because *periph does not change

Slides created by: Professor Ian G. Harris Bitwise Operations  Treat the value as an array of bits  Bitwise operations are performed on pairs of corresponding bits X = 0b0011, Y = 0b0110 Z = X | Y = 0b0111 Z = X & Y = 0b0001 Z = X ^ Y = 0b0101 Z = ~X = 0b1100 Z = X << 1 = 0b0110 Z = x >> 1 = 0b0001

Slides created by: Professor Ian G. Harris Bit Masks  Need to access a subset of the bits in a variable Write or read  Masks are bit sequences which identify the important bits with a ‘1’ value  Ex. Set bits 3 and 5 or X, don’t change other bits X = , mask = X = X | mask  Ex. Clear bits 2 and 4 mask = X = X & mask

Slides created by: Professor Ian G. Harris Bit Assignment Macros  1 << (n) and ~(1) << (n) create the mask Single 1 (0) shifted n times  Macro doesn’t require memory access (on stack) #define SET_BIT(p,n) ((p) |= (1 << (n))) #define CLR_BIT(p,n) ((p) &= (~(1) << (n)))

Slides created by: Professor Ian G. Harris Embedded Toolchain  A toolchain is the set of software tools which allow a program to run on an embedded system  Host machine is the machine running the toolchain  Target machine is the embedded system where the program will execute Host has more computational power then target  We are using the GNU toolchain Free, open source, many features

Slides created by: Professor Ian G. Harris Cross-Compiler  A compiler which generates code for a platform different from the one it executes on Executes on host, generates code for target  Generates an object file (.o)  Contains machine instructions  References are virtual Absolute addresses are not yet available Labels are used instead

Slides created by: Professor Ian G. Harris Cross-Compiler Example ABBOTT.o … MOVE R1, (idunno) CALL whosonfirst … ABBOTT.c int idunno; … whosonfirst(idunno) … Cross- compiler COSTELLO.c int whosonfirst(int x) { … } Cross- compiler COSTELLO.o … whosonfirst: … Idunno, whosonfirst Unknown addresses

Slides created by: Professor Ian G. Harris Linker  Combines multiple object files  References are relative to the start of the executable  Executable is relocatable  Typically need an operating system to handle relocation

Slides created by: Professor Ian G. Harris Linker Example ABBOTT.o … MOVE R1, (idunno) CALL whosonfirst … COSTELLO.o … whosonfirst: MOVE R5, R1 … HAHA.exe … MOVE R1, 2388 CALL 1547 … MOVE R5, R1 … (value of idunno) Linker  Functions are merged  Relative addresses used

Slides created by: Professor Ian G. Harris Linker/Locator  Links executables and identifies absolute physical addresses on the target  Locating obviates the need for an operating system  Needs memory map information Select type of memory to be used (Flash, SRAM, …) Select location in memory to avoid important data (stack, etc.) Often provided manually

Slides created by: Professor Ian G. Harris Segments  Data in an executable is typically divided into segments  Type of memory is determined by the segment  Instruction Segment - non-volatile storage  Constant Strings – non-volatile storage  Uninitialized Data – volatile storage  Initialized Data – non-volatile and volatile Need to record initial values and allow for changes

Slides created by: Professor Ian G. Harris AVR GNU Toolchain  Cross-Compiler: avr-gcc  Linker/Locator: avr-ld  Cross-Assembler: avr-as  Programmer: avrdude  All can be invoked via AVR Studio 5

Slides created by: Professor Ian G. Harris ATmega 2560 Pins  Fixed-Use pins VCC, GND, RESET XTAL1, XTAL2 - input/output for crystal oscillator AVCC - power for ADC, connect to VCC AREF - analog reference pin for ADC  General-Purpose ports Ports A-E, G, H, J, L Ports F and K are for analog inputs All ports are 8-bits, except G (6 bits)

Slides created by: Professor Ian G. Harris I/O Pins, Output Path DDRx PORTx

Slides created by: Professor Ian G. Harris I/O Pins, Input Path PINx

Slides created by: Professor Ian G. Harris I/O Control Registers  DDRx – Controls the output tristate for port x DDRx bit = 1 makes the port x an output pin DDRx bit = 0 makes the port x an input pin Ex. DDRA = 0b , outputs are bits 7, 6, 3, and 2  PORTx – Control the value driven on port x Only meaningful if port x is an output Ex. PORTA = 0b assigns pin values as shown  PINx – Contains value on port x Ex. Q = PINC;

Slides created by: Professor Ian G. Harris Test and Debugging  Controllability and observability are required Controllability Ability to control sources of data used by the system Input pins, input interfaces (serial, ethernet, etc.) Registers and internal memory Observability Ability to observe intermediate and final results Output pins, output interfaces Registers and internal memory

Slides created by: Professor Ian G. Harris I/O Access is Insufficient  Control and observation of I/O is not enough to debug main(){ x = f1(RA0,RA1); foo (x); } foo(x){ y = f2(x); bar (y); } bar(y){ RA2 = f3(y); } RA0 RA1 RA2  If RA2 is incorrect, how do you locate the bug?  Control/observe x and y at function calls?

Slides created by: Professor Ian G. Harris Embedded Debugging Properties of a debugging environment: 1. Run Control of the target - Start and stop the program execution 2. Ability to change code and data on target - Fix errors, test alternatives 3. Real-Time Monitoring of target execution - Non-intrusive in terms of performance 4. Timing and Functional Accuracy - Debugged system should act like the real system

Slides created by: Professor Ian G. Harris Host-Based Debugging  Compile and debug your program on the host system, not target - Compile C to your laptop, not the microcontroller Advantages: 1.Can use a good debugging environment 2.Easy to try it, not much setup (register names, etc) Disadvantages: 1.Timing is way off 2.Peripherals will not work, need to simulate them 3.Interrupts probably implemented differently 4.Different data sizes and “endian”ness

Slides created by: Professor Ian G. Harris Instruction Set Simulator  Instruction Set Simulator (ISS) runs on the host but simulates the target  Each machine instruction on the target is converted into a set of instructions on the host  Example:  Target Instruction - add x : Adds register x to the acc register, result in the acc register  Host equivalent: add acc, x, acc : Adds second reg to third, result in the first reg

Slides created by: Professor Ian G. Harris ISS Tradeoffs Advantages: 1. Total run control 2. Can change code and data easily Disadvantages: 1. Simulator assumptions can cause inaccuracies 2. Timing is off, no real-time monitoring - initial register values, timing assumptions 3. “Hardware environment” of target cannot be easily modeled

Slides created by: Professor Ian G. Harris Hardware Environment  PIC communicates with the switch and the RAM  Communications must be modeled to test PIC code  Simulators allow generation of simple event sequences  Responsiveness is more difficult to model

Slides created by: Professor Ian G. Harris Remote Debug/Debug Kernel  Remote debugger on the host interacts with a debug kernel on the target  Communication through a spare channel (serial or ethernet)  Debug kernel responds to commands from remote debugger  Debug kernel is an interrupt, so control is possible at any time Host (PC) Target (Atmega) Serial or TCP/IP

Slides created by: Professor Ian G. Harris Remote Debug Tradeoffs Advantages: 1.Good run control using interrupts to stop execution 2.Debug kernel can alter memory and registers 3.Perfect functional accuracy Disadvantages: 1.Debug interrupts alter timing so real-time monitoring is not possible 2.Need a spare communication channel 3.Need program in RAM (not flash) to add breakpoints

Slides created by: Professor Ian G. Harris ROM Emulator  Common to read instructions from a separate ROM on the target  ROM emulator substitutes the ROM for a RAM with a controller

Slides created by: Professor Ian G. Harris ROM Emulator Features  Remote debugger where ROM is replaced by RAM - Debug kernel is in the RAM  Solves the “non-writable ROM” problem of remote debugging  ROM emulator completely controls the instructions - Full data access is possible  ROM emulator can contain a debug communication channel No need for a spare channel

Slides created by: Professor Ian G. Harris ROM Emulator Disadvantages  Instruction ROM must be separate from the microcontroller - No embedded ROM  There must be a way to write to the ROM - May be done with a complex sequence of reads  Alters timing, just as any debug kernel would

Slides created by: Professor Ian G. Harris In-Circuit Emulation (ICE)  Replace the microcontroller with an new one  Can select instructions from external ROM (normal mode) or internal shadow RAM (test mode)

Slides created by: Professor Ian G. Harris ICE Advantages  ICE can always maintain control of the program  - Interrupt cannot be masked  Works even if system ROM is broken  Generally the best solution

Slides created by: Professor Ian G. Harris Debouncing Buttons Micro- controller Vcc Input input 10ms  Mechanical bounce in switch causes signal to bounce  Noticable at MHz clock rates  Need to wait until signal settles before sampling it

Slides created by: Professor Ian G. Harris Wait to Settle  settletime is the time a button signal must stay constant to be sure that it is settled  After a signal change, wait settletime clks  Debounce rising edge, reset counter every signal change to 0 i = 0; while (i < settletime) { if (in == 0) i = 0; else i = i + 1; }  Reset counter  Advance counter  Need to debounce falling edge as well as rising edge

Slides created by: Professor Ian G. Harris Debouncing Code while (1 == 1) { i = 0; while (i < settletime) { if (in == 0) i = 0; else i = i + 1; } i = 0; while (i < settletime) { if (in == 1) i = 0; else i = i + 1; } // perform operation }  Wait for rising edge to settle  Wait for falling edge to settle  Perform Operation