driver_tasks.v 11.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
//`define DEBUG

task cbus_write;
  input	[CBUS_DATA_SIZE-1:0] address;
  input	[CBUS_DATA_SIZE-1:0] data;
  begin
    while (!dma_ready)
	@(posedge clock);
    cbus_command <= CBUS_WRITE_COMMAND;
    cbus_data_reg <= address;
    @(posedge clock);

    cbus_command <= CBUS_IDLE_COMMAND;
    cbus_data_reg <= data;
    @(posedge clock);
  end
endtask

task cbus_refresh;
  begin
    while (!dma_ready)
	@(posedge clock);
    cbus_command <= CBUS_REFRESH_COMMAND;
    cbus_data_reg <= 'hxxxxxxxx;
    @(posedge clock);

    cbus_command <= CBUS_IDLE_COMMAND;
    @(posedge clock);
  end
endtask

task cbus_dma_write;
  input masked;
  input down;
  input	[CBUS_DATA_SIZE-1:0] address;
  input	[DMA_DEVICE_SIZE-1:0] device;
  input [31:0] delay;
  input	[31:0] length;

  reg	[DMA_DELAY_SIZE-1:0] start_delay;
  reg	[DMA_LENGTH_SIZE-1:0] byte_length;
  reg	nseq;

  begin
    start_delay = delay;
    byte_length = length - 1;

    while (!dma_ready)
	@(posedge clock);

