compilers programming embedded

Upload: chandan-bose

Post on 06-Apr-2018

250 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Compilers Programming Embedded

    1/16

    Compilers, assemblers,Compilers, assemblers,

    linkers, loaders, andlinkers, loaders, and

    programming issuesprogramming issues

    For embedded SystemsFor embedded SystemsChris GreggChris Gregg

    January 29, 2009January 29, 2009

  • 8/3/2019 Compilers Programming Embedded

    2/16

    is programming for anis programming for an

    embedded system different?embedded system different?

    SpeedSpeed

    SizeSize

    CorrectnessCorrectness

    PortabilityPortability

    RealReal--Time or notTime or not

    Other Hardware ConsiderationsOther Hardware Considerations

  • 8/3/2019 Compilers Programming Embedded

    3/16

    How does one actuallyHow does one actually

    program an embedded system?program an embedded system?

    Has this changed over the years? Has there been significantHas this changed over the years? Has there been significantprogress?progress?

    How does Ford program their Fuel Injection System computer?How does Ford program their Fuel Injection System computer?

    How does GE program their Microwave Ovens (and was thisHow does GE program their Microwave Ovens (and was thisdifferent 30 years ago?)different 30 years ago?)

    How does Nikon program their digital SLRcameras?How does Nikon program their digital SLRcameras?

    How does Apple/RIM/Microsoft program theirHow does Apple/RIM/Microsoft program theiriPhone/Blackberry/SmartPhone?iPhone/Blackberry/SmartPhone?

    How does a hobbyist program a Pic microprocessor?How does a hobbyist program a Pic microprocessor?

    How does NASA program (andHow does NASA program (and reprogramreprogram) the Mars Rover?) the Mars Rover?

    How did James Gosling at Sun want his setHow did James Gosling at Sun want his set--top boxestop boxesprogrammed?programmed?

    (How was the original 128K Macintosh programmed?)(How was the original 128K Macintosh programmed?)

  • 8/3/2019 Compilers Programming Embedded

    4/16

    ProgrammingProgramming

    LanguagesLanguages

    Machine Code

    Assembly

    Code

    HigherLevel

    Languages

    Fixed Rom, Ram,

    Firmware

    Compiled

    C, nesC, C++,

    Ada, Forth, etc.

    Interpreted (?)

    Perl, Python,

    Javascript

    Markup

    HTML, XML

    JavaAll Eventually End up

    as Machine Code

  • 8/3/2019 Compilers Programming Embedded

    5/16

    So youve chosen C.So youve chosen C.

    Lets Go!Lets Go!

    What does a programmer need to know aboutWhat does a programmer need to know aboutprogramming for an embedded system?programming for an embedded system?

    Shed better know about the hardware.Shed better know about the hardware. PurposePurpose

    How data flows (to include getting the program onto theHow data flows (to include getting the program onto thesystem, I/O), how to interface with sensors, actuators,system, I/O), how to interface with sensors, actuators,etc.etc.

    Whether there is an operating system, and how it runsWhether there is an operating system, and how it runsprogramsprograms

    Limitations: memory, speed, upgradability (firmware?)Limitations: memory, speed, upgradability (firmware?)

    How are hardware errors handled? (think Mars Rover)How are hardware errors handled? (think Mars Rover)

    Plan on debugging hardware issuesPlan on debugging hardware issues

    (Not so fast.)

  • 8/3/2019 Compilers Programming Embedded

    6/16

    So youve chosen C.So youve chosen C.

    Lets Go!Lets Go!

    What does a programmer need to know about programmingWhat does a programmer need to know about programmingfor an embedded system?for an embedded system?

    Shed better know about the software tools related toShed better know about the software tools related toprogramming for the specific hardware.programming for the specific hardware.

    Is there a compiler/linker/assembler? (hopefully!)Is there a compiler/linker/assembler? (hopefully!)

    How is the memory addressed, what bitHow is the memory addressed, what bit--level knowledge of thelevel knowledge of thehardware is necessary, how does one access pins, etc.?hardware is necessary, how does one access pins, etc.?

    How will debugging be managed?How will debugging be managed?

    How will testing be done?How will testing be done?

    What licensing needs to be organized (this can be tricky!)What licensing needs to be organized (this can be tricky!)

    Does the software need to be portable? (using C isDoes the software need to be portable? (using C isprobablyprobably

    going to help yougoing to help yousee the second point above).see the second point above).

    (Not so fast.)

  • 8/3/2019 Compilers Programming Embedded

    7/16

    The Embedded SoftwareThe Embedded Software

    Development ProcessDevelopment Process

    Barr, M. & Massa, A. Oram, A. (ed.)Programming Embedded Systemsin C and C++, 2nd Edition. O'Reilly & Associates, Inc., 2006 , p.55

  • 8/3/2019 Compilers Programming Embedded

    8/16

    The ToolsThe Tools

    Compiler: Translates human readable code into assemblyCompiler: Translates human readable code into assembly

    language or opcodes for a particularprocessor (orpossiblylanguage or opcodes for a particularprocessor (orpossibly

    into machineinto machine--independent opcodes a la Java). Produces anindependent opcodes a la Java). Produces an

    object file.object file.

    Assembler: Translates assembly language into opcodes (it isAssembler: Translates assembly language into opcodes (it is

    really a compiler, too). Also produces an object file.really a compiler, too). Also produces an object file.

    Linker: Organizes the object files, necessary libraries, andLinker: Organizes the object files, necessary libraries, and

    other data and produces a relocatable file.other data and produces a relocatable file.

    Locator: Takes the relocatable file and information aboutLocator: Takes the relocatable file and information about

    the memory of the system and produces an executable.the memory of the system and produces an executable.

    (By the way: gcc takes care of(By the way: gcc takes care of allallof these functions at once)of these functions at once)

  • 8/3/2019 Compilers Programming Embedded

    9/16

    The Tools: EmbeddedThe Tools: Embedded

    System SpecificsSystem SpecificsAll of the tools run on the host computer, not the embedded computer.All of the tools run on the host computer, not the embedded computer.

    Compiler: Has to know about the specific hardware (except in veryCompiler: Has to know about the specific hardware (except in verytrivial cases). Should be able to optimize for size.trivial cases). Should be able to optimize for size.

    Assembler: Produces startup code; not inserted automatically as inAssembler: Produces startup code; not inserted automatically as ingeneral purpose computers (i.e., the programmer needs to compile itgeneral purpose computers (i.e., the programmer needs to compile itindependently).independently).

    Linker: Needs the correct libraries (open source c libraries, such asLinker: Needs the correct libraries (open source c libraries, such as

    newlibnewlib, are available)., are available).

    Locator: Needs programmer input for information about memory.Locator: Needs programmer input for information about memory.

    Bottom Line: There can be a lot of extra work for the programmer,

    although certain systems (e.g. Pic programming) tools can automate most

    of it.

  • 8/3/2019 Compilers Programming Embedded

    10/16

    Moving the program ontoMoving the program onto

    the embedded systemthe embedded system

    Remember, the program is written (and possibly run inRemember, the program is written (and possibly run in

    an emulator) on a host computer, but it still needs toan emulator) on a host computer, but it still needs to

    get onto the embedded system.get onto the embedded system.

    Methods:Methods:

    Build/burn the program into the hardware (firmware orBuild/burn the program into the hardware (firmware or

    other flash memory)other flash memory)

    Bootloader: a bootloader resides on the embedded systemBootloader: a bootloader resides on the embedded system

    and facilitates loading programs onto the system.and facilitates loading programs onto the system.

    Debug Monitor: The debug monitor is a more robustDebug Monitor: The debug monitor is a more robust

    program on an embedded system that helps withprogram on an embedded system that helps with

    debugging and other chores, and can include a bootloaderdebugging and other chores, and can include a bootloader

    as well.as well.

  • 8/3/2019 Compilers Programming Embedded

    11/16

    DebuggingDebugging

    Debugging embedded systems can be facilitated with aDebugging embedded systems can be facilitated with aDebug Monitor, or through a remote debugger on the hostDebug Monitor, or through a remote debugger on the hostcomputer. A serial link is normally set up, and the debuggercomputer. A serial link is normally set up, and the debuggeracts more or less like a general purpose debugger.acts more or less like a general purpose debugger.

    Emulators can be used to test the system without utilizingEmulators can be used to test the system without utilizingthe actual hardware (but this has many caveats, and nothingthe actual hardware (but this has many caveats, and nothingbeats testing on the real system).beats testing on the real system).

    Software Simulators allow the programmer to debugSoftware Simulators allow the programmer to debugcom

    pletely on the host system, which can be quicker andcom

    pletely on the host system, which can be quicker and

    can allow faster code turnaround.can allow faster code turnaround.

    When it comes down to it, an oscilloscope and a multimeterWhen it comes down to it, an oscilloscope and a multimetercan be your best friend for debugging.can be your best friend for debugging.

  • 8/3/2019 Compilers Programming Embedded

    12/16

    Final ThoughtsFinal Thoughts

    Programming for embedded systems has come a longProgramming for embedded systems has come a long

    way since the days of toggle switches, but it stillway since the days of toggle switches, but it still

    involves greaterprogrammer involvement in theinvolves greaterprogrammer involvement in the

    hardware aspect of the system.hardware aspect of the system.

    There are many software tools built for embeddedThere are many software tools built for embedded

    systems, and many embedded system hardwaresystems, and many embedded system hardware

    designers include debugging tools with the hardware.designers include debugging tools with the hardware.

    You had probably learn C (and a fair amount ofYou had probably learn C (and a fair amount of

    assembly) to program embedded systems.assembly) to program embedded systems.

  • 8/3/2019 Compilers Programming Embedded

    13/16

    Final ThoughtsFinal Thoughts

    Is this a necessary topic for an Embedded SystemsIs this a necessary topic for an Embedded Systems

    class?class?

    YesYes Youve got to get yourprogram onto the system someYouve got to get yourprogram onto the system some

    how, and flipping toggle switches doesnt put food on thehow, and flipping toggle switches doesnt put food on the

    table any more.table any more.

    Hardware only does what you tell it to, via software.Hardware only does what you tell it to, via software.

    Discussion of the tradeoffs necessary to program anDiscussion of the tradeoffs necessary to program an

    embedded system versus a GP system is a necessity.embedded system versus a GP system is a necessity.

  • 8/3/2019 Compilers Programming Embedded

    14/16

    6 Questions6 Questions

    1)1) Discuss the steps needed to get a program fromDiscuss the steps needed to get a program from

    source code to executable in an embedded system,source code to executable in an embedded system,

    and the differences between similar steps on a generaland the differences between similar steps on a general

    purpose system.purpose system.

    2)2) What tradeWhat trade--offs are necessary when thinking aboutoffs are necessary when thinking about

    how you are going to program for an embeddedhow you are going to program for an embedded

    system?system?

    3)3) Why is C generally considered a better language toWhy is C generally considered a better language to

    program in for embedded systems than, say, Java orprogram in for embedded systems than, say, Java or

    Perl?Perl?

  • 8/3/2019 Compilers Programming Embedded

    15/16

    6 Questions6 Questions

    4)4) Name three different ways you might debug the codeName three different ways you might debug the code

    for your embedded system.for your embedded system.

    5)5) Why is it imperative that an embedded systemWhy is it imperative that an embedded systemprogrammer know the details of the hardware thatprogrammer know the details of the hardware that

    she is programming for? Compare this to someoneshe is programming for? Compare this to someone

    writing a Java applet for a web site.writing a Java applet for a web site.

    6)6) Talk about the role firmware plays in developingTalk about the role firmware plays in developingsoftware for an embedded system.software for an embedded system.

  • 8/3/2019 Compilers Programming Embedded

    16/16

    BibliographyBibliography

    Barr, M. & Massa, A. Oram, A.Barr, M. & Massa, A. Oram, A. (ed.)(ed.)Programming Embedded Systems in C and C++, 2ndProgramming Embedded Systems in C and C++, 2ndEdition.Edition. O'Reilly & Associates, Inc.,O'Reilly & Associates, Inc., 20062006

    Wolfe, M. How compilers and tools differ for embeddedWolfe, M. How compilers and tools differ for embeddedsystems.systems. 20052005..http://www.pgroup.com/lit/pgi_article_cases.pdfhttp://www.pgroup.com/lit/pgi_article_cases.pdf

    Gay, D.; Levis, P.; von Behren, R.; Welsh, M.; Brewer, E. &Gay, D.; Levis, P.; von Behren, R.; Welsh, M.; Brewer, E. &Culler, D. The nesC language: A holistic approach toCuller, D. The nesC language: A holistic approach tonetworked embedded systemsnetworked embedded systemsSIGPLAN Not., ACM,SIGPLAN Not., ACM, 20032003, 38, 38, 1, 1--1111

    Williams, B.; Ingham, M.; Chung, S. & Elliott, P.Williams, B.; Ingham, M.; Chung, S. & Elliott, P.ModelModel--based programming of intelligent embedded systemsbased programming of intelligent embedded systemsand robotic space explorersand robotic space explorers

    Proceedings of the IEEE,Proceedings of the IEEE, 20032003, 91, 91, 212, 212--237237