HOME       UP       PREV       FURTHER NOTES       NEXT (Keyboard Controller (scan multiplexed type).)  

GPIO - General Purpose Input/Output Pins

  reg [31:0] ddr;    // Data direction reg
  reg [31:0] pins_r; // regsiter'd pin data
  reg [31:0] dout;   // output regsiter
  reg [31:0] imask;  // interrupt mask 
  reg [31:0] ipol;   // interrupt polarities

reg int_enable, // output register always @(posedge clk) begin pins_r <= pins; if (hwen && addr==0) ddr <= wdata; if (hwen && addr==4) dout <= wdata; if (hwen && addr==8) imask <= wdata; if (hwen && addr==12) ipol <= wdata; if (hwen && addr==16) int_enable <= wdata[0]; end

bufif b0 (pins[0], dout[0], ddr[0]); // Tri-state buffers. .. // thirty others here bufif b31 (pins[31], dout[31], ddr[31]); wire int_pending = (|((din ^ ipol) & imask)); assign rdata = pins_r; assign interrupt = int_pending && int_enable;

Micro-controllers have a large number of GPIO pins.

Exercise: Show how to wire up a push button and write a device driver that counts how many times it is/was pressed.

(C) 2008-10, DJ Greaves, University of Cambridge, Computer Laboratory.