top.v 1.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
module decode1_1(input clk,
		 input 	       rst,
		 input [31:0]  in_count,
		 input 	       in_valid,
		 output        in_ready,

		 input 	       out_ready,
		 output        out_valid);

   reg [31:0] 		       r_remaining_count;
   reg 			       r_valid;
   reg 			       r_ready;

   assign out_valid = r_valid;
   assign in_ready = r_ready;

   always @(posedge clk) begin
      if (rst) begin
	 r_remaining_count <= 0;
	 r_valid <= 0;
	 r_ready <= 0;
      end else begin
	 if (r_remaining_count == 0) begin
	    if (r_ready && in_valid) begin
	       r_remaining_count <= in_count;
	       r_valid <= in_count != 0;
	       r_ready <= 0;
	    end else begin
	       r_ready <= 1;
	       r_valid <= 0;
	    end
	 end else begin
	    r_valid <= !(r_remaining_count == 1 && out_ready && out_valid);
	    r_ready <= 0;

	    if (out_valid && out_ready) begin
	       r_remaining_count <= r_remaining_count - 1;
	    end
	 end
      end
   end

endmodule // decode1_1

module top(input clk);
   wire        out_valid;
   wire [31:0] out_data;
   wire        out_ready = 1'b1;

   reg [31:0]  cycles;
   wire        rst = (cycles < 3);

   wire        in_ready;

   reg [31:0]  test_counts [0:1];
   reg [31:0]  test_index;
   wire        in_valid = (test_index < 1) && (cycles > 2);

   reg [9:0]   out_data_index;

   always @(posedge clk)
     begin
	cycles <= cycles + 1;
     end

   always @(posedge clk)
     begin
	if (cycles < 1) begin
	   test_counts[cycles] <= $anyseq;
	end
     end

   initial begin
      cycles  = 0;

      test_index = 0;
   end

   decode1_1 decoder(clk, rst,
		 test_counts[test_index],
		 in_valid,
		 in_ready,

		 out_ready,
		 out_valid);

   always @(posedge clk) begin
      if (!rst) begin
	 assert(out_data_index <= 0);

	 if (in_valid && in_ready) begin
	    test_index <= test_index + 1;
	 end
	 if (out_ready && out_valid) begin
	    out_data_index <= out_data_index + 1;
	 end
      end
   end // always @ (posedge clk)
endmodule