Development tools and Programming for embedded processors

Document Sample
scope of work template
							嵌入式處理器架構與程式設計

       王建民
   中央研究院 資訊所
     2008年 7月
Contents
 Introduction
 Computer Architecture

 ARM Architecture
 Development Tools
 GNU Development Tools
 ARM Instruction Set

 ARM Assembly Language
 ARM Assembly Programming
 GNU ARM ToolChain

 Interrupts and Monitor

                             2
 Lecture 1
Introduction
Outline
   Basic Concepts
   Course Info
   Embedded Systems
   Programming Systems




                          4
Computer Systems
   Hardware
   Firmware
   Software
       Application software
       System software
          Programming systems
          Utilities

          Operating systems




                                 5
Computer Software
   Application software is designed to solve a
    specific problem.
   System software is intended to support the
    operation and use of the computer itself.
       Provide a general programming environment.
       Provide functions used by application software
        and users.
       Provide mechanisms to share the hardware in
        an orderly fashion.

                                                     6
Foundations of Computer Systems

                 Users
          Application Software
          Programming System
       Operating System
               Hardware




                                  7
Evolution of Programming1
   Machine Language
       Binary format
          11100101100111110001000000010000
          11100101100111110000000000001000
          11100000100000010101000000000000
          11100101100011110101000000001000
       Hexadecimal format
          E59F1010
          E59F0008
          E0815000
          E58F5008

                                             8
Evolution of Programming2
   Assembly Language
       Mnemonic codes
         E59F1010    LDR   R1,   num1
         E59F0008    LDR   R0,   num2
         E0815000    ADD   R5,   R1, R0
         E58F5008    STR   R5,   sum
   High-Level Language
       C language
         sum = num1 + num2;


                                          9
How instructions are executed?
. . .
E59F1010
E59F0008
E0815000
E59F5008
. . .




                                 10
How a source program is compiled?
int main()
{
  . . .
  sum = num1 + num2;
  . . .
}



                        . . .
                        E59F1010
                        E59F0008
                        E0815000
                        E59F5008
                        . . .

                                   11
How to develop embedded software?
#define GREETING “Hello, World!\n”
int main()
{
  printf(GREETING);
}




                                     12
What are you going to learn?
   How instructions are executed?
       Computer Architecture
   How a source program is compiled?
       Development tools
   How to develop embedded software?
       Embedded processors
       Assembly language and programming
       Cross development
       Software interrupts

                                            13
Outline
   Basic Concepts
   Course Info
   Embedded Systems
   Programming Systems




                          14
Prerequisites and Related Courses
   Prerequisites
       計算機概論
       C/C++程式設計
       資料結構
   Related Courses
       計算機結構
       系統程式
       作業系統
       嵌入式系統


                                    15
Course Info1
   Related Links
       Slides and documents
        http://www.iis.sinica.edu.tw/~cmwang/arm/
       The ARM processor
        http://www.arm.com/
       GNU software
        http://www.gnu.org/
       Open source software for handheld systems
        http://www.handhelds.org/

                                                    16
Course Info2
   PC Software
       Linux
        http://www.linux.org/
       Cygwin
        http://www.cygwin.com/
       GNU Software
        http://www.gnu.org/
       GNU ARM ToolChain
        http://www.gnuarm.com/

                                 17
Course Info3
   Reference Books
       Computer Organization and Design: The
        Hardware/Software Interface, Patterson and
        Hennessy
       System software: an introduction to systems
        programming, 3rd edition, Leland L. Beck.
       Compilers – Principles, Techniques, and Tools,
        A. V. Aho, R. Sethi, and J. D. Ullman.
       Operating System Concepts, Abraham
        Silberschatz.


                                                    18
Outline
   Basic Concepts
   Course Info
   Embedded Systems
   Programming Systems




                          19
What are embedded systems?
   Anything that uses a microprocessor but
    isn't a general-purpose computer
        PDAs                  Set-top boxes
        Televisions           Video games

        Refrigerators         Cars

        Planes                Elevators

        Remote controls       Alarm systems

   More than just a computer; it's a complete
    system

                                                 20
What is an embedded system?
   Computer purchased as part of some other
    piece of equipment
       Typically dedicated software
       Often replaces previously electromechanical
        components
       Often no “real” keyboard
       Often limited display or no general purpose
        display device
   But, every system is unique. There are
    always exceptions.

                                                      21
