Необходимо конвертировать разные типы данных.

This commit is contained in:
sokolovstanislav 2024-03-27 16:40:59 +03:00
parent f04720071b
commit 2ece286472

View File

@ -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;
end if;
if pback = '0' then
count := 0;
countValue := 1;
pbdata <= (others => 'Z');
CommunicationState <= PreparingToReceiveData;
else
CommunicationState <= Waiting;
errorBuf(0) <= '1';
if count < countValue then
count := count + 1;
else
CommunicationState <= Waiting;
errorBuf(0) <= '1';
end if;
end if;
when PreparingToReceiveData =>
if count < countValue then
count <= count + 1;
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;
end if;
if pback = '1' then
pbclk <= '1';
dataTemp <= pbdata;
CommunicationState <= ReceiveCheck;
count := 0;
countValue := 15;
else
CommunicationState <= Waiting;
errorBuf(1) <= '1';
if count < countValue then
count := count + 1;
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
CommunicationState <= Waiting;
errorBuf(3) <= '1';
if count < countValue then
count := count + 1;
else
CommunicationState <= Waiting;
errorBuf(3) <= '1';
end if;
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;