feat: add entropy byte stream FIFO and faster SPI read-back (FPGA v7)

This commit is contained in:
randogoth 2026-10-25 15:29:30 +02:00
parent 8541cce59c
commit 7777384495
6 changed files with 232 additions and 38 deletions

View file

@ -1,7 +1,8 @@
// Testbench for strix_core: register access, generator XOR logic checked against the sampled
// ring outputs, captures read back across transactions, generator enable, the frequency
// counter, the health monitors with injected faults, the statistics snapshots against a
// reference model, and the bias amplifier's bit counts in several configurations. Rings are replaced by the SIM model in ring_osc.v.
// reference model, the bias amplifier's bit counts in several configurations, and the entropy
// byte stream against the FIFO contents. Rings are replaced by the SIM model in ring_osc.v.
`timescale 1ns / 1ps
module tb_strix_core;
@ -19,7 +20,8 @@ module tb_strix_core;
REG_HEALTHY = 7'h20, REG_HEALTH_CTRL = 7'h21, REG_TRIAL_LOW = 7'h27,
REG_STATS_CTRL = 7'h28, REG_STATS = 7'h40, REG_AMP = 7'h42,
REG_AMP_CTRL = 7'h50, REG_AMP_SOURCES = 7'h51, REG_AMP_SUB_MS = 7'h52,
REG_AMP_SUBS = 7'h53, REG_AMP_STAGE = 7'h54;
REG_AMP_SUBS = 7'h53, REG_AMP_STAGE = 7'h54, REG_STREAM_CTRL = 7'h29,
REG_LEVEL_HIGH = 7'h2A, REG_LEVEL_LOW = 7'h2B, REG_STREAM = 7'h44;
localparam AMP_SNAPSHOT_BYTES = 44;
localparam SNAPSHOT_BYTES = 72;
localparam TICK_CYCLES = 1500; // 1 "ms" = 12.5 us: a 10 "ms" trial outlasts a 72-byte read
@ -280,7 +282,7 @@ module tb_strix_core;
// Identification
read_reg(REG_ID0, v); expect(v, "S", "ID0");
read_reg(REG_ID3, v); expect(v, "X", "ID3");
read_reg(REG_VERSION, v); expect(v, 8'h06, "VERSION");
read_reg(REG_VERSION, v); expect(v, 8'h07, "VERSION");
read_reg(REG_GENERATORS, v); expect(v, 8'd4, "GENERATORS");
read_reg(REG_RINGS, v); expect(v, RINGS, "RINGS");
read_reg(REG_TEMPORAL, v); expect(v, 8'd5, "TEMPORAL");
@ -429,6 +431,34 @@ module tb_strix_core;
expect_range(amp_word(8), 4 * AMP_GEN_BITS / 6, 4 * AMP_GEN_BITS / 3, "amp von Neumann bits");
write_reg(REG_AMP_CTRL, 8'h00);
// Entropy stream: combined channel, flushed, then 16 bytes read in one burst
write_reg(REG_STREAM_CTRL, 8'h84);
#20000;
read_reg(REG_LEVEL_LOW, v);
expect_range(v, 20, 255, "stream level");
begin : stream_read
reg [7:0] expected [0:15];
reg [12:0] start_ptr;
reg [7:0] dummy, value;
integer i;
start_ptr = dut.stream.read_ptr;
for (i = 0; i < 16; i = i + 1) expected[i] = dut.stream.buffer[(start_ptr + i) % 4096];
ss_n = 1'b0; #SCK_HALF;
spi_byte({1'b1, REG_STREAM}, dummy);
for (i = 0; i < 16; i = i + 1) begin
spi_byte(8'h00, value);
if (value !== expected[i]) begin
$display("FAIL stream byte %0d: got %02x, expected %02x", i, value, expected[i]);
errors = errors + 1;
end
end
#SCK_HALF ss_n = 1'b1; #(4 * SCK_HALF);
expect(dut.stream.read_ptr - start_ptr, 8'd16, "stream bytes removed");
end
write_reg(REG_STREAM_CTRL, 8'h84);
read_reg(REG_LEVEL_LOW, v);
expect_range(v, 0, 15, "stream level after flush");
if (xor_checks < 100) begin
$display("FAIL only %0d temporal XOR checks ran", xor_checks);
errors = errors + 1;