Es Module 2 Notes PDF

Embed Size (px)

DESCRIPTION

es notes

Citation preview

  • MODULE 2

  • Hardware Architecture for Embedded systems

    An embedded system is built around a processor. The central processing unit does the

    necessary computation based on the input it receives from various external devices. The

    functionality of the CPU is an embedded system is same as the functionality of the CPU in a

    desktop, except that the CPU in an embedded system is less powerful. The processor has limited

    internal memory, and if this internal memory is not sufficient for a given application external

    memory devices are used. The hardware also includes any components that facilitates the user-

    application interaction, such as display units, keypads etc.

  • Processor

    The processor used in embedded systems can be of three types:

    Micro-Controllers

    Microprocessors

    Digital Signal Processor

    Each of them is specified by clock speed( 100MHz, etc) and data word length( 8-bit, 16-bit, 32-

    bit). The higher the clock speed, the faster the processor. Same way, bigger data word-length

    leads to higher precision. The word length also indicates the processor's capability to address the

    memory. This addressing capability is specified by the number of bits used for addressing. For

    instance, an 8-bit processor can be use 8 or 16-bit for addressing.

    Micro-controller

    Micro-controllers are mainly of Intel's 805x family, Motorola's 68HCxx, etc. A typical micro-

    controller contains a CPU, interrupts, timer/counter, memory (RAM, ROM, or both) and other

    peripherals in same Integrated Circuit(IC). Micro-controller are often an ideal solution for control

    applications because you can use them to build an embedded system with little additional

    circuitry. The 8-bit micro-controllers are used for process control applications, such as the ones

    found in toys and smart cards. If your processing power and memory requirements are high, you

    need to choose a 16-bit or 32-bit processor.

  • High level language programming makes the program development cycle short, enables

    use of the modular programming approach and lets us follow sound software engineering

    principles. It facilitates the program development with Bottom up design and top down

    design approaches. Embedded system programmers have long preferred C for the following

    reasons: (i) The feature of embedding assembly codes using in-line assembly. (ii) Readily

    available modules in C compilers for the embedded system and library codes that can directly

    port into the system-programmer codes.

  • ADVANTAGES OF EMBEDDED C IN THE PROGRAMMING

    Programming in C makes the Embedded systems more reliable. C code written for a specific

    micro controller can easily be transferred to systems using different micro controllers of

    different vendors without little or no modification. It can be reused, easy to maintain and easy

    to debug and extend. The advantages of C as shown in the following

    Of higher level languages, C is the closest to assembly languages.

    Most micro controllers have available C compilers.

    Writing in C simplifies code development for large projects.

    It is easier and less time consuming to write in C language than assembly.

    C is easier to modify and update.

    We can use code available in function libraries.

    C code is portable to other micro controllers with little or no change.

    Assembly is the fastest, however, it is difficult to find or train assembly experts. Then if a

    new processor is required, we have to start over!

    C is mid-level, lots of good C programmers are available, C compilers are available. C can

    be used on 8-, 16-, 32-, and 64-bits processors.

    Advantage of using C for Programming

    Procedure oriented language (Noobjects)

    Provision of inserting the assemblylanguage codes in between (called inlineassembly) to

    obtain a direct

    hardware control.

    A large program in C splits into thedeclarations for variables, functions anddata structure,

    simpler unctional blocksand statementsProcessor and memory sensitivepart of the program

    within the inline

    assembly, and the complexpart in the HLL codes.

    Example function outportb (q, p)

    Example Mov al, p; out q, al

  • Advantages of embedded c

    It is a mid-level, with high-level features (such as support for functions and

    modules), and low-level features (such as good access to hardware via pointers)

    C is the most common Embedded language 85%, of embedded applications are

    coded in C.

    C , when used correctly is as safe and robust as any other high level language.

    It directly manipulates the hardware and memory addresses.

    It is very efficient, It is popular and well understood

    Good, well proven compilers are available for every embedded processor(8-bit to

    32-bit or more)

    Cx51 Cross compiler supports all of the ANSI Standard C directives.

    Code optimisation

    Code-optimization techniques include the following:

    To minimize the code working set of a program, pack frequently executed code

    together, while separating infrequently used code. In other words, do not put long

    blocks of error handling code in line and load frequently called modules next to their

    callers.

    To minimize the data working set, concentrate frequently used data together and avoid

    unnecessary references to pages. This can be accomplished by using the malloc()

    subroutine instead of the calloc() subroutine, initializing data structures immediately

    before they are used and being sure to free and disclaim allocated space when no

    longer needed.

    To minimize pinned storage, package pinned code in separate load modules. Make

    sure it is necessary to use pinned code. Certain system structures (such as mbuf

    pools) are pinned in memory; do not arbitrarily increase them.

    Real-time techniques can be used, such as the plock() subroutine to pin code in

    memory, and priorities pinned with the setpri() subroutine

    Techniques

    o Constant propagation

    o Constant folding

    o Algebraic simplification, strength reduction

  • o Copy propagation

    o Common subexpression elimination

    o Unreacheable code elimination

    o Dead code elimination

    o Loop Optimization

    o Function related

    Branch optimization Rearranges the program code to minimize branching logic and to combine physically

    separate blocks of code. Code motion If variables used in a computation within a loop are not altered within the loop, the

    calculation can be performed outside of the loop and the results used within the loop. Common subexpression elimination In common expressions, the same value is recalculated in a subsequent expression.

    The duplicate expression can be eliminated by using the previous value. Constant propagation Constants used in an expression are combined, and new ones are generated. Some

    implicit conversions between integers and floating-point types are done. Dead code elimination Eliminates code that cannot be reached or where the results are not subsequently

    used. Dead store elimination Eliminates stores when the value stored is never referenced again. For example, if two

    stores to the same location have no intervening load, the first store is unnecessary and is removed.

    Global register allocation Allocates variables and expressions to available hardware registers using a "graph

    coloring" algorithm. Inlining Replaces function calls with actual program code Instruction scheduling Reorders instructions to minimize execution time Interprocedural analysis Uncovers relationships across function calls, and eliminates loads, stores, and

    computations that cannot be eliminated with more straightforward optimizations. Invariant IF code floating (Unswitching) Removes invariant branching code from loops to make more opportunity for other

    optimizations. Reassociation Rearranges the sequence of calculations in an array subscript expression, producing

    more candidates for common expression elimination.

  • Store motion Moves store instructions out of loops. Strength Reduction Replaces less efficient instructions with more efficient ones. For example, in array

    subscripting, an add instruction replaces a multiply instruction. Value numbering Involves constant propagation, expression elimination, and folding of several

    instructions into a single instruction.

    Assembly vs highlevel languages

    HLL (High Level Language) programs are machine independent. They are easy to learn,

    easy to use, and convenient for managing complex tasks.

    Assembly language programs are machine specific. It is the language that the processor

    directly understands

    Advantage of Assembly Language Programming

    _ Assembly codes sensitive to the processor,memory, ports and devices hardware

    _ Gives a precise control of the processor internal devices

    _ Enables full use of processor specific features in its instruction set and its addressing

    modes

    _ Machine codes are compact, processor and memory sensitive

    _ System needs a smaller memory.

    _ Memory needed does not depend on the programmer data type selection and

    ruledeclarations

    _ Not the compiler specific and library functions Specific Device driver codes may need only

    a few assembly instructions.

    _ Bottom-up-design approach

    Advantage of using high levellanguage (HLL) for Programming Short Development

    Cycle

    Code reusability A function or routine can be repeatedly used in a program

    Standard library functions For examples, the mathematical functions and delay ( ), wait ( ),

    sleep ( ) functions

    Use of the modular building blocks Sub-modules are designed first for specific and distinct

    set of actions,

    then the modules and finally integration into complete design. First code the basic functional

    modules and then build a bigger module and then integrate into the final system First design

    of main program (blueprint),

    then its modules and finally the sub-modules are designed for specific and distinct set of

    actions.

  • Top-down design Most favoured program design approach

    Examples, char, int, unsigned short, long, float, double, Boolean.

    Each data type provides an abstraction of the (i) methods to use, manipulate and represent,

    and (ii) set

    of permissible operations.Type checking during compilation makes the program less prone

    toerrors.

    Example type checking on a chardata type variable (a character) doesnot permit

    subtraction, multiplication and division.Control Structures and loops

    Examples while, do-while, breakand for

    Conditional Statements examples

    if, if- else, else - if and switch - case)

    Makes tasks simple for the programflowDesignData structure- A way of organizing large

    amounts of data.

    _ A data elements collection

    _ Data element in a structure identifiedand accessed with the help of a fewpointers and/or

    indices and/or functions

    C PROGRAM ELEMENTS

    Pre-processor include Directive

    Header, configuration and other available source files are made the part of an embedded

    system program source file by this directive

    Examples of Pre-processor include Directives

    Pre-processor Directive for the definitions

    Global Variables # define volatile boolean IntrEnable

    Constants # define false 0

    # include vxWorks.h /* Include VxWorks functions*/ # include semLib.h /* Include Semaphore functions Library */ # include taskLib.h /* Include multitasking functions Library */ # include msgQLib.h /* Include Message Queue functions Library */ # include fioLib.h /* Include File-Device Input-Output functions Library */ # include sysLib.c /* Include system library for system functions */ # include netDrvConfig.txt /* Include a text file that provides the Network Driver Configuration. It provides the frame format protocol (SLIP or PPP or Ethernet) description, card description/make, address at the system, IP address (s) of the node (s) that drive the card for transmitting or receiving from the network. */# include prctl Handlers.c /* Include file for the codes for handling and actions as per the protocols used for driving streams to the network. */

  • Strings # define welcome msg

    "Welcome To ABC Telecom

    Preprocessor Macros

    Macro - A named collection of codes that is defined in a program as pre processor directive.

    Differs from a function in the sense that once a macro is defined by a name, the compiler

    puts the corresponding codes at the macro at every place where that macro-name appears.

    Difference between Macro and Function

    The codes for a function compiled once only

    On calling that function, the processor has to save the context, and on return restore the

    context.

    Macros are used for short codes only. When a function call is used instead of macro, the

    overheads (context saving and return) will take a time, Overheads that is the same order of

    magnitude as the time, Texec for execution of short codes within a function.

    Use the function when the Toverheads