ms_sm.v 24.6 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 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
 /************************************************************************\
 *                                                                        *
 *               Copyright (C) 1994, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 \************************************************************************/

// $Id: ms_sm.v,v 1.1.1.1 2002/05/17 06:07:47 blythe Exp $
//		rdram state machine for memspan
//	this module performs rdram request/activity/r/w/c/z for 
//	memspan;  attempts to minimize latency between requests;
//	clears requests and controls update flow of pointers/busy flags;
//	shortcuts for write cases of write masks c/z being zero.
//	generation of rbphase, being the rambus access phase to regfile.
//	address/pointer selection for memspan regfile address; rdram phase
//	write enable selection also, for rdram phase.
//	rdram writes into regfile (R) are terminated by finish line from io;
//	regfile writes into rdram (W) are terminated by counter compare here.
//	write requests (from writemask logic, another module) are reset as
//	soon as writemask is output to rdram, this allows unstalling of
//	writemask stall ASAP, overlapping accrual of next wmask with 
//	rdram write activity here.
//	the only use of rbphase here is to control write enable behavior
//	there is no use of stalls here, all rdram state machine activity
//	is non-stallable and should only connect to non-stallable
//	interfaces of other blocks.
//
//	notes:  reads are fn of enreadc/z;  writes implied by creqw/zreqw;
//
//	NOTES FOR JLSMITH:  protocol is READS:  0 delay, WRITES: 2 delay.

//	mods 10-7-94:  stay in wrctxt if (resetc/zreqw) set, and mod rp
//	  so that set c/zreqw has priority over reset;  this way we don't
//	  skip a write beat during reset req and ensure writes before reads.

//	mods 10-11-94:  place all stall inputs here and generate single one out
//		later put all sync stuff in here...and clock stoppage.
//	mods 10-19-94:  stb_sync_full, freeze_gclk, unfreeze_gclk, rel_sync_full
//	mod 10-20-94:  pipe_busy output
//	mod 10-26-94:  init wcount to 1;  add stallnxtwm
//	mod 10-27-94:  buffer rbcwincwr/rbzwincwr for wcount cmp:  wnum
//	11-1	eliminate state_rdcstart/rdzstart? (miss finish)
//		kill steprddone at rdctxt/loop if set
//	11-3   disallow read request until spanproc=0
//	11-14 outport finishd1/finishd2 for si killwe's;
//	11-16 advance selrbc/zw high a state for address init
//	11-23 add start_gclk output, = !stopgclock;  retain latter for my sim env
//	12-1  add steprbptrd1,d2 to delay rdramreq after rdptr update: rdspace
//	12-8  add 3 more states, for c/zwmzero rdram cycle bypass;
//	12-9  add 4th state, bug fix; also add ensteprbc/zwptr;
//	12-13 fix write bypass (sync reset*reqw/steprb*wptr, reset in bypass2);
//	12-16 fix 32b c zbuf case:  add zreqwbuf; fix cwmzero/!zwmzero case;
//	12-20 fix wrzdata-to-rdctxt clear of ensteprbcwptr (32b z tri bug);
//		cleanup state machine transitions
//	12-22 create reset_ld as delayed reset, to stopgclock generation;
//	12-28 create delayread to guarantee rbc/zrinc settling before dma read request;
//	1-4 add stopgclockd, output to ms_debug for observation;
//	1-10 reset to zero:  wnum, wcount for synthesis reasons;
//	1-12 add spanprocd register, to fix rdspace latency issue;
//		remove delayread, which was not sufficent solution.
//	2-2  generate/output start4ms for back-to-back dma fix;


module ms_sm(clock, reset_l, rdspace, rdenreadc, rdenreadz,
	grant, start, finish,
	creqw, zreqw, cwmzero, zwmzero, rddone, smcwincwr, smzwincwr,
	stallphase, stallrw, stallrdctxt, stallwrctxt, stallptr,
	stallczwm, stb_sync_full, freeze_gclk, unfreeze_gclk, stallnxtwm,
	spanproc,

	steprddone, finishd1, finishd2,
	rdramreqcr, rdramreqzr, rdramreqcw, rdramreqzw,
	enrbwe, selrbcr, selrbzr, stopgclockd, start4ms,
	selrbcw, selrbzw, selcwmask, selzwmask, resetcreqw, resetzreqw,
	steprbcrptr, steprbzrptr, steprbcwptr, steprbzwptr, rbphase,
	start_gclk, stopgclock, rel_sync_full, pipe_busy);