`ifdef DEBUG
    $write("dma write ");
    if (masked)
      $write("masked ");
    if (down)
      $write("down ");
    else
      $write("up ");
    $write("to 0x%x, length 0%x at time %d\n", address, length, $time);
`endif

    cbus_command <= CBUS_DMA_COMMAND;
    cbus_data_reg <= address;

    @(posedge clock);

    nseq = (masked || down);
    cbus_command <= CBUS_IDLE_COMMAND;
    cbus_data_reg <= {1'b0, masked, down, nseq, device, start_delay,
		      1'b0, byte_length};
    @(posedge clock);
  end
endtask

task cbus_dma_read;
  input subblock;
  input down;
  input	[CBUS_DATA_SIZE-1:0] address;
  input	[DMA_DEVICE_SIZE-1:0] device;
  input	[31:0] delay;
  input	[31:0] length;

  reg	[DMA_DELAY_SIZE-1:0] start_delay;
  reg	[DMA_LENGTH_SIZE-1:0] byte_length;
  reg	nseq;

  begin
    start_delay = delay;
    byte_length = length - 1;

    while (!dma_ready)
      @(posedge clock);

`ifdef DEBUG
    $write("dma read ");
    if (subblock)
      $write("subblock ");
    if (down)
      $write("down ");
    else
      $write("up ");
    $write("from 0x%x, length 0%x at time %d\n", address, length, $time);
`endif

    cbus_command <= CBUS_DMA_COMMAND;
    cbus_data_reg <= address;
    @(posedge clock);

    nseq = (subblock || down);
    cbus_command <= CBUS_IDLE_COMMAND;
    cbus_data_reg <= {subblock, 1'b0, down, nseq, device, start_delay,
		      1'b1, byte_length};
    @(posedge clock);
  end
endtask

task dbus_put_data;
  input	[DBUS_DATA_SIZE-1:0] dbus_data_val;
  input	[EBUS_DATA_SIZE-1:0] ebus_data_val;
  input	[31:0] delay;
  begin
     while (!dma_start)
	@(posedge clock);
    repeat(-(2+delay))
	@(posedge clock);
    dbus_data_out <= dbus_data_val;
    ebus_data_out <= ebus_data_val;
    @(posedge clock);
  end
endtask

task dbus_get_data;
  output	[DBUS_DATA_SIZE-1:0] dbus_data_val;
  output	[EBUS_DATA_SIZE-1:0] ebus_data_val;
  input	[31:0] delay;
  integer i;
  begin
    while (!dma_start)
      @(posedge clock);

    repeat(3-delay)
      @(posedge clock);
    dbus_data_val = dbus_data_reg;
    ebus_data_val = ebus_data_reg;
  end
endtask

task initialize_dram;
  begin

    // set reset mode
    cbus_write(BUS_ADDRESS_RI_MODE, {LOW, LOW, RDRAM_RESET_MODE});

    // write the RI current control register
    cbus_write(BUS_ADDRESS_RI_CONFIG, 'b0_001000);

    // wait for the current register to propogate
    repeat (32) @(posedge clock);

    // load current control register
    cbus_write(BUS_ADDRESS_RI_CURRENT_LOAD, 0);

    // set RAC transmit and receive selects
    cbus_write(BUS_ADDRESS_RI_SELECT, {4'b0001, 4'b0100});

    // wait for reset_l to take hold
    repeat (80) @(posedge clock);

    // set standby mode
    cbus_write(BUS_ADDRESS_RI_MODE, {HIGH, HIGH, RDRAM_STANDBY_MODE});

    // Initialize the RDRAM delay register
    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_DELAY | RDRAM_GLOBAL_CONFIG,
		   BUS_DEVICE_MI, -2, 16);
    dbus_put_data({2{'h18_08_28_38}}, 8'hxx, -2);

    repeat (10) @(posedge clock);

    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_RAS_INTERVAL | RDRAM_GLOBAL_CONFIG,
		   BUS_DEVICE_MI, -2, 8);
    dbus_put_data({2{8'd1, 8'd7, 8'd10, 8'd4}}, 8'hxx, -2);

    // configure RDRAM 3

    repeat (10) @(posedge clock);

    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_DEVICE_ID,
		   BUS_DEVICE_MI, -2, 8);
    dbus_put_data({2{RDRAM_3_DEVICE_ID, 3'b0, 8'b0, 8'b0, 8'b0}}, 8'hxx, -2);

    repeat (10) @(posedge clock);

    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_MODE + RDRAM_3_CONFIG,
		   BUS_DEVICE_MI, -2, 8);
    dbus_put_data({2{8'b0000_0010, 8'b0, 8'b0, 8'b0}}, 8'hxx, -2);
    repeat (10) @(posedge clock);

    // configure RDRAM 2

    repeat (10) @(posedge clock);

    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_DEVICE_ID,
		   BUS_DEVICE_MI, -2, 8);
    dbus_put_data({2{RDRAM_2_DEVICE_ID, 3'b0, 8'b0, 8'b0, 8'b0}}, 8'hxx, -2);

    repeat (10) @(posedge clock);

    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_MODE + RDRAM_2_CONFIG,
		   BUS_DEVICE_MI, -2, 8);
    dbus_put_data({2{8'b0000_0010, 8'b0, 8'b0, 8'b0}}, 8'hxx, -2);
    repeat (10) @(posedge clock);

    // configure RDRAM 1

    repeat (10) @(posedge clock);

    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_DEVICE_ID,
		   BUS_DEVICE_MI, -2, 8);
    dbus_put_data({2{RDRAM_1_DEVICE_ID, 3'b0, 8'b0, 8'b0, 8'b0}}, 8'hxx, -2);

    repeat (10) @(posedge clock);

    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_MODE + RDRAM_1_CONFIG,
		   BUS_DEVICE_MI, -2, 8);
    dbus_put_data({2{8'b0000_0010, 8'b0, 8'b0, 8'b0}}, 8'hxx, -2);
    repeat (10) @(posedge clock);

    // configure RDRAM 0

    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_DEVICE_ID,
		   BUS_DEVICE_MI, -2, 8);
    dbus_put_data({2{RDRAM_0_DEVICE_ID, 3'b0, 8'b0, 8'b0, 8'b0}}, 8'hxx, -2);

    repeat (10) @(posedge clock);

    cbus_dma_write(`DMA_UNMASKED, `DMA_UP,
		   BUS_ADDRESS_RDRAM_MODE + RDRAM_0_CONFIG,
		   BUS_DEVICE_MI, -2, 8);
    dbus_put_data({2{8'b0000_0010, 8'b0, 8'b0, 8'b0}}, 8'hxx, -2);

    repeat (10) @(posedge clock);

    // validate the banks before refreshing begins

    cbus_dma_read(`DMA_NOSUBBLOCK, `DMA_UP, BUS_ADDRESS_DRAM + 'h00_0000,
		  BUS_DEVICE_MI, 3, 8);
    while (!dma_start)
      @(posedge clock);

    cbus_dma_read(`DMA_NOSUBBLOCK, `DMA_UP, BUS_ADDRESS_DRAM + 'h10_0000,
		  BUS_DEVICE_MI, 3, 8);
    while (!dma_start)
      @(posedge clock);

    cbus_dma_read(`DMA_NOSUBBLOCK, `DMA_UP, BUS_ADDRESS_DRAM + 'h20_0000,
		  BUS_DEVICE_MI, 3, 8);
    while (!dma_start)
      @(posedge clock);

    cbus_dma_read(`DMA_NOSUBBLOCK, `DMA_UP, BUS_ADDRESS_DRAM + 'h30_0000,
		  BUS_DEVICE_MI, 3, 8);
    while (!dma_start)
      @(posedge clock);

    // enable refresh
    cbus_write(BUS_ADDRESS_RI_REFRESH, 'b1_1_0_00110100_00110010);

    // wait for the post-write-reg delay
    repeat (10) @(posedge clock);
  end
endtask

task check_data;
  input		[7*8:1] test_name;
  input		[DBUS_DATA_SIZE-1:0] expected_d_data, actual_d_data;
  input		[EBUS_DATA_SIZE-1:0] expected_e_data, actual_e_data;

  begin
    if (expected_d_data !== actual_d_data)
    begin
      $write("%s: dbus_data_reg expected: 0x%x was: 0x%x at time %d\n",
	     test_name, expected_d_data, actual_d_data, $time);
      errors = errors + 1;
    end
    if (expected_e_data !== actual_e_data)
    begin
      $write("%s: ebus_data_reg expected: 0x%x was: 0x%x at time %d\n",
	     test_name, expected_e_data, actual_e_data, $time);
      errors = errors + 1;
    end
  end
endtask

task check_unmasked;
  input		[7*8:1] test_name;
  integer	i, j;
  begin
    for (i = 1; i <= `MAX_TRANSFER; i = i + 1)
    begin
      while (!dma_start)
	@(posedge clock);

      for (j = 0; j < (i-1); j = j + 1)
      begin
	if ((j != 0) && dma_start)
	begin
	  $write("%s: dma_start expected: %d was %d at time %d\n",
		  test_name, 1'b1, dma_start, $time);
	  errors = errors + 1;
        end
	@(posedge clock);
      end

      if (!dma_last)
      begin
	$write("%s: dma_last expected: %d was %d at time %d\n",
		test_name, 1'b1, dma_last, $time);
	errors = errors + 1;
      end
      @(posedge clock);
    end
  end
endtask

task check_nosubblock;
  input		[7*8:1] test_name;
  integer	i, j;
  begin
    for (i = 1; i <= `MAX_TRANSFER; i = i + 1)
    begin
      while (!dma_start)
	@(posedge clock);

      for (j = 0; j < (i-1); j = j + 1)
      begin
	if ((j != 0) && dma_start)
	begin
	  $write("%s: dma_start expected: %d was %d at time %d\n",
		  test_name, 1'b1, dma_start, $time);
	  errors = errors + 1;
        end
	@(posedge clock);
      end

      if (!dma_last)
      begin
	$write("%s: dma_last expected: %d was %d at time %d\n",
		test_name, 1'b1, dma_last, $time);
	errors = errors + 1;
      end
      @(posedge clock);
    end
  end
endtask

task check_masked;
  input		[7*8:1] test_name;
  integer	i, j;
  begin
    for (i = 1; i <= `MAX_MASKEDTRANSFER; i = i + 1)
    begin
      while (!dma_start)
	@(posedge clock);

      for (j = 0; j < (i-1); j = j + 1)
      begin
	if ((j != 0) && dma_start)
	begin
	  $write("%s: dma_start expected: %d was %d at time %d\n",
		  test_name, 1'b1, dma_start, $time);
	  errors = errors + 1;
        end
	@(posedge clock);
      end

      if (!dma_last)
      begin
	$write("%s: dma_last expected: %d was %d at time %d\n",
	       test_name, 1'b1, dma_last, $time);
	errors = errors + 1;
      end
      @(posedge clock);
    end
  end
endtask

task check_subblock;
  input		[7*8:1] test_name;
  integer	i, j;
  begin
    for (i = 0; i < 2; i = i + 1)
    begin
      while (!dma_start)
	@(posedge clock);

      for (j = 0; j < (2-1); j = j + 1)
      begin
	if ((j != 0) && dma_start)
	begin
	  $write("%s: dma_start expected: %d was %d at time %d\n",
		  test_name, 1'b1, dma_start, $time);
	  errors = errors + 1;
        end
	@(posedge clock);
      end

      if (!dma_last)
      begin
	$write("%s: dma_last expected: %d was %d at time %d\n",
	       test_name, 1'b1, dma_last, $time);
	errors = errors + 1;
      end
      @(posedge clock);
    end

    for (i = 0; i < 4; i = i + 1)
    begin
      while (!dma_start)
      begin
	@(posedge clock);
      end

      for (j = 0; j < (4-1); j = j + 1)
      begin
	if ((j != 0) && dma_start)
	begin
	  $write("%s: dma_start expected: %d was %d at time %d\n",
		  test_name, 1'b1, dma_start, $time);
	  errors = errors + 1;
        end
	@(posedge clock);
      end

      if (!dma_last)
      begin
	$write("%s: dma_last expected: %d was %d at time %d\n",
	       test_name, 1'b1, dma_last, $time);
	errors = errors + 1;
      end
      @(posedge clock);
    end
  end
endtask

task check_single;
  input		[7*8:1] test_name;
  integer	i, j;

  begin
    for (i = 1; i <= `MAX_TRANSFER; i = i + 1)
    begin
      for (j = 0; j < i; j = j + 1)
      begin
	while (!dma_start)
	  @(posedge clock);
	if (!dma_last)
	begin
	  $write("%s: dma_last expected: %d was %d at time %d\n",
		 test_name, 1'b1, dma_last, $time);
	  errors = errors + 1;
	end
	@(posedge clock);
      end
    end
  end
endtask

task check_refresh;
  input		[7*8:1] test_name;
  integer	got_refresh;
  begin
    got_refresh = 0;

    while (!dma_start)
    begin
      if (c_ctl_ld)
	got_refresh = 1;
      @(posedge clock);
    end
    if (!got_refresh)
    begin
      $write("%s: c_ctl_ld did not go high after refresh (around time %d)\n",
	     test_name, $time);
      errors = errors + 1;
    end
  end
endtask