Files
CoCo3_Plus_MiSTer/tests/external_sdram_commands_tb.sv
T
bholman cb40fed3b9 Introduce Coco 3 Plus for MiSTer
Add original-firmware Sound & Speech, four configurable Multi-Pak sockets,
bounded per-slot ROM allocation and a nine-page menu organized around devices
and media. Repair inherited clock/reset/CPU-memory/video paths and add explicit
conditional external-I/O timing contracts. Preserve native Main startup-file
ordering, saved layouts, stock-core separation and the coco3plus media profile.

Provide native Windows tool downloads, pinned ToolShed ROM assembly, fresh
Quartus builds, functional and fitted timing checks, reviewed release packaging
and passwordless SSH installation with backups. Retain original component
notices, document contribution copyright and keep SSC ROM inputs outside Git.

Validation: Quartus17.0.2 Build602 seed5, zero errors; 15 functional jobs,
368 both-corner timing scopes and eight tooling-integrity checks pass.
The renamed build reaches Disk BASIC, PRINT1+1 returns2 and SSC loads ready.
Physical cold power cycling and conditional board-delay assumptions remain
separate. Full original upstream histories are preserved before this single
consolidated implementation commit.
2026-11-18 16:00:45 -07:00

88 lines
3.5 KiB
Systemverilog

`timescale 1ns/1ps
// Pin-command minimum intervals, independent of the controller's state encoding.
module external_sdram_commands_tb;
reg clk=0,init=1,req=0,rnw=0;
always #4.365079 clk=~clk;
wire [15:0] dq;
assign dq=rnw ? 16'h965a : 16'hzzzz;
wire [12:0] address;
wire [1:0] bank;
wire cs,ras,cas,we,memclk,ack,ready;
reg [24:0] cpu_address=0;
integer commands=0,activates=0,writes=0,reads=0,refreshes=0;
realtime released=0, next_command=0;
realtime last_active[0:3],next_active[0:3];
realtime now_time, earliest;
realtime last_refresh=-1;
reg configured=0;
integer b,j,timeout;
reg started=0;
sdram_probe dut(.init(init),.clk(clk),.SDRAM_DQ(dq),.SDRAM_A(address),.SDRAM_BA(bank),
.SDRAM_nCS(cs),.SDRAM_nRAS(ras),.SDRAM_nCAS(cas),.SDRAM_nWE(we),.SDRAM_CLK(memclk),
.sdram_cpu_addr(cpu_address),.sdram_cpu_din(8'h5a),.sdram_cpu_req(req),.sdram_cpu_rnw(rnw),
.sdram_cpu_ack(ack),.sdram_cpu_ready(ready),.sdram_vid_addr(25'd0),.sdram_vid_req(1'b0));
initial for(b=0;b<4;b=b+1) begin last_active[b]=-1000000;next_active[b]=0;end
always @(posedge memclk) if(!init && {ras,cas,we}!==3'b111) begin
now_time=$realtime;
if(!started) begin
if(!$test$plusargs("IGNORE_STARTUP") && now_time-released<200000)
$fatal(1,"SDRAM startup below 200 us: %0.3f ns",now_time-released);
started=1;
end
if(now_time+0.001<next_command) $fatal(1,"SDRAM refresh/precharge/mode recovery");
commands=commands+1;
case({ras,cas,we})
3'b011: begin
if(!$test$plusargs("IGNORE_TRC") && now_time-last_active[bank]<63.0) $fatal(1,"SDRAM tRC below 63 ns: %0.3f",now_time-last_active[bank]);
if(!$test$plusargs("IGNORE_TRC") && now_time+0.001<next_active[bank]) $fatal(1,"SDRAM auto-precharge recovery");
last_active[bank]=now_time;activates=activates+1;
end
3'b101,3'b100: begin
if(now_time-last_active[bank]<21.0) $fatal(1,"SDRAM tRCD below 21 ns");
if({ras,cas,we}==3'b100) begin
writes=writes+1;earliest=now_time+14.0;
end else begin
reads=reads+1;earliest=now_time+2.0*8.730158;
end
if(earliest<last_active[bank]+42.0) earliest=last_active[bank]+42.0;
if(address[10]) next_active[bank]=earliest+21.0;
end
3'b010: next_command=now_time+21.0;
3'b001: begin
next_command=now_time+63.0;refreshes=refreshes+1;
if(configured) begin
if(last_refresh>=0 && now_time-last_refresh>7812.5) $fatal(1,"SDRAM refresh interval above 7812.5 ns: %0.3f",now_time-last_refresh);
last_refresh=now_time;
end
end
3'b000: begin next_command=now_time+14.0;configured=1;end
endcase
end
task transfer(input bit read_mode,input [24:0] addr);
begin
@(negedge clk);rnw=read_mode;cpu_address=addr;req=1;
timeout=0;
while(!ack && timeout<40000) begin @(negedge clk);timeout=timeout+1;end
if(timeout==40000) $fatal(1,"SDRAM request timeout");
req=0;
while(ack) @(negedge clk);
if(read_mode) begin
timeout=0;
while(!ready && timeout<100) begin @(negedge clk);timeout=timeout+1;end
if(timeout==100) $fatal(1,"SDRAM read timeout");
end
end
endtask
initial begin
repeat(10) @(negedge clk);
init=0;released=$realtime;
// Legal held-until-ACK requests may be queued during startup.
for(j=0;j<128;j=j+1) transfer(0,{9'd0,j[7:0],8'd0});
for(j=0;j<32;j=j+1) transfer(1,{9'd0,j[7:0],8'd0});
repeat(50000) @(negedge clk);
if(writes!=128 || reads!=32 || refreshes<3) $fatal(1,"Incomplete command coverage");
$display("PASS SDRAM command intervals: startup >=200us, %0d ACT, %0d WR, %0d RD, %0d REF",activates,writes,reads,refreshes);
$finish;
end
endmodule