`include "ms.vh"

input clock;					// system clock
input reset_l;					// system reset

input rdspace;					//space is avail for next dmard
input rdenreadc;				//rdctxt enrdcolor
input rdenreadz;				//rdctxt enrddepth 
input grant;					//dma grant
input start;					//dma valid (0/2 delay r/w)
input finish;					//dma last data cycle
input creqw;					//color write request
input zreqw;					//depth write request
input cwmzero;					//color wmask is all zero's
input zwmzero;					//depth wmask is all zero's
input rddone;
input [3:0] smcwincwr;				//number of regfile 36b entries
input [3:0] smzwincwr;				//per current spanlet 1-16 ??

input stallphase, stallrw, stallrdctxt, stallwrctxt;
input stallptr, stallczwm;
input stb_sync_full, freeze_gclk, unfreeze_gclk;
input stallnxtwm;
input spanproc;

output steprddone;
output finishd1, finishd2;
output rdramreqcr;                              //dma request
output rdramreqzr;                               //dma request
output rdramreqcw;                               //dma request
output rdramreqzw;                               //dma request
output enrbwe;					//regfile we for rdram activity
output selrbcr;					//sel rf addr for rdram c rd
output selrbzr;					//sel rf addr for rdram z rd
output selrbcw;                                 //sel rf addr for rdram c wr
output selrbzw;                                 //sel rf addr for rdram z wr
output selcwmask;
output selzwmask;
output resetcreqw;				//clear write request (color)
output resetzreqw;				//clear write request (depth)
output steprbcrptr;
output steprbzrptr;
output steprbcwptr;
output steprbzwptr;
output rbphase;

output start4ms;
output stopgclock;
output start_gclk;
output rel_sync_full;
output pipe_busy;
output stopgclockd;

// input/output registers

reg finishd1;
reg steprbcrptr;
reg steprbzrptr;
reg steprbcwptr;
reg steprbzwptr;
reg enrbwe;
reg rdramreqcr;
reg rdramreqzr;
reg rdramreqcw;
reg rdramreqzw;
reg steprddone;
reg selrbcr;
reg selrbzr;
reg selrbcw;
reg selrbzw;
reg selcwmask;
reg selzwmask;
reg resetcreqw;
reg resetzreqw;
reg rel_sync_full, rel_sync_fulld, freeze_gclkd;
reg fullsyncreq;

reg steprbptrd1, steprbptrd2;
reg ensteprbcwptr, ensteprbzwptr;
reg stopgclockd;

// internal registers
reg finishd2;
reg [3:0] wcount, wnum;
reg rbphase;
reg zreqwbuf;
reg reset_ld;
reg spanprocd;

// pseudo registers

reg stopgclock;
reg pipe_busy;

// wires

wire start_gclk;
wire start4ms;
assign start_gclk = !stopgclock;

// rdram state machine
reg [21:0] state;
parameter

   state_rdctxt			= 22'h1,
   state_rdcreq			= 22'h2,
   state_rdcwait		= 22'h4,
   state_rdcdata		= 22'h10,
   state_rdzreq			= 22'h20,
   state_rdzwait		= 22'h40,
   state_rdzdata		= 22'h100,
   state_wrctxt			= 22'h200,
   state_wrcreq			= 22'h400,
   state_wrcwait		= 22'h800,
   state_wrcstart		= 22'h1000,
   state_wrcdata		= 22'h2000,
   state_wrzreq			= 22'h4000,
   state_wrzwait		= 22'h8000,
   state_wrzstart		= 22'h10000,
   state_wrzdata		= 22'h20000,
   state_bypass1		= 22'h40000,
   state_bypass2		= 22'h80000,
   state_bypass3		= 22'h100000,
   state_bypass4		= 22'h200000;

assign start4ms = ((state == state_rdcwait) || (state == state_rdzwait) ||
                        (state == state_wrcwait) ||
                        (state == state_wrzwait));
   
// synopsys translate_off
`ifdef MSPAN_MON
reg [6:0] rdctxt_arcs;
reg [3:0] rdcdata_arcs;
reg [2:0] rdzdata_arcs;

