From 2ece2864727112a2a578ea19932477caaa02669e Mon Sep 17 00:00:00 2001 From: sokolovstanislav Date: Wed, 27 Mar 2024 16:40:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=D0=BE=20=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D1=82=D0=B8=D0=BF=D1=8B=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainController/RAM9X8_ParallelBusMaster.vhd | 140 ++++++++++---------- 1 file changed, 73 insertions(+), 67 deletions(-) diff --git a/MainController/RAM9X8_ParallelBusMaster.vhd b/MainController/RAM9X8_ParallelBusMaster.vhd index 70377af..84d2e80 100644 --- a/MainController/RAM9X8_ParallelBusMaster.vhd +++ b/MainController/RAM9X8_ParallelBusMaster.vhd @@ -46,10 +46,11 @@ signal cmdBuf : std_logic_vector(15 downto 0) := (others => '0'); signal fasBuf : std_logic_vector(15 downto 0) := (others => '0'); signal controlBuf : std_logic_vector(15 downto 0) := (others => '0'); -signal direction : std_logic := '0'; -signal addressToTransmit : std_logic_vector(7 downto 0) := x"00"; -signal dataToTransmit : std_logic_vector(15 downto 0) := x"0000"; -signal dataFromDevices : std_logic_vector(15 downto 0) := x"0000"; +signal updatedAddress : std_logic_vector(7 downto 0) := (others => '0'); + +signal errorBuf : std_logic_vector(7 downto 0) := x"00"; +signal addrTemp : std_logic_vector(15 downto 0) := x"0000"; +signal dataTemp : std_logic_vector(15 downto 0) := x"0000"; type CommunicationState_start is (Waiting, TransmiteAddress, TransmiteCheck, PreparingToReceiveData, ReceiveData, ReceiveCheck, Timeout, ReceiveCheckTimeout); signal CommunicationState : CommunicationState_start := Waiting ; @@ -67,7 +68,7 @@ begin if (ce = '0') then -- Если микросхема выбрана addr := conv_integer(address); if (addr = REG_ADDR_FIRST_FREE_UPPER_BYTE or addr = REG_ADDR_FIRST_FREE_LOWER_BYTE or addr = REG_ADDR_CMD_UPPER_BYTE or addr = REG_ADDR_CMD_LOWER_BYTE - or addr = REG_ADDR_FILL_ADDRESS_SPACE_UPPER_BYTE or addr = REG_ADDR_FILL_ADDRESS_SPACE_LOWER_BYTE or addr = ) then + or addr = REG_ADDR_FILL_ADDRESS_SPACE_UPPER_BYTE or addr = REG_ADDR_FILL_ADDRESS_SPACE_LOWER_BYTE or addr = REG_ADDR_CONTROL_UPPER_BYTE or addr = REG_ADDR_CONTROL_LOWER_BYTE) then if (oe = '0') then -- Если сигнал чтения активен case addr is when REG_ADDR_FIRST_FREE_UPPER_BYTE => @@ -103,7 +104,7 @@ begin fasBuf(15 downto 8) <= data; when REG_ADDR_FILL_ADDRESS_SPACE_LOWER_BYTE => fasBuf(7 downto 0) <= data; - position := data; + position := conv_integer(data); memoryAddress(position) <= fasBuf(15 downto 8); when others => data <= (others => 'Z'); -- Запретить запись на шину @@ -111,9 +112,9 @@ begin else data <= (others => 'Z'); -- Запретить запись на шину end if; - elsif (addr >= firstFree and addr <= firstFree + cmdBuf(7 downto 0)) then + elsif (addr >= firstFreeBuf and addr <= firstFreeBuf + cmdBuf(7 downto 0)) then if (oe = '0') then -- Если сигнал чтения активен - data <= memoryData(addr - firstFree); + data <= memoryData(addr - conv_integer(firstFreeBuf)); else data <= (others => 'Z'); -- Запретить запись на шину end if; @@ -144,86 +145,91 @@ begin pbclk <= '1'; pbce <= '1'; pbdata <= (others =>'Z'); - pbdir <= '1'; - countValue <= 6; - count <= 0; + pbdir <= b"11"; + countValue := 7; + count := 0; when TransmiteAddress => if count < countValue then - count <= count + 1; - pbdata(15 downto 8) <= addrTemp; - pbdata(7 downto 0) <= not addrTemp; + if count = 0 then + pbdata(15 downto 8) <= addrTemp; + pbdata(7 downto 0) <= not addrTemp; + end if; + count := count + 1; else pbce <= '0'; CommunicationState <= TransmiteCheck; - count <= 0; - countValue <= 10; + count := 0; + countValue := 15; end if; when TransmiteCheck => - if count < countValue then - count <= count + 1; - if pback = '0' then - count <= 0; - countValue <= 15; - pbdata <= (others => 'Z'); - CommunicationState <= PreparingToReceiveData; + if pback = '0' then + count := 0; + countValue := 1; + pbdata <= (others => 'Z'); + CommunicationState <= PreparingToReceiveData; + else + if count < countValue then + count := count + 1; + else + CommunicationState <= Waiting; + errorBuf(0) <= '1'; end if; - else - CommunicationState <= Waiting; - errorBuf(0) <= '1'; end if; when PreparingToReceiveData => if count < countValue then - count <= count + 1; - else + count := count + 1; + else + pbdir <= b"00"; pbclk <= '0'; - count <= 0; - countValue <= 12; + count := 0; + countValue := 15; CommunicationState <= ReceiveData; - end if;; + end if; when ReceiveData => - if count < countValue then - if pback = '1' then - pbclk <= '1'; - dataTemp <= pbdata; - CommunicationState <= ReceiveCheck; - count <= 0; - countValue <= 12; - else - count <= count + 1; + if pback = '1' then + pbclk <= '1'; + dataTemp <= pbdata; + CommunicationState <= ReceiveCheck; + count := 0; + countValue := 15; + else + if count < countValue then + count := count + 1; + else + CommunicationState <= Waiting; + errorBuf(1) <= '1'; end if; - else - CommunicationState <= Waiting; - errorBuf(1) <= '1'; - end if; + end if; when ReceiveCheck => - if count < countValue then - if pback = '0' then - if pbdata = not dataTemp then - memoryData(position) <= dataTemp(15 downto 8); - memoryData(position + 1) <= dataTemp(7 downto 0); - CommunicationState <= Timeout; - count <= 0; - countValue <= 12; - if position + 1 < cmdBuf(7 downto 0) then - updatedAddress <= position; - position <= position + 2; - else - position <= 0; - end if; + if pback = '0' then + if pbdata = not dataTemp then + memoryData(position) <= dataTemp(15 downto 8); + memoryData(position + 1) <= dataTemp(7 downto 0); + CommunicationState <= Timeout; + count := 0; + pbce <= '1'; + countValue := 5; + if position + 1 < cmdBuf(7 downto 0) then + updatedAddress <= position; + position := position + 2; else - CommunicationState <= Waiting; - errorBuf(2) <= '1'; + position := 0; end if; else - count <= count + 1; + CommunicationState <= Waiting; + errorBuf(2) <= '1'; + end if; + else + if count < countValue then + count := count + 1; + else + CommunicationState <= Waiting; + errorBuf(3) <= '1'; end if; - else - CommunicationState <= Waiting; - errorBuf(3) <= '1'; end if; when Timeout => if count < countValue then - count <= count + 1; + count := count + 1; else CommunicationState <= Waiting; end if; @@ -233,8 +239,8 @@ begin pbclk <= '1'; pbce <= '1'; pbdata <= (others =>'Z'); - pbdir <= '1'; - position <= 0; + pbdir <= b"11"; + position := 0; errorCount <= 0; errorBuf <= (others => '0'); end if;