[11] | 1 | `timescale 1ns / 1ps |
---|
| 2 | |
---|
| 3 | module tb_top; |
---|
| 4 | |
---|
| 5 | parameter CLK_WIDTH = 3; // # of clock outputs |
---|
| 6 | parameter CS_NUM = 1; // # of separate memory chip selects |
---|
| 7 | parameter CS_WIDTH = 1; // # of total memory chip selects |
---|
| 8 | parameter DQ_WIDTH = 64; // # of data width |
---|
| 9 | parameter DQS_WIDTH = 8; // # of DQS strobes |
---|
| 10 | parameter ODT_WIDTH = 1; // # of memory on-die term enables |
---|
| 11 | |
---|
| 12 | parameter CLK_PERIOD = 5000; // Core/Mem clk period (in ps) |
---|
| 13 | localparam real CLK_PERIOD_NS = CLK_PERIOD / 1000.0; |
---|
| 14 | localparam real TCYC_200 = 5.0; |
---|
| 15 | parameter RST_ACT_LOW = 1; // =1 for active low reset, =0 for active high |
---|
[22] | 16 | localparam real TPROP_DQS = 0.01; // Delay for DQS signal during Write Operation |
---|
| 17 | localparam real TPROP_DQS_RD = 0.01; // Delay for DQS signal during Read Operation |
---|
| 18 | localparam real TPROP_PCB_CTRL = 0.01; // Delay for Address and Ctrl signals |
---|
| 19 | localparam real TPROP_PCB_DATA = 0.01; // Delay for data signal during Write operation |
---|
| 20 | localparam real TPROP_PCB_DATA_RD = 0.01; // Delay for data signal during Read operation |
---|
[11] | 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | genvar j; |
---|
| 25 | genvar i; |
---|
| 26 | reg clk_in; |
---|
| 27 | wire clk_in_n; |
---|
| 28 | wire clk_in_p; |
---|
| 29 | reg sys_clk200; |
---|
| 30 | wire clk200_n; |
---|
| 31 | wire clk200_p; |
---|
| 32 | reg sys_rst_n; |
---|
| 33 | wire sys_rst_out; |
---|
| 34 | |
---|
| 35 | wire [DQ_WIDTH-1:0] ddr2_dq_sdram; |
---|
| 36 | wire [DQS_WIDTH-1:0] ddr2_dqs_sdram; |
---|
| 37 | wire [DQS_WIDTH-1:0] ddr2_dqs_n_sdram; |
---|
| 38 | wire [7:0] ddr2_dm_sdram; |
---|
[22] | 39 | reg [7:0] ddr2_dm_sdram_tmp; |
---|
| 40 | reg ddr2_clk_sdram; |
---|
| 41 | reg ddr2_clk_n_sdram; |
---|
| 42 | reg [12:0] ddr2_address_sdram; |
---|
| 43 | reg [1:0] ddr2_ba_sdram; |
---|
| 44 | reg ddr2_ras_n_sdram; |
---|
| 45 | reg ddr2_cas_n_sdram; |
---|
| 46 | reg ddr2_we_n_sdram; |
---|
| 47 | reg [CS_WIDTH-1:0] ddr2_cs_n_sdram; |
---|
| 48 | reg ddr2_cke_sdram; |
---|
| 49 | reg [ODT_WIDTH-1:0] ddr2_odt_sdram; |
---|
[11] | 50 | |
---|
[22] | 51 | wire [DQ_WIDTH-1:0] ddr2_dq_fpga; |
---|
| 52 | wire [DQS_WIDTH-1:0] ddr2_dqs_fpga; |
---|
| 53 | wire [DQS_WIDTH-1:0] ddr2_dqs_n_fpga; |
---|
| 54 | wire [7:0] ddr2_dm_fpga; |
---|
| 55 | wire ddr2_clk_fpga; |
---|
| 56 | wire ddr2_clk_n_fpga; |
---|
| 57 | wire [12:0] ddr2_address_fpga; |
---|
| 58 | wire [1:0] ddr2_ba_fpga; |
---|
| 59 | wire ddr2_ras_n_fpga; |
---|
| 60 | wire ddr2_cas_n_fpga; |
---|
| 61 | wire ddr2_we_n_fpga; |
---|
| 62 | wire [CS_WIDTH-1:0] ddr2_cs_n_fpga; |
---|
| 63 | wire ddr2_cke_fpga; |
---|
| 64 | wire [ODT_WIDTH-1:0] ddr2_odt_fpga; |
---|
| 65 | |
---|
| 66 | |
---|
[11] | 67 | wire stx; |
---|
| 68 | wire srx; |
---|
| 69 | |
---|
[17] | 70 | wire [21:0] flash_addr; |
---|
| 71 | wire [15:0] flash_data; |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
[11] | 75 | initial begin |
---|
| 76 | |
---|
| 77 | // Display start message |
---|
| 78 | $display("INFO: TBENCH: Starting simulation..."); |
---|
| 79 | |
---|
| 80 | // Create VCD trace file |
---|
[22] | 81 | // $dumpfile("trace.vcd"); |
---|
| 82 | // $dumpvars(); |
---|
[11] | 83 | |
---|
| 84 | // Run the simulation |
---|
| 85 | // sys_clock <= 1'b1; |
---|
| 86 | // sys_reset <= 1'b1; |
---|
| 87 | // #1000 |
---|
| 88 | // sys_reset <= 1'b0; |
---|
[23] | 89 | // #700_000 |
---|
| 90 | #374_600 |
---|
[11] | 91 | $display("INFO: TBENCH: Completed simulation!"); |
---|
| 92 | $finish; |
---|
| 93 | |
---|
| 94 | end |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | //*************************************************************************** |
---|
| 98 | // Clock generation and reset |
---|
| 99 | //*************************************************************************** |
---|
| 100 | |
---|
| 101 | initial |
---|
| 102 | clk_in = 1'b0; |
---|
| 103 | always |
---|
| 104 | clk_in = #(CLK_PERIOD_NS/2) ~clk_in; |
---|
| 105 | |
---|
| 106 | assign clk_in_p = clk_in; |
---|
| 107 | assign clk_in_n = ~clk_in; |
---|
| 108 | |
---|
| 109 | initial |
---|
| 110 | sys_clk200 = 1'b0; |
---|
| 111 | always |
---|
| 112 | sys_clk200 = #(TCYC_200/2) ~sys_clk200; |
---|
| 113 | |
---|
| 114 | assign clk200_p = sys_clk200; |
---|
| 115 | assign clk200_n = ~sys_clk200; |
---|
| 116 | |
---|
| 117 | initial begin |
---|
| 118 | sys_rst_n = 1'b0; |
---|
| 119 | #200; |
---|
| 120 | sys_rst_n = 1'b1; |
---|
| 121 | end |
---|
| 122 | assign sys_rst_out = RST_ACT_LOW ? sys_rst_n : ~sys_rst_n; |
---|
| 123 | |
---|
| 124 | //*************************************************************************** |
---|
| 125 | // W1 module instance |
---|
| 126 | //*************************************************************************** |
---|
| 127 | |
---|
| 128 | W1 W1_inst |
---|
| 129 | ( |
---|
| 130 | .clk_in (clk_in), |
---|
[17] | 131 | .sysrst (sys_rst_out), |
---|
[11] | 132 | |
---|
| 133 | // ddr3 memory interface |
---|
[22] | 134 | .ddr3_dq (ddr2_dq_fpga), |
---|
| 135 | .ddr3_dqs (ddr2_dqs_fpga), |
---|
| 136 | .ddr3_dqs_n (ddr2_dqs_n_fpga), |
---|
| 137 | .ddr3_ck (ddr2_clk_fpga), |
---|
| 138 | .ddr3_ck_n (ddr2_clk_n_fpga), |
---|
| 139 | .ddr3_a (ddr2_address_fpga), |
---|
| 140 | .ddr3_ba (ddr2_ba_fpga), //FIXME |
---|
| 141 | .ddr3_ras_n (ddr2_ras_n_fpga), |
---|
| 142 | .ddr3_cas_n (ddr2_cas_n_fpga), |
---|
| 143 | .ddr3_we_n (ddr2_we_n_fpga), |
---|
| 144 | .ddr3_cs_n (ddr2_cs_n_fpga), |
---|
| 145 | .ddr3_odt (ddr2_odt_fpga), |
---|
| 146 | .ddr3_ce (ddr2_cke_fpga), |
---|
| 147 | .ddr3_dm (ddr2_dm_fpga), |
---|
[11] | 148 | |
---|
| 149 | // Console interface |
---|
| 150 | .srx (srx), |
---|
| 151 | .stx (stx), |
---|
| 152 | |
---|
| 153 | //flash interface |
---|
| 154 | .flash_addr(flash_addr), |
---|
| 155 | .flash_data(flash_data), |
---|
| 156 | .flash_oen(flash_oen), |
---|
| 157 | .flash_wen(flash_wen), |
---|
| 158 | .flash_cen(flash_cen), |
---|
| 159 | .flash_clk(flash_clk), |
---|
| 160 | .flash_adv(flash_adv), |
---|
| 161 | .flash_rst(flash_rst) |
---|
| 162 | ); |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | //*************************************************************************** |
---|
| 166 | // FLASH module instance |
---|
| 167 | //*************************************************************************** |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | flash flash_inst |
---|
| 171 | ( |
---|
| 172 | .flash_addr(flash_addr), |
---|
| 173 | .flash_data(flash_data), |
---|
| 174 | .flash_oen(flash_oen), |
---|
| 175 | .flash_wen(flash_wen), |
---|
| 176 | .flash_cen(flash_cen), |
---|
| 177 | .flash_clk(flash_clk), |
---|
| 178 | .flash_adv(flash_adv), |
---|
| 179 | .flash_rst(flash_rst) |
---|
| 180 | ); |
---|
[22] | 181 | |
---|
| 182 | //DDR2 model |
---|
| 183 | // |
---|
| 184 | |
---|
| 185 | always @( * ) begin |
---|
| 186 | ddr2_clk_sdram <= #(TPROP_PCB_CTRL) ddr2_clk_fpga; |
---|
| 187 | ddr2_clk_n_sdram <= #(TPROP_PCB_CTRL) ddr2_clk_n_fpga; |
---|
| 188 | ddr2_address_sdram <= #(TPROP_PCB_CTRL) ddr2_address_fpga; |
---|
| 189 | ddr2_ba_sdram <= #(TPROP_PCB_CTRL) ddr2_ba_fpga; |
---|
| 190 | ddr2_ras_n_sdram <= #(TPROP_PCB_CTRL) ddr2_ras_n_fpga; |
---|
| 191 | ddr2_cas_n_sdram <= #(TPROP_PCB_CTRL) ddr2_cas_n_fpga; |
---|
| 192 | ddr2_we_n_sdram <= #(TPROP_PCB_CTRL) ddr2_we_n_fpga; |
---|
| 193 | ddr2_cs_n_sdram <= #(TPROP_PCB_CTRL) ddr2_cs_n_fpga; |
---|
| 194 | ddr2_cke_sdram <= #(TPROP_PCB_CTRL) ddr2_cke_fpga; |
---|
| 195 | ddr2_odt_sdram <= #(TPROP_PCB_CTRL) ddr2_odt_fpga; |
---|
| 196 | ddr2_dm_sdram_tmp <= #(TPROP_PCB_DATA) ddr2_dm_fpga;//DM signal generation |
---|
| 197 | end |
---|
| 198 | |
---|
| 199 | assign ddr2_dm_sdram = ddr2_dm_sdram_tmp; |
---|
| 200 | |
---|
| 201 | genvar dqwd; |
---|
| 202 | generate |
---|
| 203 | for (dqwd = 0;dqwd < DQ_WIDTH;dqwd = dqwd+1) begin : dq_delay |
---|
| 204 | WireDelay # |
---|
| 205 | ( |
---|
| 206 | .Delay_g (TPROP_PCB_DATA), |
---|
| 207 | .Delay_rd (TPROP_PCB_DATA_RD) |
---|
| 208 | ) |
---|
| 209 | u_delay_dq |
---|
| 210 | ( |
---|
| 211 | .A (ddr2_dq_fpga[dqwd]), |
---|
| 212 | .B (ddr2_dq_sdram[dqwd]), |
---|
| 213 | .reset (sys_rst_n) |
---|
| 214 | ); |
---|
| 215 | end |
---|
| 216 | endgenerate |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | genvar dqswd; |
---|
| 220 | generate |
---|
| 221 | for (dqswd = 0;dqswd < DQS_WIDTH;dqswd = dqswd+1) begin : dqs_delay |
---|
| 222 | WireDelay # |
---|
| 223 | ( |
---|
| 224 | .Delay_g (TPROP_DQS), |
---|
| 225 | .Delay_rd (TPROP_DQS_RD) |
---|
| 226 | ) |
---|
| 227 | u_delay_dqs |
---|
| 228 | ( |
---|
| 229 | .A (ddr2_dqs_fpga[dqswd]), |
---|
| 230 | .B (ddr2_dqs_sdram[dqswd]), |
---|
| 231 | .reset (sys_rst_n) |
---|
| 232 | ); |
---|
| 233 | |
---|
| 234 | WireDelay # |
---|
| 235 | ( |
---|
| 236 | .Delay_g (TPROP_DQS), |
---|
| 237 | .Delay_rd (TPROP_DQS_RD) |
---|
| 238 | ) |
---|
| 239 | u_delay_dqs_n |
---|
| 240 | ( |
---|
| 241 | .A (ddr2_dqs_n_fpga[dqswd]), |
---|
| 242 | .B (ddr2_dqs_n_sdram[dqswd]), |
---|
| 243 | .reset (sys_rst_n) |
---|
| 244 | ); |
---|
| 245 | end |
---|
| 246 | endgenerate |
---|
| 247 | |
---|
[11] | 248 | // if the data width is multiple of 16 |
---|
| 249 | //for(j = 0; j < CS_NUM; j = j+1) begin : gen_cs |
---|
| 250 | for(i = 0; i < DQS_WIDTH/2; i = i+1) begin : gen |
---|
| 251 | ddr2_model u_mem0 |
---|
| 252 | ( |
---|
| 253 | .ck (ddr2_clk_sdram), |
---|
| 254 | .ck_n (ddr2_clk_n_sdram), |
---|
| 255 | .cke (ddr2_cke_sdram), |
---|
| 256 | .cs_n (ddr2_cs_n_sdram[CS_WIDTH*i/DQS_WIDTH]), |
---|
| 257 | .ras_n (ddr2_ras_n_sdram), |
---|
| 258 | .cas_n (ddr2_cas_n_sdram), |
---|
| 259 | .we_n (ddr2_we_n_sdram), |
---|
| 260 | .dm_rdqs (ddr2_dm_sdram[(2*(i+1))-1 : i*2]), |
---|
[17] | 261 | .ba (ddr2_ba_sdram), //FIXME |
---|
[11] | 262 | .addr (ddr2_address_sdram), |
---|
| 263 | .dq (ddr2_dq_sdram[(16*(i+1))-1 : i*16]), |
---|
| 264 | .dqs (ddr2_dqs_sdram[(2*(i+1))-1 : i*2]), |
---|
| 265 | .dqs_n (ddr2_dqs_n_sdram[(2*(i+1))-1 : i*2]), |
---|
| 266 | .rdqs_n (), |
---|
| 267 | .odt (ddr2_odt_sdram[ODT_WIDTH*i/DQS_WIDTH]) |
---|
| 268 | ); |
---|
| 269 | end |
---|
| 270 | //end |
---|
| 271 | endmodule |
---|
| 272 | |
---|