reg [9:0] wrctxt_arcs;
reg [3:0] wrcdata_arcs;
reg [1:0] wrzdata_arcs;
`endif
// synopsys translate_on

//stall OR'ing

always @(stallphase or stallrw or stallrdctxt or stallwrctxt or
  stallptr or stallczwm or freeze_gclkd or rel_sync_fulld or
		stallnxtwm or reset_ld) begin

	stopgclock <= #1 (stallphase || stallrw || stallrdctxt || stallwrctxt ||
	  stallptr || stallczwm || freeze_gclkd || rel_sync_fulld ||
			stallnxtwm) & reset_ld;
end

always @(rel_sync_fulld) begin
	pipe_busy <= (!rel_sync_fulld);
end

always @(posedge clock or negedge reset_l) begin
   if (!reset_l) begin
      // resettable registers
      enrbwe <= low;
      reset_ld <= low;
      rdramreqcr <= low;
      rdramreqzr <= low;
      rdramreqcw <= low;
      rdramreqzw <= low;
      	steprbptrd1 <= low;
      	steprbptrd2 <= low;
      steprbcrptr <= low;
      steprbzrptr <= low;
      steprbcwptr <= low;
      steprbzwptr <= low;
      steprddone <= low;
      state <= state_rdctxt;
	ensteprbcwptr <= low;
	ensteprbzwptr <= low;
      rbphase <= high;
      resetcreqw <= high;
      resetzreqw <= high;
      freeze_gclkd <= low;
      rel_sync_full <= low;
      rel_sync_fulld <= low;
      fullsyncreq <= low;
	selcwmask <= low;
	selzwmask <= low;
	selrbcr <= low;
	selrbzr <= low;
	selrbcw <= low;
	selrbzw <= low;
	zreqwbuf <= low;
	spanprocd <= low;
	stopgclockd <= low;
//nonresettable registers
	wcount <= 4'b0;
	wnum <= 4'b0;
	finishd1 <= 'bx;
	finishd2 <= 'bx;
// synopsys translate_off
`ifdef MSPAN_MON
	rdctxt_arcs <= 7'b0;
	rdcdata_arcs <= 4'b0;
	rdzdata_arcs <= 3'b0;
	wrctxt_arcs <= 10'b0;
	wrcdata_arcs <= 4'b0;
	wrzdata_arcs <= 2'b0;
