Table Of Contents
Previous Section Next Section

Program 106: Taking Out the Trash

We have a memory-mapped input port pointed to by in_port_ptr. The device can buffer up to three characters. In order to initialize the device, we need to empty the buffer and clear out any old garbage. That's what this function is supposed to do. But sometimes it doesn't work. Why?

  1 /***********************************************
  2  * clear port -- Clear the input port.         *
  3  ***********************************************/
  4 // Input register
  5 char *in_port_ptr  = (char *)0xFFFFFFE0;
  6
  7 // Output register
  8 char *out_port_ptr = (char *)0xFFFFFFE1;
  9
 10 /***********************************************
 11  * clear_input -- Clear the input device by    *
 12  *      reading enough characters to empty the *
 13  *      buffer. (It doesn't matter if we read  *
 14  *      extra, just so long as we read enough.)*
 15  ***********************************************/
 16 void clear_input(void)
 17 {
 18     char ch;    // Dummy character
 19
 20     ch = *in_port_ptr;  // Grab data
 21     ch = *in_port_ptr;  // Grab data
 22     ch = *in_port_ptr;  // Grab data
 23 }

(Next Hint 129. Answer 9.)

Table Of Contents
Previous Section Next Section