/////////////////////////////////////////////////////////////////////// // // led module // // /////////////////////////////////////////////////////////////////////// `ifdef led_access_time // already defined - do nothing `else `define led_access_time 500ns `endif module io_leds ( LEDs, Data, RnW, nCE, nWait ); timeunit 1ns; timeprecision 100ps; output nWait; output [15:0] LEDs; inout [15:0] Data; input RnW, nCE; specify specparam tViolate=250; $width(negedge nCE, tViolate); $width(posedge nCE, tViolate); $width(negedge RnW &&& ~nCE, tViolate); $width(posedge RnW &&& ~nCE, tViolate); $setuphold(edge[10, 01] nCE, RnW, tViolate, tViolate); $setuphold(edge[01] nCE &&& ~RnW, Data, tViolate, tViolate); endspecify reg [15:0] LEDs; reg delay; integer count_writes; initial begin delay = 0; count_writes = 0; end always @(negedge nCE) begin delay = 1; #`led_access_time delay = 0; end assign nWait = (delay && !nCE && !RnW) ? 0 : 1'bz; always @(nCE or RnW) begin while ((nCE == 0) && (RnW == 0)) begin LEDs = Data; @(nCE or RnW or Data); // Detect that LED update has just completed // This prevents spurious messages as LED value settles if ((nCE != 0) || (RnW != 0)) begin $display( $time, ": LED update: %d", LEDs ); count_writes = count_writes + 1; `ifdef max_led_writes if ( count_writes == `max_led_writes ) begin $display("Terminating after %d LED writes\n", `max_led_writes); #2000ns $stop; $finish; end `endif end end end endmodule