Why are embedded systems important?
   Engineering reasons
       Why does a satellite need a Windows prompt ?
       Does the McDonald’s POS (point-of-sale)
        terminal need MacOS?
       Any device that needs to be controlled can be
        controlled by a microprocessor




                                                   22
Why are embedded systems important?
   Market reasons
       The general-purpose computing market is in
        billions of US $
       The embedded systems market is also in
        billions of $
       ~80 Million PCs vs. ~3 Billion Embedded
        CPUs annually
            Embedded market growing; PC market mostly
             saturated
       In year 2000, about $2,700 of every car went to
        electronics

                                                         23
Why are embedded systems important?
   Pedagogical reasons
       General-purpose system designers specialize
       HW vs. SW
   Embedded system designers are often
       Jackofmanytrades
       Need to know hardware, software, and some
        combination of networking,
       control theory and signal processing
       business models

                                                      24
Embedded Systems: An Introduction
   What makes embedded systems different?
       Real-time operation
       Many sets of constraints on designs
          Size
          Cost

          Time

          Reliability

          Energy

          Safety

          Security



                                              25
An Engineer’s View: A Computer
   Measured by: performance, cost
       Compilers & OS matters




                                     26
An Embedded Computer
   Measured by: cost, I/O connections,
    memory size, performance




                                          27
An Embedded Control System
   Measured by: Cost, time to market,
    performance, functionality, dependability




                                                28
Some Embedded System Examples
   Pocket remote control RF transmitter
       100 KIPS, water/crushproof, fits in pocket, 5 year
        battery life
       Software handcrafted for small size (less than 1 KB)
   Industrial equipment controller (e.g., elevator; jet
    engine)
       1~10 MIPS for 1 to 10 CPUs, 1~8 MB memory
       Safety critical software; real time control loops
   Military signal processing (e.g., Radar/Sonar)
       1 GFLOPS, 1 GB/sec I/O, 32 MB memory
       Software handcrafted for extremely high performance

                                                               29
Categories of Embedded Systems1
   General Computing
       Applications similar to desktop computing, but
        in an embedded package
       Video games, set top boxes, wearable
        computers, automatic tellers
   Control Systems
       Closed loop feedback control of real time
        system
       Vehicle engines, chemical processes, nuclear
        power, flight control

                                                       30
Categories of Embedded Systems2
   Signal Processing
       Computations involving large data streams
       Radar, Sonar, video compression
   Communication & Networking
       Switching and information transmission
       Telephone system, Internet




                                                    31
Functions of Embedded Systems1
   Control Laws
       PID control
       Fuzzy logic, ...
   Sequencing Logic
       Finite state machines
       Switching modes between control laws
   Signal Processing
       Multimedia data compression
       Digital filtering

                                               32
Functions of Embedded Systems2
   Application Specific Interfacing
       Buttons, bells, lights,...
       High speed I/O
   Fault Response
       Detection & reconfiguration
       Diagnosis
   …



                                       33
Distinctive Attributes1
   Reactive: computations occur in response to
    external events
       Periodic events (e.g., rotating machinery and
        control loops)
       Aperiodic events (e.g., button closures)




                                                        34
Distinctive Attributes2
   Real-Time: timing correctness is part of system
    correctness
       Hard real-time
            Absolute deadline, beyond which answer is useless
            May include minimum time as well as maximum time
       Soft real-time
            Missing a deadline is not catastrophic
            Utility of answer degrades with time difference from deadline
       Example:
            a train is entering an urban area...
            the railway gate in the city allows automotive traffic to go over
             the tracks
            when should the railway gate close?
       In general, Real Time != “Real Fast”
                                                                           35
Embedded System Constraints1
   Small Size, Low Weight
       Handheld electronics
       Transportation applications weight costs money
   Low Power
       Battery power for 8+ hours (laptops often last
        only 2 hours)
       Limited cooling may limit power even if AC
        power available


                                                         36
Embedded System Constraints2
   Harsh Environment
       Heat, vibration, shock
       Power fluctuations, RF interference, lightning
       Water, corrosion, physical abuse
   Safety Critical Operation
       Must function correctly
       Must not function incorrectly
   Extreme Cost Sensitivity
       $.05 adds up over 1,000,000 units

                                                     37
 Embedded System Design View
    A complex set of tradeoffs:
         Optimize for more than just speed
         Consider more than just the computer
         Take into account more than just initial product design

