Page 153 - Embedded Microprocessor Systems Real World Design
P. 153

in the HLL and then writing the functions in assembler. You can waste a lot of time
                   trying to get this to work if the vendor does not document things well.
                     Another  problem  with  microcontroller-based compilers  is  that  the  compiler
                   tends to generate code that is generic-the  code produced for a do/while  loop
                  may not take advantage of instructions that can speed up the code considerably if
                  you are ending when a variable reaches zero or something similar.
                     An example involves a design I did using a Microchip PIC device. The proces-
                   sor functions as a smart sensor, communicating with an external PLD that collects
                   time-based data. To make the PLD interface work, the processor needs one loop
                   to run very fast. The C compiler I was using simply would not generate any kind
                   of loop that terminated with a DECFSZ instruction, which decrements a memory
                   location, stores the result, and branches if the result is zero. In addition, a feature
                   of the PIC that involves a shift-and-test operation was implemented inefficiently. To
                   make matters worse, the assembly language interface for that compiler was poorly
                   documented, making the task of linking an assembly module very difficult.
                     The original code, prototyped in assembly, took less than a day to write, debug,
                   and verify. Attempting to write a C version and then to merge the original assem-
                   bly version with the final C program took three days and numerous email exchanges
                  with the technical support group at the vendor that supplied the compiler.
                     While the language is the  tool that  actually implements a design, other  tools
                   document it. Flowcharting tools simplify flowchart generation, with  linkages be-
                   tween blocks “rubberbanding” as the blocks are moved around on the page. Some
                   tools offer a complete development environment, from flowchart to finished code.


                   Debugging Tools

                  When selecting tools, give some thought to how the design will be debugged. If you
                   are developing an embedded system based on the PC architecture, you probably
                  will  get some kind of debugger with  the compiler. However, on a smaller design,
                   there are other considerations. The most severe restrictions occur when you  are
                   dealing with  microcontrollers.  For  example,  some debugger software for  micro-
                   controllers requires using the onchip serial port for communication with a host
                   PC. If your design uses the serial port to communicate with other processors in the
                   system, you must find another debugger solution.
                     Even  some emulators require  system resources  (such as serial ports)  that you
                   may need for your design. Check into this carefully before you choose your devel-
                   opment environment. Make sure you do not paint yourself into a corner.
                     Debugging systems on very small microcontrollers presents special challenges.
                   The best solution is an emulator. However, sometimes an emulator is not available
                   for  cost  reasons.  I  have  worked  on microcontroller-based  designs in  which  an
                   emulator simply would not fit in the space available or the controller board was on
                   a moving robotic arm and attaching an emulator was out of the question.


                   134                                             Embedded Micrcprocessor Systems
   148   149   150   151   152   153   154   155   156   157   158