mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-12 20:15:31 +08:00
- Add hw/syn/Makefile with hier/flat/full synth targets and artifact mirroring - Add synth_cam_top_hier.ys for hierarchy-preserving resource estimation on Xilinx 7-series - Add synth_cam_top_flat.ys for flattened Xilinx 7-series synthesis - Add cam-synth just target for convenient invocation - Guard runtime assertions (NUM_ROWS/LANES checks, noise seed checks, NOISE_BITS checks) behind SYNTHESIS guard in cam_core_banked, cam_read_noise, cam_write_noise, and noise_mask_grouped - Fix shadowed 'return' variable in random128 xorshift128 function
78 lines
2.4 KiB
Systemverilog
78 lines
2.4 KiB
Systemverilog
`timescale 1ns / 1ps
|
|
`include "cam_params.svh"
|
|
|
|
module cam_write_noise #(
|
|
parameter bit WRITE_NOISE_EN = 1'b1,
|
|
parameter int WRITE_NOISE_RATE_NUM = 1,
|
|
parameter int WRITE_NOISE_RATE_DEN = 100,
|
|
parameter int WRITE_NOISE_BITS = 8,
|
|
parameter logic [63:0] WRITE_NOISE_SEED = 64'hB504_F32D_B504_F32D
|
|
) (
|
|
input logic clk,
|
|
input logic rst_n,
|
|
input logic wr_valid,
|
|
output logic wr_ready,
|
|
input logic [(`ROW_BITS)-1:0] wr_row,
|
|
input logic [(`HASH_BITS)-1:0] wr_hash,
|
|
output logic core_wr_valid,
|
|
output logic [(`ROW_BITS)-1:0] core_wr_row,
|
|
output logic [(`HASH_BITS)-1:0] core_wr_hash
|
|
);
|
|
logic pending_q;
|
|
logic [(`ROW_BITS)-1:0] row_q;
|
|
logic [(`HASH_BITS)-1:0] hash_q;
|
|
logic [127:0] random_num;
|
|
logic [(`HASH_BITS)-1:0] flip_mask;
|
|
|
|
assign wr_ready = !pending_q;
|
|
|
|
random128 u_random_write (
|
|
.clk (clk),
|
|
.rst_n (rst_n),
|
|
.enable(wr_valid && wr_ready && WRITE_NOISE_EN && (WRITE_NOISE_RATE_NUM > 0)),
|
|
.seed ({WRITE_NOISE_SEED, WRITE_NOISE_SEED}),
|
|
.out (random_num)
|
|
);
|
|
|
|
noise_mask_grouped #(
|
|
.HASH_BITS (`HASH_BITS),
|
|
.NOISE_BITS (WRITE_NOISE_BITS),
|
|
.NOISE_RATE_NUM (WRITE_NOISE_RATE_NUM),
|
|
.NOISE_RATE_DEN (WRITE_NOISE_RATE_DEN)
|
|
) u_mask (
|
|
.random_i(random_num),
|
|
.mask_o (flip_mask)
|
|
);
|
|
|
|
`ifndef SYNTHESIS
|
|
initial begin
|
|
if (WRITE_NOISE_SEED == 64'd0) $fatal(1, "WRITE_NOISE_SEED must be nonzero");
|
|
end
|
|
`endif
|
|
|
|
always_ff @(posedge clk or negedge rst_n) begin
|
|
if (!rst_n) begin
|
|
pending_q <= 1'b0;
|
|
row_q <= '0;
|
|
hash_q <= '0;
|
|
core_wr_valid <= 1'b0;
|
|
core_wr_row <= '0;
|
|
core_wr_hash <= '0;
|
|
end else begin
|
|
core_wr_valid <= pending_q;
|
|
core_wr_row <= row_q;
|
|
if (WRITE_NOISE_EN && (WRITE_NOISE_RATE_NUM > 0)) begin
|
|
core_wr_hash <= hash_q ^ flip_mask;
|
|
end else begin
|
|
core_wr_hash <= hash_q;
|
|
end
|
|
|
|
pending_q <= wr_valid && wr_ready;
|
|
if (wr_valid && wr_ready) begin
|
|
row_q <= wr_row;
|
|
hash_q <= wr_hash;
|
|
end
|
|
end
|
|
end
|
|
endmodule
|