Multi-Discipline             MultiPhase            MultiObjective
• Electronic Hardware        • Requirements        • Dependability
• Software                   • Design              • Affordability
• Mechanical Hardware    x   • Manufacturing   x   • Safety
• Control Algorithms         • Deployment          • Security
• Humans                     • Logistics           • Scalability
• Society/Institutions       • Retirement          • Timeliness



                                                                     38
Mission Critical Applications1
   Loss of Arianne inaugural flight in June, 1996
       Lost a $400 million scientific payload (the rocket was
        extra)
   Efforts to reduce system costs led to the failure
       Reuse of Inertial Reference System software from
        Ariane 4
       64bit float converted to 16bit int assumed not to
        overflow
       Improperly handled exception caused by variable
        overflow during
       New flight profile (that wasn't simulated because of
        cost/schedule)

                                                               39
Mission Critical Applications2
   Exception caused dual hardware shutdown
    (software doesn't fail!)
   What really happened?
       The narrow view: it was a software bug; fix it
       The broad view: the loss was caused by a lack of
        system robustness in an exceptional (unanticipated)
        situation
   Many embedded systems must be robust




                                                              40
Software Drives Designs
   Hardware is mostly a recurring cost
       Cost proportional to number of units manufactured
   Software is a “one time” nonrecurring engineering
    design cost (NRE)
       Paid for ''only once''
   But bug fixes may be expensive, or impossible
       Cost is related to complexity & number of functions
       Market pressures lead to feature creep
   Software Is NOT free!!!!!


                                                              41
Review
   What is an embedded system?
       More than just a computer it's a complete system
   What makes embedded systems different?
       Reactive and/or real-time
       Many sets of constraints on designs
   What embedded system designers need to know ?
       Multi-objective: cost, dependability, performance, etc.
       Multidiscipline: hardware, software, electromechanical,
        etc.
       Life-cycle: specification, design, prototyping,
        deployment, support, retirement


                                                            42
Outline
   Basic Concepts
   Course Info
   Embedded Systems
   Programming Systems




                          43
How a source program is executed?
#define GREETING “Hello, World!\n”
int main()
{
  printf(GREETING);
}




                                     44
Source Model vs. Real Machine
   Representation in text      Binary representation
   Arbitrary variable          All numerical
    names                        addresses
   Rules for name scope        No address scope
   Everything in memory        Hierarchical memory
   Fancy operations            Limited operations
   Model uniform across        Significant difference
    computers                    between processors



                                                      45
Approaches
             Machine Independent   Machine Dependent

Human        High-Level Languages Assembly Languages
Readable     (C, C++, Java, Pascal)




Human        Pseudo Code           Machine Languages
Unreadable   (Bytecode, P-code)    (x86, MIPS, ARM)

                                                       46
From Source to Executable
  Source Code        Object Code

  Preprocessor          Linker
                                      Libraries
Preprocessed Code   Executable Code

    Compiler            Loader

 Assembly Code
                                      Debugger
   Assembler



                                                  47
An Example Program
   C Program
/* hello.c, a simple example program */
#define GREETING “Hello, World!\n”

int main()
{
    printf(GREETING);
}




                                          48
C Preprocessor
   Preprocess the C source
       Strip out comments
       Perform textual substitution
   Preprocessor output
# 1 “hello.c”




int main()
{
    printf(“Hello, World!\n”);
}

                                       49
C Compiler
   Translate preprocessed C into assembly
        .file   "hello.c"
        .section        .rodata
.LC0:
        .string "Hello, World!\n"
        .text
        .align 2
.globl main
        .type   main,@function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        andl    $-16, %esp
        movl    $0, %eax
        subl    %eax, %esp
        subl    $12, %esp
        pushl   $.LC0
        call    printf
        addl    $16, %esp
        leave
        ret
.Lfe1:
        .size   main,.Lfe1-main
        .ident "GCC: (GNU) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)"

                                                                     50
Assembly Language
   Representation in text
   Arbitrary variable names
   Rules for name scope
   Hierarchical memory
   Operations specific to target processor
   Model dependent on target system



                                              51
Assembler
    Convert assembly into object file
     1                               .file    "hello.c"
     2                               .section         .rodata
     3                       .LC0:
     4   0000 48656C6C               .string "Hello, World!\n"
     4        6F2C2057
     4        6F726C64
     4        210A00
     5                               .text
     6                               .align 2
     7                       .globl main
     8                               .type    main,@function
     9                       main:
    10   0000   55                   pushl    %ebp
    11   0001   89E5                 movl     %esp, %ebp
    12   0003   83EC08               subl     $8, %esp
    13   0006   83E4F0               andl     $-16, %esp
    14   0009   B800000000           movl     $0, %eax
    15   000e   29C4                 subl     %eax, %esp
    16   0010   83EC0C               subl     $12, %esp
    17   0013   6800000000           pushl    $.LC0
    18   0018   E8FCFFFFFF           call     printf
    19   001d   83C410               addl     $16, %esp
    20   0020   C9                   leave
    21   0021   C3                   ret

                                                                 52
Linker
   Link the object files and libraries to form an
    executable
       Fix unresolved address (call printf)
       Put in startup code (crt0.o) that calls main
        function int main(argc,argv,envp)
       Create executable file




                                                       53
Libraries
   Startup Routine (crt0.o)
       Required as it is the first piece of user code
        executed
       Setup arguments and environment for your
        main function
   C Library (glibc)
       Required as they provide functions printf,
        open, read, close, etc.
   User Libraries

                                                         54
Loader
   Load executable file into memory for
    execution
       Allocate memory space from operating system
       Load executable file into allocated memory
       Perform the relocation of loaded program
   Bootstrap Loader
       An small program which enables the loading of
        larger, more complex programs, such as
        the boot loader for an operating system.

                                                   55
Debugger
   Allow you to see what is going on “inside”
    another program while it executes.
       Start your program, specifying anything that
        might affect its behavior.
       Make it stop on specified conditions.
       Examine what has happened, when your
        program has stopped.
       Change things in your program, so you can
        correct the effects of one bug and go on.

                                                       56
Debugging Information
   The debugger need information to map
    machine code back to original program
   Debugging information maps
       Code addresses to lines in source code
       Data addresses to variables
       Registers to variables
       Data in memory into meaningful types



                                                 57
Development Tools
   Preprocessor
   Compiler
   Assembler
   Linker
   Libraries
   Loader
   Debugger
   . . ., etc.
                    58
Why are these important?
• Where is the bug reported by compiler?
#define GREETING “Hello, World!\n”)
int main()
{
    printf(GREETING);
}



# 1 “hello.c”

int main()
{
    printf(“Hello, World!\n”));
}
                                           59
