diff --git a/controller.vhd b/controller.vhd index d9642d1791593a0910faec369f0d26a891296ad8..919f0b0ae5940f591727311530a54ed29bcd6731 100644 --- a/controller.vhd +++ b/controller.vhd @@ -67,12 +67,12 @@ end function resetLogic; function statusCheck(turn_taker: std_logic) return StatusResult is variable result : StatusResult; begin - if turn_taker = '0' then + if turn_taker = '0' then -- Hvis det er 0 sin tur, så sjekker vi TX status på neste klokkepuls. result.rd_sig_out := '1'; result.adresse_out := "010"; result.wr_sig_out := '0'; result.turn_taker_out := '1'; - elsif turn_taker = '1' then + elsif turn_taker = '1' then -- Hvis det er 1 sin tur, da sjekker vi Rx status på neste klokkepuls. result.rd_sig_out := '1'; result.adresse_out := "110"; result.wr_sig_out := '0'; @@ -94,17 +94,17 @@ begin impure function sendDataToTx(databus: std_logic_vector(7 downto 0)) return TxResult is variable result : TxResult; begin - if txBusy = '0' then + --if txBusy = '0' then result.adresse_out := "001"; result.data_bus_out := databus; result.wr_sig_out := '1'; result.rd_sig_out := '0'; - else - result.adresse_out := "ZZZ"; - result.data_bus_out := databus; - result.wr_sig_out := '0'; - result.rd_sig_out := '0'; - end if; + --else + -- result.adresse_out := "ZZZ"; + -- result.data_bus_out := databus; + -- result.wr_sig_out := '0'; + -- result.rd_sig_out := '0'; + --end if; return result; end function sendDataToTx; @@ -155,7 +155,7 @@ begin Rd_sig <= '0'; adresse <= "001"; - else if rxIncomingData = '1' and txBusy = '0' then + else if rxIncomingData = '1'then tx_result := sendDataToTx(Data_bus); adresse <= tx_result.adresse_out; @@ -164,13 +164,14 @@ begin Rd_sig <= '0'; rxIncomingData <= '0'; else + LED_msg <= '0'; -- normal klokkelogikk. Annahver polling av RX og TX for status. status_result := statusCheck(turnTaker); Rd_sig <= status_result.rd_sig_out; Wr_sig <= status_result.wr_sig_out; adresse <= status_result.adresse_out; turnTaker <= status_result.turn_taker_out; - if turnTaker = '1' then -- da skal vi sjekke om TX er busy + if turnTaker = '0' then -- da skal vi sjekke om TX er busy if Data_bus(0 downto 0) = "1" then txBusy <= '1'; Data_bus <= "ZZZZZZZZ"; @@ -178,9 +179,16 @@ begin txBusy <= '0'; end if; - elsif turnTaker = '0' then -- Skal sjekke om Rx har data til oss, status på fifo osv. - if txBusy = '0' then - rxIncomingData <= '1'; + elsif turnTaker = '1' then -- Da sjekker på på denne pulsen om Rx har data til oss, status på fifo osv. + if Data_bus = "ZZZZ0100"then + + tx_result := sendDataToTx(Data_bus); + adresse <= tx_result.adresse_out; + Data_bus <= tx_result.data_bus_out; + Wr_sig <= tx_result.wr_sig_out; + Rd_sig <= '0'; + LED_msg <= '1'; + rxIncomingData <= '0'; else --do nothing end if; diff --git a/controller_tb.vhd b/controller_tb.vhd index 1acd4d60fa3985b7ad06c7f30b1f047eba3b365e..9de5b36714ef593fae899f3ca21ad03d767e06a2 100644 --- a/controller_tb.vhd +++ b/controller_tb.vhd @@ -104,16 +104,11 @@ begin procedure loopAscii is begin - wait for 100 ns; - adresse <= "101"; - --wait until rising_edge(clk); + wait until adresse = "110"; + wait until rising_edge(clk); + Data_bus <= "ZZZZ0100"; + wait until rising_edge(clk); Data_bus <= "01000001"; - --wait until rising_edge(clk); - --assert Rd_sig = '1'; - --wait until rising_edge(clk); - --Data_bus(7 downto 0) <= "01000001"; - --wait until rising_edge(clk); - --assert adresse(2 downto 0) = "001" report "erra erra pants on fire" severity error; end loopAscii; begin