CSE 477 Midterm Exam Solution (3 Nov 1999)


1. Microcontrollers and their I/O Devices (25 points)

Describe how you would design a new peripheral for the SA-1100 microcontroller that would directly handle the interface to a sonar module like the one you used in laboratory assignments 2 and 3.  The peripheral will be memory-mapped to the microcontroller's memory space and will have two external pins to connect it to the sonar module (INIT and ECHO).

a) What registers will provide the interface between the microcontroller and the sonar?  Describe the purpose of each in detail and include the minimum width of each register (i.e., 32-bit word, 1 bit, etc.).

 

 

  1. 1-bit register to start sonar:

  2. writing a 1 causes INIT to be raised and the sonar unit to wait for an echo 
  3. 1-bit register to enable sonar interrupt: 

  4. allows sonar unit to interrupt processor if set to one 
  5. 1-bit register for sonar interrupt bit: 

  6. when echo returns this bit goes high and an interrupt (if enabled) is signalled 
  7. 1-bit register to clear sonar interrupt: 

  8. a one written here clears the interrupt bit 
  9. 32-bit register to hold sonar distance: 

  10. distance in meters from the time the start bit is written to detecting echo
 
 
b) What will be the internal components of such a device controller and how are they interconnected?  Draw a block diagram of the main components (i.e., registers, counters/timers, comparators, etc.) and their interconnection and explain their operation for a basic scenario of generating a pulse and determining the time until an echo is detected.  You should have the microcontroller registers on one side and the microcontroller pins on the other with the components required in between.
 

 

 

 
    1. Setup sonar interrupt routine
    2. Set sonar intr enable 
    3. Set sonar start
    4. Sonar unit sets INIT, clears counter, enables counter, waits for ECHO
    5. When echo arrives, sonar intr is set, converted count is placed in sonar distance register
    6. SA1100 detects interrupt and start sonar interrupt service routine
    7. Sonar interrupt routine uses sonar distance and eventually clears sonar intr
 
 

2. Communication and Interfacing (35 points)
 
Your microcontroller needs to communicate with an I2C-compatible device but does not have built-in I2C support and there is no room to add an external I2C interface controller chip. Your only alternative is to emulate the protocol in software and use the I/O ports of your microcontroller to connect to the two I2C signal lines. Because your microcontroller does not have open-collector output pins, you will have to use two open-collector non-inverting buffers to make the electrical connection to the bus (the lines SDA and SCL) as shown in the figure below.

 

Sketch a routine (in pseudo-code) that sends out an 8 bit character over the I2C lines. You can assume that your microcontroller is the only possible initiator on the bus so that you do not need to consider arbitration. However, you must consider the effects of a slow receiving device on the SCL line. The figures below provide a reminder of the signalling convention used by the I2C bus. Make sure to consider a complete transmission including start bit, 8 bits of data, acknowledgement from the receiver, and stop bit.
 
 

 

 

  1. raise SDA (ensure not driving SDA low)
  2. raise SCL (ensure not driving SCL low)
  3. wait until both SCL ==1 and SDA==1 for minimum time (make sure no one else using channel)
  4. lower SDA (signal the start of a byte transmission)
  5. lower SCL (to get ready to start the data stream)
  6. do 8 times
  7.     get next bit
  8.     set SDA to that value
  9.     set SCL to high
  10.     wait until SCL really goes high (receiver may be holding it low)
  11.     lower SCL
  12. end loop
  13. set SDA high
  14. set SCL high
  15. wait until SCL really goes high (receiver may be holding it low)
  16. check that SDA is low (acknowledge from receiver)
  17. if SDA is not low, then error
  18. lower SDA (to hold it low even if receiver lets it rise)
  19. lower SCL
  20. raise SCL
  21. raise SDA (to signal end of transaction)

 


3. Pilot Programming (40 points)
 
You are to design a wireless messaging system for the Palm Pilot. The Pilot application will continuously poll its IrDA port, listening for message servers. When a message server is discovered, the Pilot application should download new message headers for the appropriate user. Headers for messages that have already been read should not be sent. Subject lines from the message headers are displayed as shown in Form 1. When a user clicks on a message, the Pilot downloads the body of that message from the server and displays the contents as shown in Form 2 for the first message.
 

 
Form 1                                                                          Form 2
 

a) Describe the various messages and packet formats that will be used in your communication protocol.  Begin by describing the messages received by the Pilot from the server and then describing those sent by the Pilot to the server.
 

 

Server -> Pilot Messages
  • HELLO HEARTBEAT  // lets the server announce its presence periodically
  • RECV HEADERS <user> <data> <checksum>  // server sends headers to pilot
  • RECV MESSAGE <message-id> <data> <checksum>  // server sends message to pilot
Pilot -> Server Messages
  • GET HEADERS <user>  // pilot asks for the headers for a particular user
  • GET MESSAGE <message-id>  // pilot asks for a specific message 
                              // all message ids are unique across users
  • READ MESSAGE <message-id>  //pilot informs server it read a message
  

b) How does your protocol handle an interrupted transmission (i.e., if an object blocks the IrDA port while sending or receiving a message)? Discuss what happens if each type of packet you listed above is either lost or corrupted.
 

 

We don't need to worry about interrupted HELLO packets since they are constantly retransmitted. A timeout mechanism will discover if GET packets were blocked. A corrupted GET packet will simply be ignored, causing the Pilot to timeout and retransmit. READ packets that are interrupted will simply cause a header to be resent that didn't need to be.  Corrupted RECV packets are identified by a checksum. If the entire RECV packet is blocked, the Pilot will assume that the GET message failed to arrive and retransmit the request. 
 
 

c) Is there any reason to limit packet size?
 

 

You might want to limit packet size to reduce the cost of error handling. For example, if the data portion of RECV packets were split into smaller packets, then only those packets which were corrupted would need to be retransmitted (as opposed to retransmitting the entire message). 
 
 

d) What will the Pilot have to do in its event loop? Describe the operations that need to be performed each time around the loop. Consider both communication and user interface events.
 

 

Each time around the event loop, the Pilot will:

  1. check for an HELLO message from a server and log it if it finds it
  2. check for RECV HEADERS messages and update the display and internal data structures for message list
  3. check for RECV MESSAGE message, send READ MESSAGE message, and update display and internal data structure for message text received
  4. check for user asking for message list and sending out a GET HEADERS message
  5. check for user asking for a particular message and sending out a GET MESSAGE message
 


Comments to: cse477-webmaster@cs.washington.edu (Last Update: )