[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; |
---|
[22] | 89 | #700_000 |
---|
[11] | 90 | $display("INFO: TBENCH: Completed simulation!"); |
---|
| 91 | $finish; |
---|
| 92 | |
---|
| 93 | end |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | //*************************************************************************** |
---|
| 97 | // Clock generation and reset |
---|
| 98 | //*************************************************************************** |
---|
| 99 | |
---|
| 100 | initial |
---|
| 101 | clk_in = 1'b0; |
---|
| 102 | always |
---|
| 103 | clk_in = #(CLK_PERIOD_NS/2) ~clk_in; |
---|
| 104 | |
---|
| 105 | assign clk_in_p = clk_in; |
---|
| 106 | assign clk_in_n = ~clk_in; |
---|
| 107 | |
---|
| 108 | initial |
---|
| 109 | sys_clk200 = 1'b0; |
---|
| 110 | always |
---|
| 111 | sys_clk200 = #(TCYC_200/2) ~sys_clk200; |
---|
| 112 | |
---|
| 113 | assign clk200_p = sys_clk200; |
---|
| 114 | assign clk200_n = ~sys_clk200; |
---|
| 115 | |
---|
| 116 | initial begin |
---|
| 117 | sys_rst_n = 1'b0; |
---|
| 118 | #200; |
---|
| 119 | sys_rst_n = 1'b1; |
---|
| 120 | end |
---|
| 121 | assign sys_rst_out = RST_ACT_LOW ? sys_rst_n : ~sys_rst_n; |
---|
| 122 | |
---|
| 123 | //*************************************************************************** |
---|
| 124 | // W1 module instance |
---|
| 125 | //*************************************************************************** |
---|
| 126 | |
---|
| 127 | W1 W1_inst |
---|
| 128 | ( |
---|
| 129 | .clk_in (clk_in), |
---|
[17] | 130 | .sysrst (sys_rst_out), |
---|
[11] | 131 | |
---|
| 132 | // ddr3 memory interface |
---|
[22] | 133 | .ddr3_dq (ddr2_dq_fpga), |
---|
| 134 | .ddr3_dqs (ddr2_dqs_fpga), |
---|
| 135 | .ddr3_dqs_n (ddr2_dqs_n_fpga), |
---|
| 136 | .ddr3_ck (ddr2_clk_fpga), |
---|
| 137 | .ddr3_ck_n (ddr2_clk_n_fpga), |
---|
| 138 | .ddr3_a (ddr2_address_fpga), |
---|
| 139 | .ddr3_ba (ddr2_ba_fpga), //FIXME |
---|
| 140 | .ddr3_ras_n (ddr2_ras_n_fpga), |
---|
| 141 | .ddr3_cas_n (ddr2_cas_n_fpga), |
---|
| 142 | .ddr3_we_n (ddr2_we_n_fpga), |
---|
| 143 | .ddr3_cs_n (ddr2_cs_n_fpga), |
---|
| 144 | .ddr3_odt (ddr2_odt_fpga), |
---|
| 145 | .ddr3_ce (ddr2_cke_fpga), |
---|
| 146 | .ddr3_dm (ddr2_dm_fpga), |
---|
[11] | 147 | |
---|
| 148 | // Console interface |
---|
| 149 | .srx (srx), |
---|
| 150 | .stx (stx), |
---|
| 151 | |
---|
| 152 | //flash interface |
---|
| 153 | .flash_addr(flash_addr), |
---|
| 154 | .flash_data(flash_data), |
---|
| 155 | .flash_oen(flash_oen), |
---|
| 156 | .flash_wen(flash_wen), |
---|
| 157 | .flash_cen(flash_cen), |
---|
| 158 | .flash_clk(flash_clk), |
---|
| 159 | .flash_adv(flash_adv), |
---|
| 160 | .flash_rst(flash_rst) |
---|
| 161 | ); |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | //*************************************************************************** |
---|
| 165 | // FLASH module instance |
---|
| 166 | //*************************************************************************** |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | flash flash_inst |
---|
| 170 | ( |
---|
| 171 | .flash_addr(flash_addr), |
---|
| 172 | .flash_data(flash_data), |
---|
| 173 | .flash_oen(flash_oen), |
---|
| 174 | .flash_wen(flash_wen), |
---|
| 175 | .flash_cen(flash_cen), |
---|
| 176 | .flash_clk(flash_clk), |
---|
| 177 | .flash_adv(flash_adv), |
---|
| 178 | .flash_rst(flash_rst) |
---|
| 179 | ); |
---|
[22] | 180 | |
---|
| 181 | //DDR2 model |
---|
| 182 | // |
---|
| 183 | |
---|
| 184 | always @( * ) begin |
---|
| 185 | ddr2_clk_sdram <= #(TPROP_PCB_CTRL) ddr2_clk_fpga; |
---|
| 186 | ddr2_clk_n_sdram <= #(TPROP_PCB_CTRL) ddr2_clk_n_fpga; |
---|
| 187 | ddr2_address_sdram <= #(TPROP_PCB_CTRL) ddr2_address_fpga; |
---|
| 188 | ddr2_ba_sdram <= #(TPROP_PCB_CTRL) ddr2_ba_fpga; |
---|
| 189 | ddr2_ras_n_sdram <= #(TPROP_PCB_CTRL) ddr2_ras_n_fpga; |
---|
| 190 | ddr2_cas_n_sdram <= #(TPROP_PCB_CTRL) ddr2_cas_n_fpga; |
---|
| 191 | ddr2_we_n_sdram <= #(TPROP_PCB_CTRL) ddr2_we_n_fpga; |
---|
| 192 | ddr2_cs_n_sdram <= #(TPROP_PCB_CTRL) ddr2_cs_n_fpga; |
---|
| 193 | ddr2_cke_sdram <= #(TPROP_PCB_CTRL) ddr2_cke_fpga; |
---|
| 194 | ddr2_odt_sdram <= #(TPROP_PCB_CTRL) ddr2_odt_fpga; |
---|
| 195 | ddr2_dm_sdram_tmp <= #(TPROP_PCB_DATA) ddr2_dm_fpga;//DM signal generation |
---|
| 196 | end |
---|
| 197 | |
---|
| 198 | assign ddr2_dm_sdram = ddr2_dm_sdram_tmp; |
---|
| 199 | |
---|
| 200 | genvar dqwd; |
---|
| 201 | generate |
---|
| 202 | for (dqwd = 0;dqwd < DQ_WIDTH;dqwd = dqwd+1) begin : dq_delay |
---|
| 203 | WireDelay # |
---|
| 204 | ( |
---|
| 205 | .Delay_g (TPROP_PCB_DATA), |
---|
| 206 | .Delay_rd (TPROP_PCB_DATA_RD) |
---|
| 207 | ) |
---|
| 208 | u_delay_dq |
---|
| 209 | ( |
---|
| 210 | .A (ddr2_dq_fpga[dqwd]), |
---|
| 211 | .B (ddr2_dq_sdram[dqwd]), |
---|
| 212 | .reset (sys_rst_n) |
---|
| 213 | ); |
---|
| 214 | end |
---|
| 215 | endgenerate |
---|
| 216 | |
---|
| 217 | |
---|
| 218 | genvar dqswd; |
---|
| 219 | generate |
---|
| 220 | for (dqswd = 0;dqswd < DQS_WIDTH;dqswd = dqswd+1) begin : dqs_delay |
---|
| 221 | WireDelay # |
---|
| 222 | ( |
---|
| 223 | .Delay_g (TPROP_DQS), |
---|
| 224 | .Delay_rd (TPROP_DQS_RD) |
---|
| 225 | ) |
---|
| 226 | u_delay_dqs |
---|
| 227 | ( |
---|
| 228 | .A (ddr2_dqs_fpga[dqswd]), |
---|
| 229 | .B (ddr2_dqs_sdram[dqswd]), |
---|
| 230 | .reset (sys_rst_n) |
---|
| 231 | ); |
---|
| 232 | |
---|
| 233 | WireDelay # |
---|
| 234 | ( |
---|
| 235 | .Delay_g (TPROP_DQS), |
---|
| 236 | .Delay_rd (TPROP_DQS_RD) |
---|
| 237 | ) |
---|
| 238 | u_delay_dqs_n |
---|
| 239 | ( |
---|
| 240 | .A (ddr2_dqs_n_fpga[dqswd]), |
---|
| 241 | .B (ddr2_dqs_n_sdram[dqswd]), |
---|
| 242 | .reset (sys_rst_n) |
---|
| 243 | ); |
---|
| 244 | end |
---|
| 245 | endgenerate |
---|
| 246 | |
---|
[11] | 247 | // if the data width is multiple of 16 |
---|
| 248 | //for(j = 0; j < CS_NUM; j = j+1) begin : gen_cs |
---|
| 249 | for(i = 0; i < DQS_WIDTH/2; i = i+1) begin : gen |
---|
| 250 | ddr2_model u_mem0 |
---|
| 251 | ( |
---|
| 252 | .ck (ddr2_clk_sdram), |
---|
| 253 | .ck_n (ddr2_clk_n_sdram), |
---|
| 254 | .cke (ddr2_cke_sdram), |
---|
| 255 | .cs_n (ddr2_cs_n_sdram[CS_WIDTH*i/DQS_WIDTH]), |
---|
| 256 | .ras_n (ddr2_ras_n_sdram), |
---|
| 257 | .cas_n (ddr2_cas_n_sdram), |
---|
| 258 | .we_n (ddr2_we_n_sdram), |
---|
| 259 | .dm_rdqs (ddr2_dm_sdram[(2*(i+1))-1 : i*2]), |
---|
[17] | 260 | .ba (ddr2_ba_sdram), //FIXME |
---|
[11] | 261 | .addr (ddr2_address_sdram), |
---|
| 262 | .dq (ddr2_dq_sdram[(16*(i+1))-1 : i*16]), |
---|
| 263 | .dqs (ddr2_dqs_sdram[(2*(i+1))-1 : i*2]), |
---|
| 264 | .dqs_n (ddr2_dqs_n_sdram[(2*(i+1))-1 : i*2]), |
---|
| 265 | .rdqs_n (), |
---|
| 266 | .odt (ddr2_odt_sdram[ODT_WIDTH*i/DQS_WIDTH]) |
---|
| 267 | ); |
---|
| 268 | end |
---|
| 269 | //end |
---|
| 270 | endmodule |
---|
| 271 | |
---|