`define RESERVED 4'b0000 `define request_block 4'b0001 `define ack_request 4'b0010 `define byte_there 4'b0011 `define start_transfer 4'b0100 `define done_transfer 4'b0101 `define done_block 4'b0111 `define start_IMDCT 4'b1100 `define done_IMDCT 4'b1110 //Just for semantical differences. I use `null for communication required // signals and `idle for saying that "we're not doing anything here." // (Eric) `define idle 4'b1111 `define null 4'b1111 `define down 1'b0 `define up 1'b1 `define no 1'b0 `define yes 1'b1 `define set 1'b1 `define unset 1'b0 `define done 1'b1 //For SEND_BYTE and READ_BYTE //if db is 0 go out on data //if db is A go out on ctrl to parent //if db is 7E read in on ctrl from parent //if db is 1 data direction register (ignore) `define ADDR_DATA 16'h0000 `define ADDR_CIN 16'h000a `define ADDR_COUT 16'h007e `define ADDR_DDR 16'h0001 (ignore) module router(reset,clk,from_parent,from_child_0,from_child_1,to_parent,to_child_0,to_child_1,data_parent,data_child_0,data_child_1,state_output); input reset; input clk; input [3:0] from_parent; input [3:0] from_child_0; input [3:0] from_child_1; output [3:0] to_parent; output [3:0] to_child_0; output [3:0] to_child_1; output [7:0] state_output; inout [7:0] data_parent; inout [7:0] data_child_0; inout [7:0] data_child_1; reg child_0_running,child_1_running,child_up_down,first_byte, do_IMDCT,IMDCT_child; wire [7:0] both_ctrl; reg last_child_run,we_data_parent,we_data_child_0,we_data_child_1,error_state,child_done; reg [3:0] to_parent,to_child_0,to_child_1,to_child_0_last, to_child_1_last,to_parent_last; reg [7:0] data_to_child_0,data_to_child_1,data_to_parent,child_state,data_to_child_0_last,data_to_child_1_last,data_to_parent_last; reg [287:0] data_to_imdct; reg [6:0] debug_state_output; wire [6:0] debug_state; //The below will be removed when the imdct module is instantiated wire from_imdct; assign both_ctrl = {from_child_0,from_child_1}; //Write_enables are all asserted HIGH! assign data_child_0 = (we_data_child_0) ? data_to_child_0 : 8'bz; assign data_child_1 = (we_data_child_1) ? data_to_child_1 : 8'bz; assign data_parent = (we_data_parent) ? data_to_parent : 8'bz; //assign state_output = (error_state) ? {error_state,debug_state} : {error_state, debug_state}; //assign debug_state = (error_state) ? debug_state : debug_state_output; //assign state_output = {error_state,debug_state_output}; assign state_output = child_state; /* A Router on power-up will: * 1) wait for reset to be de-asserted * 2) monitor its children for requested blocks/done_blocks * 3) as necessary forward these requests to its parent * 4) chec */ always @(posedge clk) begin if (reset)//reset is asserted LOW begin //$display("!reset ",reset); to_child_0_last <= to_child_0; to_child_1_last <= to_child_1; to_parent_last <= to_parent; data_to_child_0_last <= data_to_child_0; data_to_child_1_last <= data_to_child_1; data_to_parent_last <= data_to_parent; //do_IMDCT is completly seperate from child_X_running //one child can be running (transferring data) at the same time // that the other is doing IMDCT if (do_IMDCT) begin //Do nothing for now. do_IMDCT <= `no; /* On assertion, should: * 1) begin read data sequence of byte_there's * 2) assert `null when done, and exit read data sequence * 3) start IMDCT process (seperate module) * 4) wait for IMDCT module to assert that it's done * 5) assert done_IMDCT to child when finished * 6) set do_IMDCT to `no */ end // if (do_IMDCT) //else if ( //We DON'T want to start_IMDCT if it is already running! //This isn't fair ATM, it just chooses child_0 if it's ready, // but it needs TO BE made fair at some point else if (from_child_0 == `start_IMDCT) begin do_IMDCT <= `yes; IMDCT_child <= 1'b0; @(posedge clk) data_to_imdct[287:280] <= data_child_0; //et all.. end else if (from_child_1 == `start_IMDCT) begin do_IMDCT <= `yes; IMDCT_child <= 1'b1; end if (from_imdct == `done) begin end if (child_0_running) begin to_child_1 <= `idle; we_data_child_1 <= `no; data_to_child_1 <= 8'b0; //$display("Starting Child_0 run ", child_state); //Be sure to uncomment this before enabling child_1 !! last_child_run <= 1'b0; /* child_state docs: * first two bits 00 == download * first two bits 01 == upload */ if (child_state == 8'b00000000) begin //start child_0 comm //$display("State = 8'b00000000"); we_data_child_0 <= `no; we_data_parent <= `no; if (from_child_0 == `request_block) begin //$display("Going to state: 8'b00000001"); child_state <= 8'b00000001; to_child_0 <= `null; to_parent <= `request_block; end else if (from_child_0 == `done_block) begin //$display("Going to state: 8'b01000001"); child_state <= 8'b01000001; to_child_0 <= `null; to_parent <= `done_block; end else if (from_child_0 == `null) begin child_state <= 8'b00000000; to_child_0 <= `null; to_parent <= `null; //$display("Shouldn't be here ", from_child_0," ", from_parent); end else begin child_state <= 8'b00000000; to_child_0 <= `null; to_parent <= `null; $display("Invalid starting code from child_0 ", from_child_0); end end // if (child_state == 8'b00000000) else if (child_state == 8'b00000001) begin //$display("State = 8'b00000001"); we_data_child_0 <= `no; we_data_parent <= `no; if (from_parent == `ack_request) begin child_state <= 8'b00000010; to_child_0 <= `ack_request; to_parent <= `request_block; end else if (from_parent == `null) begin child_state <= 8'b00000001; to_child_0 <= `null; to_parent <= `request_block; end else begin child_state <= 8'b00000001; to_child_0 <= `null; to_parent <= `request_block; $display("Invalid response by parent to `request_block ", from_parent); end end // if (child_state == 8'b00000001) else if (child_state == 8'b00000010) begin we_data_child_0 <= `no; we_data_parent <= `no; if (from_child_0 == `null) begin child_state <= 8'b00000100; to_child_0 <= `ack_request; to_parent <= `null; end else if (from_child_0 == `request_block) begin child_state <= 8'b00000010; to_child_0 <= `ack_request; to_parent <= `request_block; end else begin child_state <= 8'b00000010; to_child_0 <= `ack_request; to_parent <= `request_block; $display("Invalid response by child_0 to `ack_request ", from_child_0); end // else: !if(from_child_0 == `request_block) end // if (child_state == 8'b00000010) //OK, so I skipped a state number here, // So sue me // -Eric else if (child_state == 8'b00000100) begin we_data_parent <= `no; if (from_parent == `byte_there) begin child_state <= 8'b00000101; to_child_0 <= `byte_there; to_parent <= `null; we_data_child_0 <= `yes; $display("Shifting first byte"); // This is the first byte sent, so we're going to shift // out a number. We're supposed to use it to pick child, // but our state already does this, so it's kinda // pointless when going down data_to_child_0 <= {1'b0,data_parent[7:1]}; end else if (from_parent == `ack_request) begin child_state <= 8'b00000100; to_child_0 <= `ack_request; to_parent <= `null; we_data_child_0 <= `no; end else begin child_state <= 8'b00000100; to_child_0 <= `ack_request; to_parent <= `null; we_data_child_0 <= `no; $display("Invalid response by parent to `null after ack_request ", from_parent); end // else: !if(from_parent == `ack_request) end // if (child_state == 8'b00000100) else if (child_state == 8'b00000101) begin we_data_parent <= `no; if (from_child_0 == `byte_there) begin // Held over from last clock, until it is acked (right now) we_data_child_0 <= `yes; $display("Byte acked"); //$display("Still Holding Data"); data_to_child_0 <= data_to_child_0_last; child_state <= 8'b00000110; to_child_0 <= `byte_there; to_parent <= `byte_there; end else if (from_child_0 == `null) begin we_data_child_0 <= `yes; //$display("Holding Data 0"); data_to_child_0 <= data_to_child_0_last; child_state <= 8'b00000101; to_child_0 <= `byte_there; to_parent <= `null; end else begin we_data_child_0 <= `yes; data_to_child_0 <= data_to_child_0_last; child_state <= 8'b00000101; to_child_0 <= `byte_there; to_parent <= `null; $display("Invalid response by child_0 to `byte_there ", from_child_0); end // else: !if(from_child_0 == `null) end // if (child_state == 8'b00000101) else if (child_state == 8'b00000110) begin //The child has acked the data by this point //but holding the data just in case we_data_parent <= `no; if (from_parent == `null) begin we_data_child_0 <= `no; child_state <= 8'b00000111; to_child_0 <= `null; to_parent <= `byte_there; end else if (from_parent == `byte_there) begin we_data_child_0 <= `yes; //$display("Holding Data 1"); data_to_child_0 <= data_to_child_0_last; child_state <= 8'b00000110; to_child_0 <= `byte_there; to_parent <= `byte_there; end else begin we_data_child_0 <= `yes; data_to_child_0 <= data_to_child_0_last; child_state <= 8'b00000110; to_child_0 <= `byte_there; to_parent <= `byte_there; $display("Invalid response by parent to `byte_there ", from_parent); end // else: !if(from_parent == `byte_there) end // if (child_state == 8'b00000110) else if (child_state == 8'b00000111) begin we_data_child_0 <= `no; we_data_parent <= `no; if (from_child_0 == `null) begin child_state <= 8'b00001000; to_child_0 <= `null; to_parent <= `null; end else if (from_child_0 == `byte_there) begin child_state <= 8'b00000111; to_child_0 <= `null; to_parent <= `byte_there; end else begin child_state <= 8'b00000111; to_child_0 <= `null; to_parent <= `byte_there; $display("Invalid response by child_0 to `null after byte_there ", from_child_0); end // else: !if(from_parent == `byte_there) end // if (child_state == 8'b00000111) else if (child_state == 8'b00001000) begin we_data_parent <= `no; if (from_parent == `done_transfer) begin we_data_child_0 <= `no; child_state <= 8'b00001001; to_child_0 <= `done_transfer; to_parent <= `null; end else if (from_parent == `byte_there) begin we_data_child_0 <= `yes; $display("Another Byte, mmmmmm.."); data_to_child_0 <= data_parent; child_state <= 8'b00000101; to_child_0 <= `byte_there; to_parent <= `null; end else if (from_parent == `null) begin we_data_child_0 <= `no; child_state <= 8'b00001000; to_child_0 <= `null; to_parent <= `null; end else begin we_data_child_0 <= `no; child_state <= 8'b00001000; to_child_0 <= `null; to_parent <= `null; $display("Invalid response by parent to `null after byte_there ", from_parent); end end // if (child_state == 8b'00001000) else if (child_state == 8'b00001001) begin we_data_child_0 <= `no; we_data_parent <= `no; if (from_child_0 == `done_transfer) begin child_state <= 8'b00001010; to_child_0 <= `done_transfer; to_parent <= `done_transfer; end else if (from_child_0 == `null) begin child_state <= 8'b00001001; to_child_0 <= `done_transfer; to_parent <= `null; end else begin child_state <= 8'b00001001; to_child_0 <= `done_transfer; to_parent <= `null; $display("Invalid response by child_0 to `done_transfer ", from_child_0); end // else: !if(from_child_0 == `null) end // if (child_state == 8'b00001001) else if (child_state == 8'b00001010) begin we_data_child_0 <= `no; we_data_parent <= `no; if (from_parent == `null) begin child_state <= 8'b00001011; to_child_0 <= `null; to_parent <= `done_transfer; end else if (from_parent == `done_transfer) begin child_state <= 8'b00001010; to_child_0 <= `done_transfer; to_parent <= `done_transfer; end else begin child_state <= 8'b00001010; to_child_0 <= `done_transfer; to_parent <= `done_transfer; $display("Invalid response by parent to `done_transfer ", from_parent); end end // if (child_state == 8'b00001010) else if (child_state == 8'b00001011) begin we_data_child_0 <= `no; we_data_parent <= `no; if (from_child_0 == `null) begin //We're Done with this download child_state <= 8'b00000000; to_child_0 <= `null; to_parent <= `null; child_0_running <= 1'b0; end else if (from_child_0 == `done_transfer) begin child_state <= 8'b00001011; to_child_0 <= `null; to_parent <= `done_transfer; end else begin child_state <= 8'b00001011; to_child_0 <= `null; to_parent <= `done_transfer; $display("Invalid response by child_0 to `null after done_transfer ", from_child_0); end // else: !if(from_child == `done_transfer) end // if (child_state == 8b'00001011) else if (child_state == 8'b01000001) begin we_data_child_0 <= `no; we_data_parent <= `no; //$display("State 8'b01000001"); if (from_parent == `start_transfer) begin child_state <= 8'b01000010; to_child_0 <= `start_transfer; to_parent <= `done_block; end else if (from_parent == `null) begin child_state <= 8'b01000001; to_child_0 <= `null; to_parent <= `done_block; end else begin child_state <= 8'b01000001; to_child_0 <= `null; to_parent <= `done_block; $display ("invalid response by parent to `done_block", from_parent); end // else: !if(from_parent == `null) end // if (child_state == 8'b01000001) else if (child_state == 8'b01000010) begin we_data_child_0 <= `no; if (from_child_0 == `byte_there) begin we_data_parent <= `yes; //This is the first byte, so we're going to shift in the // child number here (0 in this case) data_to_parent <= {data_child_0[6:0],1'b0}; child_state <= 8'b01000011; to_child_0 <= `start_transfer; to_parent <= `byte_there; end else if (from_child_0 == `done_block) begin we_data_parent <= `no; child_state <= 8'b01000010; to_child_0 <= `start_transfer; to_parent <= `done_block; end else begin we_data_parent <= `no; child_state <= 8'b01000010; to_child_0 <= `start_transfer; to_parent <= `done_block; $display ("invalid response by child_0 to `start_transfer", from_child_0); end // else: !if(from_child_0 == `done_block) end // if (child_state == 8'b01000010) else if (child_state == 8'b01000011) begin we_data_child_0 <= `no; if (from_parent == `byte_there) begin we_data_parent <= `no; child_state <= 8'b01000100; to_child_0 <= `byte_there; to_parent <= `byte_there; end else if (from_parent == `start_transfer) begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000011; to_child_0 <= `start_transfer; to_parent <= `byte_there; end else if (from_parent == `null) begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000011; to_child_0 <= `null; to_parent <= `byte_there; end else begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000011; to_child_0 <= `start_transfer; to_parent <= `byte_there; $display ("invalid response by parent to `byte_there %h %h", from_parent, child_state ); end // else: !if(from_parent == `start_transfer) end // if (child_state == 8'b01000011) else if (child_state == 8'b01000100) begin we_data_child_0 <= `no; if (from_child_0 == `null) begin we_data_parent <= `no; child_state <= 8'b01000101; to_child_0 <= `byte_there; to_parent <= `null; end else if (from_child_0 == `byte_there) begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000100; to_child_0 <= `byte_there; to_parent <= `byte_there; end else begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000100; to_child_0 <= `byte_there; to_parent <= `byte_there; $display ("invalid response by child_0 to `byte_there ", from_child_0); end // else: !if(from_child_0 == `byte_there) end // if (child_state == 8'b01000100) else if (child_state == 8'b01000101) begin we_data_child_0 <= `no; we_data_parent <= `no; if (from_parent == `null) begin child_state <= 8'b01000110; to_child_0 <= `null; to_parent <= `null; end else if (from_parent == `byte_there) begin child_state <= 8'b01000101; to_child_0 <= `byte_there; to_parent <= `null; end else begin child_state <= 8'b01000101; to_child_0 <= `byte_there; to_parent <= `null; $display ("invalid response by parent to `null after byte_there ", from_parent); end // else: !if(from_parent == `byte_there) end // if (child_state == 8'b01000101) else if (child_state == 8'b01000110) begin we_data_child_0 <= `no; if (from_child_0 == `done_transfer) begin we_data_parent <= `no; child_state <= 8'b01000111; to_child_0 <= `null; to_parent <= `done_transfer; end else if (from_child_0 == `byte_there) begin we_data_parent <= `yes; //Not the first byte, so just send it on data_to_parent <= data_child_0; child_state <= 8'b01000011; to_child_0 <= `null; to_parent <= `byte_there; end else if (from_child_0 == `null) begin we_data_parent <= `no; child_state <= 8'b01000110; to_child_0 <= `null; to_parent <= `null; end else begin we_data_parent <= `no; child_state <= 8'b01000110; to_child_0 <= `null; to_parent <= `null; $display ("invalid response by child_0 to `null after byte_there ", from_child_0); end // else: !if(from_child_0 == `null) end // if (child_state == 8'b01000110) else if (child_state == 8'b01000111) begin we_data_child_0 <= `no; we_data_parent <= `no; if (from_parent == `done_transfer) begin child_state <= 8'b01001000; to_child_0 <= `done_transfer; to_parent <= `done_transfer; end else if (from_parent == `null) begin child_state <= 8'b01000111; to_child_0 <= `null; to_parent <= `done_transfer; end else begin child_state <= 8'b01000111; to_child_0 <= `null; to_parent <= `done_transfer; $display ("invalid response by parent to `done_transfer ", from_parent); end // else: !if(from_parent == `null) end // if (child_state == 8'b01000111) else if (child_state == 8'b01001000) begin we_data_child_0 <= `no; we_data_parent <= `no; if (from_child_0 == `null) begin child_state <= 8'b01001001; to_child_0 <= `done_transfer; to_parent <= `null; end else if (from_child_0 == `done_transfer) begin child_state <= 8'b01001000; to_child_0 <= `done_transfer; to_parent <= `done_transfer; end else begin child_state <= 8'b01001000; to_child_0 <= `done_transfer; to_parent <= `done_transfer; $display ("invalid response by child_0 to `done_transfer ", from_child_0); end // else: !if(from_child_0 == `done_transfer) end // if (child_state == 8'b01001000) else if (child_state == 8'b01001001) begin we_data_child_0 <= `no; we_data_parent <= `no; if (from_parent == `null) begin child_0_running <= `no; //We're done with this upload child_state <= 8'b00000000; to_child_0 <= `null; to_parent <= `null; end else if(from_parent == `done_transfer) begin child_state <= 8'b01001001; to_child_0 <= `done_transfer; to_parent <= `null; end else begin child_state <= 8'b01001001; to_child_0 <= `done_transfer; to_parent <= `null; $display ("invalid response by parent to `null after done_transfer ", from_parent); end // else: !if(from_parent == `done_transfer) end // if (child_state == 8'b01001001) end // if (child_0_running) else if (child_1_running) begin //$display("Running Child_1"); //child_1_running <= 1'b0; to_child_0 <= `idle; we_data_child_0 <= 1'b1; //Be sure to uncomment this before enabling child_1 !! last_child_run <= 1'b1; //child_1_running <= 1'b0; /* child_state docs: * first two bits 00 == download * first two bits 01 == upload */ if (child_state == 8'b00000000) begin //start child_1 comm //$display("State = 8'b00000000"); we_data_child_1 <= `no; we_data_parent <= `no; if (from_child_1 == `request_block) begin //$display("Going to state: 8'b00000001"); child_state <= 8'b00000001; to_child_1 <= `null; to_parent <= `request_block; end else if (from_child_1 == `done_block) begin //$display("Going to state: 8'b01000001"); child_state <= 8'b01000001; to_child_1 <= `null; to_parent <= `done_block; end else if (from_child_1 == `null) begin child_state <= 8'b00000000; to_child_1 <= `null; to_parent <= `null; //$display("Shouldn't be here ", from_child_1," ", from_parent); end else begin child_state <= 8'b00000000; to_child_1 <= `null; to_parent <= `null; $display("Invalid starting code from child_1 ", from_child_1); end end // if (child_state == 8'b00000000) else if (child_state == 8'b00000001) begin //$display("State = 8'b00000001"); we_data_child_1 <= `no; we_data_parent <= `no; if (from_parent == `ack_request) begin child_state <= 8'b00000010; to_child_1 <= `ack_request; to_parent <= `request_block; end else if (from_parent == `null) begin child_state <= 8'b00000001; to_child_1 <= `null; to_parent <= `request_block; end else begin child_state <= 8'b00000001; to_child_1 <= `null; to_parent <= `request_block; $display("Invalid response by parent to `request_block ", from_parent); end end // if (child_state == 8'b00000001) else if (child_state == 8'b00000010) begin we_data_child_1 <= `no; we_data_parent <= `no; if (from_child_1 == `null) begin child_state <= 8'b00000100; to_child_1 <= `ack_request; to_parent <= `null; end else if (from_child_1 == `request_block) begin child_state <= 8'b00000010; to_child_1 <= `ack_request; to_parent <= `request_block; end else begin child_state <= 8'b00000010; to_child_1 <= `ack_request; to_parent <= `request_block; $display("Invalid response by child_1 to `ack_request ", from_child_1); end // else: !if(from_child_1 == `request_block) end // if (child_state == 8'b00000010) //OK, so I skipped a state number here, // So sue me // -Eric else if (child_state == 8'b00000100) begin //$display("Entering state " ,child_state); we_data_parent <= `no; if (from_parent == `byte_there) begin child_state <= 8'b00000101; to_child_1 <= `byte_there; to_parent <= `null; we_data_child_1 <= `yes; //The first byte, so we have to shift out a byte data_to_child_1 <= {1'b0,data_parent[7:1]}; end else if (from_parent == `ack_request) begin child_state <= 8'b00000100; to_child_1 <= `ack_request; to_parent <= `null; we_data_child_1 <= `no; end else begin child_state <= 8'b00000100; to_child_1 <= `ack_request; to_parent <= `null; we_data_child_1 <= `no; $display("Invalid response by parent to `null after ack_request ", from_parent); end // else: !if(from_parent == `ack_request) end // if (child_state == 8'b00000100) else if (child_state == 8'b00000101) begin we_data_parent <= `no; if (from_child_1 == `byte_there) begin // shouldn't be necessary, but.. we_data_child_1 <= `yes; data_to_child_1 <= data_to_child_1_last; child_state <= 8'b00000110; to_child_1 <= `byte_there; to_parent <= `byte_there; end else if (from_child_1 == `null) begin we_data_child_1 <= `yes; data_to_child_1 <= data_to_child_1_last; child_state <= 8'b00000101; to_child_1 <= `byte_there; to_parent <= `null; end else begin we_data_child_1 <= `yes; data_to_child_1 <= data_to_child_1_last; child_state <= 8'b00000101; to_child_1 <= `byte_there; to_parent <= `null; $display("Invalid response by child_1 to `byte_there ", from_child_1); end // else: !if(from_child_1 == `null) end // if (child_state == 8'b00000101) else if (child_state == 8'b00000110) begin we_data_parent <= `no; if (from_parent == `null) begin we_data_child_1 <= `no; child_state <= 8'b00000111; to_child_1 <= `null; to_parent <= `byte_there; end else if (from_parent == `byte_there) begin we_data_child_1 <= `yes; data_to_child_1 <= data_to_child_1_last; child_state <= 8'b00000111; to_child_1 <= `byte_there; to_parent <= `byte_there; end else begin we_data_child_1 <= `yes; data_to_child_1 <= data_to_child_1_last; child_state <= 8'b00000110; to_child_1 <= `byte_there; to_parent <= `byte_there; $display("Invalid response by parent to `byte_there ", from_parent); end // else: !if(from_parent == `byte_there) end // if (child_state == 8'b00000110) else if (child_state == 8'b00000111) begin we_data_child_1 <= `no; we_data_parent <= `no; if (from_child_1 == `null) begin child_state <= 8'b00001000; to_child_1 <= `null; to_parent <= `null; end else if (from_child_1 == `byte_there) begin child_state <= 8'b00000110; to_child_1 <= `null; to_parent <= `byte_there; end else begin child_state <= 8'b00000111; to_child_1 <= `null; to_parent <= `byte_there; $display("Invalid response by child_1 to `null after byte_there ", from_child_1); end // else: !if(from_parent == `byte_there) end // if (child_state == 8'b00000111) else if (child_state == 8'b00001000) begin we_data_parent <= `no; if (from_parent == `done_transfer) begin we_data_child_1 <= `no; child_state <= 8'b00001001; to_child_1 <= `done_transfer; to_parent <= `null; end else if (from_parent == `byte_there) begin we_data_child_1 <= `yes; data_to_child_1 <= data_parent; child_state <= 8'b00000101; to_child_1 <= `byte_there; to_parent <= `null; end else if (from_parent == `null) begin we_data_child_1 <= `no; child_state <= 8'b00001000; to_child_1 <= `null; to_parent <= `null; end else begin we_data_child_1 <= `no; child_state <= 8'b00001000; to_child_1 <= `null; to_parent <= `null; $display("Invalid response by parent to `null after byte_there ", from_parent); end end // if (child_state == 8b'00001000) else if (child_state == 8'b00001001) begin we_data_child_1 <= `no; we_data_parent <= `no; if (from_child_1 == `done_transfer) begin child_state <= 8'b00001010; to_child_1 <= `done_transfer; to_parent <= `done_transfer; end else if (from_child_1 == `null) begin child_state <= 8'b00001001; to_child_1 <= `done_transfer; to_parent <= `null; end else begin child_state <= 8'b00001001; to_child_1 <= `done_transfer; to_parent <= `null; $display("Invalid response by child_1 to `done_transfer ", from_child_1); end // else: !if(from_child_1 == `null) end // if (child_state == 8'b00001001) else if (child_state == 8'b00001010) begin we_data_child_1 <= `no; we_data_parent <= `no; if (from_parent == `null) begin child_state <= 8'b00001011; to_child_1 <= `null; to_parent <= `done_transfer; end else if (from_parent == `done_transfer) begin child_state <= 8'b00001010; to_child_1 <= `done_transfer; to_parent <= `done_transfer; end else begin child_state <= 8'b00001010; to_child_1 <= `done_transfer; to_parent <= `done_transfer; $display("Invalid response by parent to `done_transfer ", from_parent); end end // if (child_state == 8'b00001010) else if (child_state == 8'b00001011) begin we_data_child_1 <= `no; we_data_parent <= `no; if (from_child_1 == `null) begin //We're done with this download child_state <= 8'b00000000; to_child_1 <= `null; to_parent <= `null; child_1_running <= 1'b0; end else if (from_child_1 == `done_transfer) begin child_state <= 8'b00001011; to_child_1 <= `null; to_parent <= `done_transfer; end else begin child_state <= 8'b00001011; to_child_1 <= `null; to_parent <= `done_transfer; $display("Invalid response by child_1 to `null after done_transfer ", from_child_1); end // else: !if(from_child == `done_transfer) end // if (child_state == 8b'00001011) else if (child_state == 8'b01000001) begin we_data_child_1 <= `no; we_data_parent <= `no; //$display("State 8'b01000001"); if (from_parent == `start_transfer) begin child_state <= 8'b01000010; to_child_1 <= `start_transfer; to_parent <= `done_block; end else if (from_parent == `null) begin child_state <= 8'b01000001; to_child_1 <= `null; to_parent <= `done_block; end else begin child_state <= 8'b01000001; to_child_1 <= `null; to_parent <= `done_block; $display ("invalid response by parent to `done_block", from_parent); end // else: !if(from_parent == `null) end // if (child_state == 8'b01000001) else if (child_state == 8'b01000010) begin we_data_child_1 <= `no; if (from_child_1 == `byte_there) begin we_data_parent <= `yes; //This is the first byte, going up, so we have to shift // in the child id# (1 here) data_to_parent <= {data_child_1[6:0],1'b1}; child_state <= 8'b01000011; to_child_1 <= `start_transfer; to_parent <= `byte_there; end else if (from_child_1 == `done_block) begin we_data_parent <= `no; child_state <= 8'b01000010; to_child_1 <= `start_transfer; to_parent <= `done_block; end else begin we_data_parent <= `no; child_state <= 8'b01000010; to_child_1 <= `start_transfer; to_parent <= `done_block; $display ("invalid response by child_1 to `start_transfer", from_child_1); end // else: !if(from_child_1 == `done_block) end // if (child_state == 8'b01000010) else if (child_state == 8'b01000011) begin we_data_child_1 <= `no; if (from_parent == `byte_there) begin we_data_parent <= `no; child_state <= 8'b01000100; to_child_1 <= `byte_there; to_parent <= `byte_there; end else if (from_parent == `start_transfer) begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000011; to_child_1 <= `start_transfer; to_parent <= `byte_there; end else if (from_parent == `null) begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000011; to_child_1 <= `null; to_parent <= `byte_there; end else begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000011; to_child_1 <= `start_transfer; to_parent <= `byte_there; $display ("invalid response by parent to `byte_there %h %h", from_parent, child_state ); end // else: !if(from_parent == `start_transfer) end // if (child_state == 8'b01000011) else if (child_state == 8'b01000100) begin we_data_child_1 <= `no; if (from_child_1 == `null) begin we_data_parent <= `no; child_state <= 8'b01000101; to_child_1 <= `byte_there; to_parent <= `null; end else if (from_child_1 == `byte_there) begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000100; to_child_1 <= `byte_there; to_parent <= `byte_there; end else begin we_data_parent <= `yes; data_to_parent <= data_to_parent_last; child_state <= 8'b01000100; to_child_1 <= `byte_there; to_parent <= `byte_there; $display ("invalid response by child_1 to `byte_there ", from_child_1); end // else: !if(from_child_1 == `byte_there) end // if (child_state == 8'b01000100) else if (child_state == 8'b01000101) begin we_data_child_1 <= `no; we_data_parent <= `no; if (from_parent == `null) begin child_state <= 8'b01000110; to_child_1 <= `null; to_parent <= `null; end else if (from_parent == `byte_there) begin child_state <= 8'b01000101; to_child_1 <= `byte_there; to_parent <= `null; end else begin child_state <= 8'b01000101; to_child_1 <= `byte_there; to_parent <= `null; $display ("invalid response by parent to `null after byte_there ", from_parent); end // else: !if(from_parent == `byte_there) end // if (child_state == 8'b01000101) else if (child_state == 8'b01000110) begin we_data_child_1 <= `no; if (from_child_1 == `done_transfer) begin we_data_parent <= `no; child_state <= 8'b01000111; to_child_1 <= `null; to_parent <= `done_transfer; end else if (from_child_1 == `byte_there) begin we_data_parent <= `yes; data_to_parent <= data_child_1; child_state <= 8'b01000011; to_child_1 <= `null; to_parent <= `byte_there; end else if (from_child_1 == `null) begin we_data_parent <= `no; child_state <= 8'b01000110; to_child_1 <= `null; to_parent <= `null; end else begin we_data_parent <= `no; child_state <= 8'b01000110; to_child_1 <= `null; to_parent <= `null; $display ("invalid response by child_1 to `null after byte_there ", from_child_1); end // else: !if(from_child_1 == `null) end // if (child_state == 8'b01000110) else if (child_state == 8'b01000111) begin we_data_child_1 <= `no; we_data_parent <= `no; if (from_parent == `done_transfer) begin child_state <= 8'b01001000; to_child_1 <= `done_transfer; to_parent <= `done_transfer; end else if (from_parent == `null) begin child_state <= 8'b01000111; to_child_1 <= `null; to_parent <= `done_transfer; end else begin child_state <= 8'b01000111; to_child_1 <= `null; to_parent <= `done_transfer; $display ("invalid response by parent to `done_transfer ", from_parent); end // else: !if(from_parent == `null) end // if (child_state == 8'b01000111) else if (child_state == 8'b01001000) begin we_data_child_1 <= `no; we_data_parent <= `no; if (from_child_1 == `null) begin child_state <= 8'b01001001; to_child_1 <= `done_transfer; to_parent <= `null; end else if (from_child_1 == `done_transfer) begin child_state <= 8'b01001000; to_child_1 <= `done_transfer; to_parent <= `done_transfer; end else begin child_state <= 8'b01001000; to_child_1 <= `done_transfer; to_parent <= `done_transfer; $display ("invalid response by child_1 to `done_transfer ", from_child_1); end // else: !if(from_child_1 == `done_transfer) end // if (child_state == 8'b01001000) else if (child_state == 8'b01001001) begin we_data_child_1 <= `no; we_data_parent <= `no; if (from_parent == `null) begin child_1_running <= `no; //We're done with this upload child_state <= 8'b00000000; to_child_1 <= `null; to_parent <= `null; end else if(from_parent == `done_transfer) begin child_state <= 8'b01001001; to_child_1 <= `done_transfer; to_parent <= `null; end else begin child_state <= 8'b01001001; to_child_1 <= `done_transfer; to_parent <= `null; $display ("invalid response by parent to `null after done_transfer ", from_parent); end // else: !if(from_parent == `done_transfer) end // if (child_state == 8'b01001001) end // if (child_1_running) else begin case(both_ctrl) {`RESERVED,`RESERVED},//If this hits after the initial reset, we have a problem {`idle,`idle}: {child_0_running, child_1_running,first_byte} <= 3'b000; {`request_block,`idle}, {`done_block,`idle}, {`request_block,`start_IMDCT}, {`done_block,`start_IMDCT}: //set_child_0(child_0_running,child_1_running); {child_0_running, child_1_running,first_byte} <= 3'b101; {`idle,`request_block}, {`idle,`done_block}, {`start_IMDCT,`request_block}, {`start_IMDCT,`done_block}: //set_child_1(child_0_running,child_1_running); {child_0_running, child_1_running,first_byte} <= 3'b011; {`request_block,`request_block}, {`request_block,`done_block}, {`done_block,`request_block}, {`done_block,`done_block}: //pick_child(child_0_running,child_1_running,last_child_run); begin:pick //could just do: //child_0_running <= last_child_run; //child_1_running <= ~last_child_run; //but that doesn't have error checking for x/z if (last_child_run == 1'b0) begin child_0_running <= 1'b0; child_1_running <= 1'b1; end else if (last_child_run == 1'b1) begin child_0_running <= 1'b1; child_1_running <= 1'b0; end else begin //Not that I'd know how a one bit number wouldn't // be either one or zero $display("Last_child_run has an invalid value! ",last_child_run); child_0_running <= 1'b0; child_1_running <= 1'b0; if (!error_state) begin error_state <= `set; debug_state_output <= 7'b1001001; end end // else: !if(last_child_run == 1'b1) end default: begin $display("Invalid Request Combination ",both_ctrl); if (!error_state) begin error_state <= `set; debug_state_output <= 7'b1001010; end end endcase // case(both_ctrl) end end // if (reset) else//if !(reset) begin $display("RESETTING!"); child_0_running <= 1'b0; child_1_running <= 1'b0; last_child_run <= 1'b1; child_done <= 1'b0; child_state <= 8'b00000000; to_child_0 <= `idle; to_child_1 <= `idle; to_parent <= `idle; we_data_child_0 <= 1'b0; we_data_child_1 <= 1'b0; we_data_parent <= 1'b0; to_child_0_last <= `idle; to_child_1_last <= `idle; to_parent_last <= `idle; do_IMDCT <= `no; error_state <= `unset; first_byte <= `set; debug_state_output <= 7'b0000000; end // else: !if(reset) end // always @ (posedge clk) task set_child_0; output child_0_running; output child_1_running; begin:set0 child_0_running <= 1'b1; child_1_running <= 1'b0; end endtask // set_child_0 task set_child_1; output child_0_running; output child_1_running; begin:set1 child_0_running <= 1'b0; child_1_running <= 1'b1; end endtask // set_child_1 //Make this do something better at some point task pick_child; output child_0_running; output child_1_running; input last_child_run; begin:pick if (last_child_run == 1'b0) begin child_0_running <= 1'b0; child_1_running <= 1'b1; end else if (last_child_run == 1'b1) begin child_0_running <= 1'b1; child_1_running <= 1'b0; end else begin $display("Last_child_run has an invalid value!"); child_0_running <= 1'b0; child_1_running <= 1'b0; end // else: !if(last_child_run == 1'b1) end // block: pick endtask // pick_child endmodule // router