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

time you  have moving objects detected by  sensors, you  run the risk of  unstable
                 output.


                 Bus Width
                 Sometimes an 8-bit device is connected to a 16, 32-, or 64bit processor. As I men-
                 tioned in  Chapter  2, an example would be a  16550 UART connected  to an x86
                 processor. In most cases, the hardware is not designed to decode all the possible
                 accesses to the device, so the software must not try to perform writes that are wider
                 than the device. In some cases, this is no problem, as the unused bits will be dis-
                 carded. However, if the hardware is designed so that the other bits write to a control
                 register, you  can  get  unexpected  results. For  instance,  if  a  device is  located  at
                 address 03F0  (hex), and the lower 8 bits are connected  to  a data register while
                 the upper 8 bits are connected to a status register, a word write will change both
                 registers. Another case in which this can cause problems is on a read: If you read
                 a  ltkbit word  from  the  %bit device,  the  unused  bits  usually will  be  undefined
                 because those bits are floating. If you do not mask them off in software, the results
                 are indeterminate.




                 Software Architecture


                 There are only so many ways to connect a flash memory to a processor, but there
                 are numerous ways to implement almost any software function. However, embed-
                 ded software usually is built on only a few architectural frameworks, as described
                 in this section.


                 Single Polling Loop
                 In  this method, a  single piece  of  polling code  loops continuously, checking for
                 input  from  interrupt  routines  and  external  devices  (such  as a  keypad)  and
                 executing whatever subroutines are necessary to implement the functionality. This
                 method of coding assumes that all functions are available all the time. For example,
                 it might check all the key switches all the time, even if some switches are not used
                 in particular  modes. This was  the method that I used to implement the protocol
                 converter described earlier. That design did not even have any interrupts-every-
                 thing was done in the polling loop.

                 State Machine

                 The software is  in  one state at a time.  Only those functions that  pertain  to  the
                 current state are monitored. I designed a burglar alarm this way once. The system


                 Software Design                                                      129
   143   144   145   146   147   148   149   150   151   152   153