How to develop embedded software?
#define GREETING “Hello, World!\n”
int main()
{
  printf(GREETING);
}




                                     60
Cross Development
   It is usually preferred to develop software
    on faster and better host computers
   Target system and development host may
    be completely different
       Development host: PC
       Target system: PDA
   May require a different breed of tools
       Native development tools
       Cross development tools


                                                  61
Core Cross Development Tools
   Cross Compiler/Assembler/Linker/Loader
       Assembly, object and executable file formats
        might be very different from native system
   Cross Development Libraries
       Need special low level components to be
        rewritten for each different target system
   Cross Debugger
       It needs to run on both target and host
       The two halves need to communicate via RPC

                                                       62
Cross Development Tools
   Preprocessor      Archiver
   Compiler          Simulator
   Assembler         Emulator
   Linker
   Libraries
   Loader
   Debugger




                                   63
Archiver
   Archive
       A single file holding a collection of other files
        in a structure that makes it possible to retrieve
        the original individual files.
       Most often used as libraries holding commonly
        needed subroutines.
   Archiver
       A program that allows you to create, modify,
        and extract from archives.

                                                       64
Simulator
   Software tool allows designers to analyze
    the system behavior
       Examine simulated hardware events which
        cause software to take actions (e.g., interrupts)
       Devices can be modeled (e.g., DMA)
       Same software as final system
       Does not run at full (target) speed
   Good for finding software bugs


                                                        65
Emulator
   Hardware and software tools allow
    designers to analyze the system
       Normally a critical component is substituted by
        a “plug” attached to emulator
       Execute at full speed
   Good for finding hardware bugs




                                                     66

						
Related docs