`endif
// synopsys translate_on
      end
   else begin
	reset_ld <= high;
	stopgclockd <= stopgclock;
	steprbptrd2 <= steprbptrd1;
	steprbptrd1 <= (steprbcrptr || steprbzrptr);
	finishd2 <= finishd1;
	finishd1 <= finish;
	rbphase  <= !rbphase;
	freeze_gclkd <= freeze_gclk;
	rel_sync_fulld <= rel_sync_full;

      //strobe full sync state machine
if (stb_sync_full) begin
	fullsyncreq <= high;
end
else if (fullsyncreq & !(creqw || zreqw || resetcreqw || resetzreqw)) begin
        fullsyncreq <= low;
end
else begin
	fullsyncreq <= fullsyncreq;
end

if (fullsyncreq & !(creqw || zreqw || resetcreqw || resetzreqw)) begin
	rel_sync_full <= high;
end
else if (unfreeze_gclk) begin
	rel_sync_full <= low;
end
else begin
	rel_sync_full <= rel_sync_full;
end

	spanprocd <= spanproc;

      // rdram state machine
      case (state)

//				rdspace <= 1 iff space for both c/z read
//                               (if one plane, define both same size)
//					and reads enabled..
//				rddone <= 1 iff no span in rdctxt
//				 set init, and set when decomp last spanlet
//   tbd:  wrptrs must update during reads if no writes enabled;
//	therefore:  disable all stalls "not applicable".

// question:  are we cycling thru rdctxt even if write only, to make space?
//	answer:  no.  below, we define rdspace=0 for this case.
//	although...can just interlock with passing of address to rmwctxt...
//	and set rddone then if !(enreadc + enreadz), similar approach for wr.

//summary:  if load, then update wrptrs whenever update rdptrs;
//	cases:
//		read	write	crptr	zrptr	cwptr	zwptr
//			c	wc		wc
//			cz	wc	wz	wc	wz
//		c	c	rc		wc
//		c	cz	rc	wz	wc	wz	
//		z	c	wc	rz	wc	rz	
//		z	cz	wc	rz	wc	wz
//		cz	c	rc	rz	wc	rz
//		cz	cz	rc	rz	wc	wz
//		c		rc		rc	
//	also, if write only op, disable read stalls and update read ptrs
//	whenever we update write ptrs. etc. 
//		therefore "rdspace" is zero when no reads invoked
//	9/24/94:  actually the above solved instead by setting rddone at t4;
//		whereas creqw/zreqw never set for loads
//	9/24/94:  ...and also wrdone is set if no writes....also at startspan;
//	therefore must flush betw.  all c/z r/w mode changes.
//	9/24/94:  still true, because r,w pointer update slips pipe for w,r
//		only cases, respectively...

	state_rdctxt : begin
                        steprbcrptr <= low;
                        steprbzrptr <= low;
                        steprbcwptr <= low;
                        steprbzwptr <= low;
                        steprddone <= low;
			resetcreqw <= low;
			resetzreqw <= low;
	  if (spanproc || spanprocd || steprddone || steprbcrptr || steprbzrptr) begin
			state <= state_rdctxt;
// synopsys translate_off
`ifdef MSPAN_MON
rdctxt_arcs <= { 1'b1 | rdctxt_arcs };		    // A
`endif
// synopsys translate_on
		end
                else if (creqw || zreqw) begin
                        state <= state_wrctxt;
// synopsys translate_off
`ifdef MSPAN_MON
rdctxt_arcs <= { { 1'b1, 1'b0 } | rdctxt_arcs };    // B
`endif
// synopsys translate_on
                        end
		else if ((!rdspace || rddone) & ! (creqw || zreqw)) begin
			state <= state_rdctxt;
// synopsys translate_off
`ifdef MSPAN_MON
rdctxt_arcs <= { { 1'b1, 2'b0 } | rdctxt_arcs };    // C
`endif
// synopsys translate_on
			end
		else if (rdspace & !rddone & rdenreadc & !(steprbptrd1 || steprbptrd2)) begin
			state <= state_rdcreq;
// synopsys translate_off
`ifdef MSPAN_MON
rdctxt_arcs <= { { 1'b1, 3'b0 } | rdctxt_arcs };    // D
`endif
// synopsys translate_on
			rdramreqcr <= high;
		//	send out addr/len/dir/rw
			end
		else if (rdspace & !rddone & rdenreadz & !(steprbptrd1 || steprbptrd2)) begin
			state <= state_rdzreq;
// synopsys translate_off
`ifdef MSPAN_MON
rdctxt_arcs <= { { 1'b1, 4'b0 } | rdctxt_arcs };    // E
`endif
// synopsys translate_on
			rdramreqzr <= high;
                //      send out addr/len/dir/rw
			end
		else if ((rdspace & !rddone) & !(rdenreadz || rdenreadc) &
		  ! (creqw || zreqw)) begin
                        state <= state_rdctxt;
// synopsys translate_off
`ifdef MSPAN_MON
rdctxt_arcs <= { { 1'b1, 5'b0 } | rdctxt_arcs };    // F
`endif
// synopsys translate_on
                        end
		else begin
			state <= state_rdctxt;
// synopsys translate_off
`ifdef MSPAN_MON
rdctxt_arcs <= { { 1'b1, 6'b0 } | rdctxt_arcs };    // G
`endif
// synopsys translate_on
			end
		end

	state_rdcreq : begin
		if (grant) begin
			state <= state_rdcwait;
			rdramreqcr <= low;
			selrbcr <= high;
			end
		else if (!grant) begin
			state <= state_rdcreq;
			end
		end

	state_rdcwait : begin
                if (start) begin
                        state <= state_rdcdata;
			enrbwe <= high;
			selrbcr <= low;
		//	rbaddr <= rbptrcr; 	
                        end
                else if (!start) begin
                        state <= state_rdcwait;
                        end
                end

	state_rdcdata : begin
                if ((rbphase & (finishd1 || finishd2)) & !rdenreadz & (creqw || zreqw)) begin
                        state <= state_wrctxt;
// synopsys translate_off
`ifdef MSPAN_MON
rdcdata_arcs <= { 1'b1 | rdcdata_arcs };	    // A
`endif
// synopsys translate_on
			enrbwe <= low;
                        steprbcrptr <= high;
                        steprddone <= high;

        //      update read pointers
                        end
                else if ((rbphase & (finishd1 || finishd2)) & !rdenreadz & !(creqw || zreqw)) begin
                        state <= state_rdctxt;
// synopsys translate_off
`ifdef MSPAN_MON
rdcdata_arcs <= { { 1'b1, 1'b0 } | rdcdata_arcs };  // B
`endif
// synopsys translate_on
                        enrbwe <= low;
                        steprbcrptr <= high;
                        steprddone <= high;

        //      update read pointers
                        end

		else if ((rbphase & (finishd1 || finishd2)) & rdenreadz) begin
			state <= state_rdzreq;
// synopsys translate_off
`ifdef MSPAN_MON
rdcdata_arcs <= { { 1'b1, 2'b0 } | rdcdata_arcs };  // C
`endif
// synopsys translate_on
                        enrbwe <= low;
			steprbcrptr <= high;
			rdramreqzr <= high;
                //      send out addr/len/dir/rw
			end
                else if (!(rbphase & (finishd1 || finishd2))) begin
                        state <= state_rdcdata;
// synopsys translate_off
`ifdef MSPAN_MON
rdcdata_arcs <= { { 1'b1, 3'b0 } | rdcdata_arcs };  // D
`endif
// synopsys translate_on
                        end
                end

	state_rdzreq : begin
			steprbcrptr <= low;
                if (grant) begin
                        state <= state_rdzwait;
			rdramreqzr <= low;
                        selrbzr <= high;
                        end
                else if (!grant) begin
                        state <= state_rdzreq;
                        end
                end

	state_rdzwait : begin
                if (start) begin
			selrbzr <= low;
                        state <= state_rdzdata;
			enrbwe <= high;
                        end
                else if (!start) begin
                        state <= state_rdzwait;
                        end
                end

	state_rdzdata : begin
                if (rbphase & (creqw || zreqw) & (finishd1 || finishd2))  begin
                        state <= state_wrctxt;
// synopsys translate_off
`ifdef MSPAN_MON
rdzdata_arcs <= { 1'b1 | rdzdata_arcs };	    // A
`endif
// synopsys translate_on
                        enrbwe <= low;
                        steprbzrptr <= high;
                        steprddone <= high;

	//  	update read pointers
                        end
		else if (rbphase & !(creqw || zreqw) & (finishd1 || finishd2))  begin
                        state <= state_rdctxt;
// synopsys translate_off
`ifdef MSPAN_MON
rdzdata_arcs <= { { 1'b1, 1'b0 } | rdzdata_arcs };  // B
`endif
// synopsys translate_on
                        enrbwe <= low;
                        steprbzrptr <= high;
                        steprddone <= high;

			end
                else if (!(rbphase & (finishd1 || finishd2))) begin
                        state <= state_rdzdata;
// synopsys translate_off
`ifdef MSPAN_MON
rdzdata_arcs <= { { 1'b1, 2'b0 } | rdzdata_arcs };  // C
`endif
// synopsys translate_on
                        end
                end

// note:  spanoverlap may need to handle 3 prims, as we might be able to
//read for span 3 while not yet written span 1 (primitive is 22 clks min)
//e.g. might have two prims in wrctxt wmask/addr bufs, and 2-3? in pipe ~21
//clks from ew to readz rdp...

	state_wrctxt : begin
                        steprbcrptr <= low;
                        steprbzrptr <= low;
                        steprbcwptr <= low;
                        steprbzwptr <= low;
                        steprddone <= low;
			resetcreqw <= low;
			resetzreqw <= low;
		if (resetcreqw || resetzreqw || steprbcwptr || steprbcrptr ||
		 steprbzwptr || steprbzrptr) begin
			state <= state_wrctxt;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { 1'b1 | wrctxt_arcs };		    // A
`endif
// synopsys translate_on
		end
		else if (creqw  & !cwmzero) begin
			state <= state_wrcreq;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { { 1'b1, 1'b0 } | wrctxt_arcs };    // B
`endif
// synopsys translate_on
			zreqwbuf <= zreqw;
			rdramreqcw <= high;
                //      send out addr/len/dir/rw
			end
		else if (creqw  & cwmzero & zreqw  & !zwmzero) begin
			state <= state_wrzreq;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { { 1'b1, 2'b0 } | wrctxt_arcs };    // C
`endif
// synopsys translate_on
			rdramreqzw <= high;
			ensteprbcwptr <= high;
			end
                else if ((creqw  & cwmzero & zreqw  & zwmzero)) begin
                        state <= state_bypass1;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { { 1'b1, 3'b0 } | wrctxt_arcs };    // D
`endif
// synopsys translate_on
                        ensteprbcwptr <= high;
                        ensteprbzwptr <= high;
                        end
                else if ((creqw  & cwmzero & !zreqw )) begin
                        state <= state_bypass1;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { { 1'b1, 4'b0 } | wrctxt_arcs };    // E
`endif
// synopsys translate_on
//                        resetcreqw <= high;
                        ensteprbcwptr <= high;
                        end
		else if (!creqw  & zreqw  & !zwmzero) begin
                        state <= state_wrzreq;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { { 1'b1, 5'b0 } | wrctxt_arcs };    // F
`endif
// synopsys translate_on
                        rdramreqzw <= high;
                        end
                else if ((!creqw  & zreqw  & zwmzero)) begin
                        state <= state_bypass1;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { { 1'b1, 6'b0 } | wrctxt_arcs };    // G
`endif
// synopsys translate_on
                        ensteprbzwptr <= high;
                        end             
                else if (!(creqw  || zreqw ) & (!rdspace || rddone)) begin
                        state <= state_wrctxt;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { { 1'b1, 7'b0 } | wrctxt_arcs };    // H
`endif
// synopsys translate_on
                        end
                else if (!(creqw  || zreqw ) & (rdspace & !rddone) &
				(rdenreadc || rdenreadz)) begin
                        state <= state_rdctxt;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { { 1'b1, 8'b0 } | wrctxt_arcs };    // I
`endif
// synopsys translate_on
                        end
		else begin
			state <= state_wrctxt;
// synopsys translate_off
`ifdef MSPAN_MON
wrctxt_arcs <= { { 1'b1, 9'b0 } | wrctxt_arcs };    // J
`endif
// synopsys translate_on
		end
	end

	state_wrcreq : begin
		if (grant) begin
			state <= state_wrcwait;
			rdramreqcw <= low;
			selrbcw <= high;
			end
		else if (!grant) begin
			state <= state_wrcreq;
			end
		end

	state_wrcwait : begin
		if (start) begin
			state <= state_wrcstart;
			selcwmask <= high;
			wcount <= 4'h1;
			wnum <= smcwincwr;
			resetcreqw <= high;
			end
		else if (!start) begin
			state <= state_wrcwait;
			end
		end

	state_wrcstart : begin
			state <= state_wrcdata;
			selcwmask <= low;
			selrbcw <= low;
			resetcreqw <= low;
		end

	state_wrcdata : begin
		if ((wcount == wnum) & zreqwbuf  & !zwmzero) begin
			state <= state_wrzreq;
// synopsys translate_off
`ifdef MSPAN_MON
wrcdata_arcs <= { 1'b1 | wrcdata_arcs };	    // A
`endif
// synopsys translate_on
			steprbcwptr <= high;
                        rdramreqzw <= high;
                //      send out addr/len/dir/rw
                        end
		else if (((wcount == wnum) & zreqwbuf  & zwmzero)) begin
			state <= state_bypass1;
// synopsys translate_off
`ifdef MSPAN_MON
wrcdata_arcs <= { { 1'b1, 1'b0 } | wrcdata_arcs };  // B
`endif
// synopsys translate_on
			resetzreqw <= high;
                        steprbcwptr <= high;
                        steprbzwptr <= high;
			end
                else if (((wcount == wnum) & !zreqwbuf )) begin
                        state <= state_wrctxt;
// synopsys translate_off
`ifdef MSPAN_MON
wrcdata_arcs <= { { 1'b1, 2'b0 } | wrcdata_arcs };  // C
`endif
// synopsys translate_on
                        steprbcwptr <= high;
                        end
		else if (!(wcount == wnum)) begin
			state <= state_wrcdata;
// synopsys translate_off
`ifdef MSPAN_MON
wrcdata_arcs <= { { 1'b1, 3'b0 } | wrcdata_arcs };  // D
`endif
// synopsys translate_on
			wcount <= wcount + 1;
			end
                end

	state_wrzreq : begin
			steprbcwptr <= low;
			resetcreqw <= low;
		if (grant) begin
			state <= state_wrzwait;
			rdramreqzw <= low;
			selrbzw <= high;
			end
		else if (!grant) begin
			state <= state_wrzreq;
			end
		end

	state_wrzwait : begin
		if (start) begin
			state <= state_wrzstart;
//			selrbzw <= high;
			selzwmask <= high;
			wcount <= 4'h1;
			wnum <= smzwincwr;
			resetzreqw <= high;
			resetcreqw <= ensteprbcwptr;
			end
		else if (!start) begin
			state <= state_wrzwait;
			end
		end			

	state_wrzstart : begin
			state <= state_wrzdata;
			selrbzw <= low;
			selzwmask <= low;
			resetzreqw <= low;
			resetcreqw <= low;
		end

	state_wrzdata : begin
		if ((wcount == wnum)) begin
			state <= state_wrctxt;
// synopsys translate_off
`ifdef MSPAN_MON
wrzdata_arcs <= { 1'b1 | wrzdata_arcs };	    // A
`endif
// synopsys translate_on
                        steprbzwptr <= high;
			steprbcwptr <= ensteprbcwptr;
			ensteprbcwptr <= low;
			end
		else if (!(wcount == wnum)) begin
			state <= state_wrzdata;
// synopsys translate_off
`ifdef MSPAN_MON
wrzdata_arcs <= { { 1'b1, 1'b0 } | wrzdata_arcs };  // B
`endif
// synopsys translate_on
			wcount <= wcount + 1;
			end
		end

//new states for write bypass, to ensure pointers settle before nxt stepping

	state_bypass1 : begin
			steprbzwptr <= ensteprbzwptr;
			steprbcwptr <= ensteprbcwptr;
			ensteprbzwptr <= low;
			ensteprbcwptr <= low;
			resetcreqw <= ensteprbcwptr;
			resetzreqw <= ensteprbzwptr;
			state <= state_bypass2;
		end
        state_bypass2 : begin
                        state <= state_bypass3;
                        steprbzwptr <= low;
                        steprbcwptr <= low;
                        resetcreqw <= low;
                        resetzreqw <= low;
                end
        state_bypass3 : begin
                        state <= state_bypass4;
                end
        state_bypass4 : begin
                        state <= state_wrctxt;
                end
	
		default :
			state <= 22'bx;

         endcase
      end
   end
endmodule