stimulus_atomic_bank.v 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. `timescale 1ns/1ps
  2. // Identification-only 32-channel stimulus storage. Host writes always stage
  3. // into the inactive bank; a commit changes the active vector only after every
  4. // address has received an in-range value.
  5. module stimulus_atomic_bank (
  6. input wire clk,
  7. input wire rst_n,
  8. input wire write_enable,
  9. input wire [4:0] write_address,
  10. input wire [7:0] write_data,
  11. input wire stimulus_commit,
  12. output wire commit_applied,
  13. output reg active_bank,
  14. input wire read_bank,
  15. input wire [4:0] read_address,
  16. output wire [7:0] read_data
  17. );
  18. reg [7:0] bank0 [0:31];
  19. reg [7:0] bank1 [0:31];
  20. reg [31:0] inactive_written;
  21. wire accepted_write = write_enable && write_data <= 100;
  22. assign commit_applied = stimulus_commit && (&inactive_written);
  23. assign read_data = read_bank ? bank1[read_address] : bank0[read_address];
  24. always @(posedge clk or negedge rst_n) begin
  25. if (!rst_n) begin
  26. active_bank <= 1'b0;
  27. inactive_written <= 32'd0;
  28. end else begin
  29. if (accepted_write) begin
  30. if (active_bank)
  31. bank0[write_address] <= write_data;
  32. else
  33. bank1[write_address] <= write_data;
  34. inactive_written[write_address] <= 1'b1;
  35. end
  36. if (commit_applied) begin
  37. active_bank <= ~active_bank;
  38. // The old active bank is now the new inactive staging bank.
  39. // It must receive a fresh complete 32-byte vector before it
  40. // can ever become active again.
  41. inactive_written <= 32'd0;
  42. end
  43. end
  44. end
  45. `ifdef FORMAL
  46. (* anyconst *) reg [4:0] formal_address;
  47. reg formal_past_valid;
  48. reg formal_active_valid;
  49. wire [7:0] formal_active_data = active_bank ?
  50. bank1[formal_address] : bank0[formal_address];
  51. wire [7:0] formal_inactive_data = active_bank ?
  52. bank0[formal_address] : bank1[formal_address];
  53. initial formal_past_valid = 1'b0;
  54. initial formal_active_valid = 1'b0;
  55. always @(posedge clk) begin
  56. formal_past_valid <= 1'b1;
  57. assume(formal_address < 32);
  58. if (!rst_n)
  59. formal_active_valid <= 1'b0;
  60. else if (commit_applied)
  61. formal_active_valid <= 1'b1;
  62. if (inactive_written[formal_address])
  63. assert(formal_inactive_data <= 100);
  64. if (formal_active_valid)
  65. assert(formal_active_data <= 100);
  66. if (formal_past_valid && $past(rst_n) && rst_n) begin
  67. if ($past(commit_applied))
  68. assert(active_bank != $past(active_bank));
  69. else begin
  70. assert(active_bank == $past(active_bank));
  71. // Inactive-bank writes are never visible through the active
  72. // vector before an explicit atomic pointer commit.
  73. assert(formal_active_data == $past(formal_active_data));
  74. end
  75. if ($past(stimulus_commit) && !$past(commit_applied))
  76. assert(active_bank == $past(active_bank));
  77. if (formal_active_valid && !$past(formal_active_valid)) begin
  78. assert($past(commit_applied));
  79. assert(formal_active_data <= 100);
  80. end
  81. end
  82. end
  83. `endif
  84. endmodule