| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- `timescale 1ns/1ps
- // Identification-only 32-channel stimulus storage. Host writes always stage
- // into the inactive bank; a commit changes the active vector only after every
- // address has received an in-range value.
- module stimulus_atomic_bank (
- input wire clk,
- input wire rst_n,
- input wire write_enable,
- input wire [4:0] write_address,
- input wire [7:0] write_data,
- input wire stimulus_commit,
- output wire commit_applied,
- output reg active_bank,
- input wire read_bank,
- input wire [4:0] read_address,
- output wire [7:0] read_data
- );
- reg [7:0] bank0 [0:31];
- reg [7:0] bank1 [0:31];
- reg [31:0] inactive_written;
- wire accepted_write = write_enable && write_data <= 100;
- assign commit_applied = stimulus_commit && (&inactive_written);
- assign read_data = read_bank ? bank1[read_address] : bank0[read_address];
- always @(posedge clk or negedge rst_n) begin
- if (!rst_n) begin
- active_bank <= 1'b0;
- inactive_written <= 32'd0;
- end else begin
- if (accepted_write) begin
- if (active_bank)
- bank0[write_address] <= write_data;
- else
- bank1[write_address] <= write_data;
- inactive_written[write_address] <= 1'b1;
- end
- if (commit_applied) begin
- active_bank <= ~active_bank;
- // The old active bank is now the new inactive staging bank.
- // It must receive a fresh complete 32-byte vector before it
- // can ever become active again.
- inactive_written <= 32'd0;
- end
- end
- end
- `ifdef FORMAL
- (* anyconst *) reg [4:0] formal_address;
- reg formal_past_valid;
- reg formal_active_valid;
- wire [7:0] formal_active_data = active_bank ?
- bank1[formal_address] : bank0[formal_address];
- wire [7:0] formal_inactive_data = active_bank ?
- bank0[formal_address] : bank1[formal_address];
- initial formal_past_valid = 1'b0;
- initial formal_active_valid = 1'b0;
- always @(posedge clk) begin
- formal_past_valid <= 1'b1;
- assume(formal_address < 32);
- if (!rst_n)
- formal_active_valid <= 1'b0;
- else if (commit_applied)
- formal_active_valid <= 1'b1;
- if (inactive_written[formal_address])
- assert(formal_inactive_data <= 100);
- if (formal_active_valid)
- assert(formal_active_data <= 100);
- if (formal_past_valid && $past(rst_n) && rst_n) begin
- if ($past(commit_applied))
- assert(active_bank != $past(active_bank));
- else begin
- assert(active_bank == $past(active_bank));
- // Inactive-bank writes are never visible through the active
- // vector before an explicit atomic pointer commit.
- assert(formal_active_data == $past(formal_active_data));
- end
- if ($past(stimulus_commit) && !$past(commit_applied))
- assert(active_bank == $past(active_bank));
- if (formal_active_valid && !$past(formal_active_valid)) begin
- assert($past(commit_applied));
- assert(formal_active_data <= 100);
- end
- end
- end
- `endif
- endmodule
|