mirror of
https://github.com/RobotechLille/cdf2018-principal
synced 2024-11-21 23:56:04 +01:00
FPGA : Envoi de valeurs des capteurs
This commit is contained in:
parent
d0e5842ca4
commit
23ef0c57dc
|
@ -163,11 +163,13 @@ isimgui: build/isim_$(TB)$(EXE)
|
||||||
# Testing (using ghdl and gtkwave)
|
# Testing (using ghdl and gtkwave)
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
|
GHDL_FLAGS=--mb-comments
|
||||||
|
|
||||||
%_syntax: %.vhd
|
%_syntax: %.vhd
|
||||||
ghdl -s --mb-comments "$<"
|
ghdl -s --mb-comments "$<"
|
||||||
|
|
||||||
build/%.o: %.vhd
|
build/%.o: %.vhd
|
||||||
ghdl -a --mb-comments --workdir="$(shell dirname "$@")" "$<"
|
ghdl -a $(GHDL_FLAGS) --workdir="$(shell dirname "$@")" "$<"
|
||||||
|
|
||||||
build/%_tb: build/%_tb.o $(addprefix build/,$(subst .vhd,.o,$(VHDSOURCE)))
|
build/%_tb: build/%_tb.o $(addprefix build/,$(subst .vhd,.o,$(VHDSOURCE)))
|
||||||
ghdl -e --workdir="$(shell dirname "$@")" -o "$(shell echo "$@" | tr A-Z a-z)" "$(basename $(notdir $<))"
|
ghdl -e --workdir="$(shell dirname "$@")" -o "$(shell echo "$@" | tr A-Z a-z)" "$(basename $(notdir $<))"
|
||||||
|
|
|
@ -33,9 +33,9 @@ architecture Behavioral of communication is
|
||||||
signal readState : readStates := readIdle;
|
signal readState : readStates := readIdle;
|
||||||
signal readOffset : integer := 0;
|
signal readOffset : integer := 0;
|
||||||
|
|
||||||
type sendMessages is (none, A2FD_PINGs, F2AD_ERR_UNKNOWN_CODEs);
|
type sendMessages is (none, A2FD_PINGs, F2AI_CODERs, F2AI_CAPTs, F2AD_ERR_UNKNOWN_CODEs);
|
||||||
|
|
||||||
constant SENDQUEUE_SIZE : integer := 4;
|
constant SENDQUEUE_SIZE : integer := 16;
|
||||||
type sendQueueMemorya is array (0 to SENDQUEUE_SIZE - 1) of sendMessages;
|
type sendQueueMemorya is array (0 to SENDQUEUE_SIZE - 1) of sendMessages;
|
||||||
|
|
||||||
signal frontTrigger : integer := 0;
|
signal frontTrigger : integer := 0;
|
||||||
|
@ -47,11 +47,12 @@ begin
|
||||||
|
|
||||||
txStb <= txStbs;
|
txStb <= txStbs;
|
||||||
|
|
||||||
|
|
||||||
readsendFA : process(clock, reset)
|
readsendFA : process(clock, reset)
|
||||||
|
|
||||||
variable sendMessage : sendMessages := none;
|
variable sendMessage : sendMessages := none;
|
||||||
variable sendOffset : integer := 0;
|
variable sendOffset : integer := 0;
|
||||||
|
variable sendSize : integer := 0;
|
||||||
|
variable sendData : std_logic_vector(63 downto 0); -- Max message size (will be trimmed down by the synthetizer)
|
||||||
|
|
||||||
-- Send queue
|
-- Send queue
|
||||||
variable sendQueueMemory : sendQueueMemorya;
|
variable sendQueueMemory : sendQueueMemorya;
|
||||||
|
@ -98,37 +99,50 @@ begin
|
||||||
case rxData is
|
case rxData is
|
||||||
when A2FD_PING =>
|
when A2FD_PING =>
|
||||||
pushSend(A2FD_PINGs);
|
pushSend(A2FD_PINGs);
|
||||||
|
when F2AI_CODER =>
|
||||||
|
pushSend(F2AI_CODERs);
|
||||||
|
when F2AI_CAPT =>
|
||||||
|
pushSend(F2AI_CAPTs);
|
||||||
when others =>
|
when others =>
|
||||||
pushSend(F2AD_ERR_UNKNOWN_CODEs);
|
pushSend(F2AD_ERR_UNKNOWN_CODEs);
|
||||||
end case;
|
end case;
|
||||||
end if;
|
end if;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
-- If what was sent is acknowledged and there is still something to send
|
-- If what was sent is acknowledged or nothing is being sent atm
|
||||||
if txStbs = '0' or txAck = '1' then
|
if txStbs = '0' or txAck = '1' then
|
||||||
if sendMessage = none then -- Reads a message if none is currently being sent
|
if sendSize = 0 then -- If no data to be sent
|
||||||
sendOffset := 0;
|
popSend(sendMessage); -- See if there a message in the message queue
|
||||||
popSend(sendMessage);
|
case sendMessage is
|
||||||
else
|
when none => -- No message available, do nothing
|
||||||
sendOffset := sendOffset + 1;
|
when A2FD_PINGs =>
|
||||||
|
sendData(7 downto 0) := A2FD_PING;
|
||||||
|
sendSize := 1;
|
||||||
|
when F2AI_CAPTs =>
|
||||||
|
sendData(7 downto 0) := F2AI_CAPT;
|
||||||
|
sendData(23 downto 8) := std_logic_vector(to_unsigned(front, 16));
|
||||||
|
sendData(39 downto 24) := std_logic_vector(to_unsigned(back, 16));
|
||||||
|
sendSize := 5;
|
||||||
|
when others => -- Including F2AD_ERR_UNKNOWN_CODEs
|
||||||
|
sendData(7 downto 0) := F2AD_ERR;
|
||||||
|
sendData(15 downto 8) := ERR_UNKNOWN_CODE;
|
||||||
|
sendSize := 2;
|
||||||
|
end case;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
txStbs <= '1';
|
if sendSize > 0 then -- If data to be sent
|
||||||
case sendMessage is
|
txData <= sendData((sendOffset + 1) * 8 - 1 downto sendOffset * 8);
|
||||||
when none => -- If no message available: don't send anything
|
txStbs <= '1';
|
||||||
txStbs <= '0';
|
|
||||||
when A2FD_PINGs =>
|
if sendOffset = sendSize - 1 then -- If it was the last character sent
|
||||||
txData <= A2FD_PING;
|
sendSize := 0; -- Make next iteration check for send queue
|
||||||
sendMessage := none;
|
sendOffset := 0;
|
||||||
when F2AD_ERR_UNKNOWN_CODEs =>
|
else -- Still data to be sent after that
|
||||||
case sendOffset is
|
sendOffset := sendOffset + 1;
|
||||||
when 0 =>
|
end if;
|
||||||
txData <= F2AD_ERR;
|
else -- If really no data to be sent
|
||||||
when others =>
|
txStbs <= '0';
|
||||||
txData <= ERR_UNKNOWN_CODE;
|
end if;
|
||||||
sendMessage := none;
|
|
||||||
end case;
|
|
||||||
end case;
|
|
||||||
end if;
|
end if;
|
||||||
end if;
|
end if;
|
||||||
end if;
|
end if;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
[*]
|
[*]
|
||||||
[*] GTKWave Analyzer v3.3.86 (w)1999-2017 BSI
|
[*] GTKWave Analyzer v3.3.86 (w)1999-2017 BSI
|
||||||
[*] Mon Feb 26 17:06:42 2018
|
[*] Mon Feb 26 19:15:08 2018
|
||||||
[*]
|
[*]
|
||||||
[dumpfile] "/home/geoffrey/Documents/Polytech/Robotech/2017-2018/CdF/cdf2018-principal/fpga/build/communication_tb.ghw"
|
[dumpfile] "/home/geoffrey/Documents/Polytech/Robotech/2017-2018/CdF/cdf2018-principal/fpga/build/communication_tb.ghw"
|
||||||
[dumpfile_mtime] "Mon Feb 26 17:03:51 2018"
|
[dumpfile_mtime] "Mon Feb 26 19:15:01 2018"
|
||||||
[dumpfile_size] 3315
|
[dumpfile_size] 4519
|
||||||
[savefile] "/home/geoffrey/Documents/Polytech/Robotech/2017-2018/CdF/cdf2018-principal/fpga/communication_tb.gtkw"
|
[savefile] "/home/geoffrey/Documents/Polytech/Robotech/2017-2018/CdF/cdf2018-principal/fpga/communication_tb.gtkw"
|
||||||
[timestart] 0
|
[timestart] 0
|
||||||
[size] 1680 1012
|
[size] 1600 862
|
||||||
[pos] -1 -1
|
[pos] -1 -1
|
||||||
*-28.533670 586000000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
|
*-29.277596 1395000000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
|
||||||
[treeopen] top.
|
[treeopen] top.
|
||||||
[treeopen] top.communication_tb.
|
[treeopen] top.communication_tb.
|
||||||
[treeopen] top.communication_tb.dut.
|
[treeopen] top.communication_tb.dut.
|
||||||
|
@ -34,9 +34,6 @@ top.communication_tb.dut.rxstb
|
||||||
top.communication_tb.dut.readstate
|
top.communication_tb.dut.readstate
|
||||||
[color] 6
|
[color] 6
|
||||||
top.communication_tb.dut.readoffset
|
top.communication_tb.dut.readoffset
|
||||||
@421
|
|
||||||
[color] 2
|
|
||||||
top.communication_tb.dut.a
|
|
||||||
@22
|
@22
|
||||||
[color] 1
|
[color] 1
|
||||||
#{top.communication_tb.txdata[7:0]} top.communication_tb.txdata[7] top.communication_tb.txdata[6] top.communication_tb.txdata[5] top.communication_tb.txdata[4] top.communication_tb.txdata[3] top.communication_tb.txdata[2] top.communication_tb.txdata[1] top.communication_tb.txdata[0]
|
#{top.communication_tb.txdata[7:0]} top.communication_tb.txdata[7] top.communication_tb.txdata[6] top.communication_tb.txdata[5] top.communication_tb.txdata[4] top.communication_tb.txdata[3] top.communication_tb.txdata[2] top.communication_tb.txdata[1] top.communication_tb.txdata[0]
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
library ieee;
|
library ieee;
|
||||||
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
||||||
|
use IEEE.NUMERIC_STD.ALL;
|
||||||
|
|
||||||
entity communication_tb is
|
entity communication_tb is
|
||||||
end communication_tb;
|
end communication_tb;
|
||||||
|
@ -40,6 +41,8 @@ architecture tb of communication_tb is
|
||||||
signal TbClock : std_logic := '0';
|
signal TbClock : std_logic := '0';
|
||||||
signal TbSimEnded : std_logic := '0';
|
signal TbSimEnded : std_logic := '0';
|
||||||
|
|
||||||
|
type multipleChar is array (0 to 15) of std_logic_vector(7 downto 0);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
dut : communication
|
dut : communication
|
||||||
|
@ -61,6 +64,7 @@ begin
|
||||||
clock <= TbClock;
|
clock <= TbClock;
|
||||||
|
|
||||||
stimuli : process
|
stimuli : process
|
||||||
|
variable shouldReceive : multipleChar;
|
||||||
begin
|
begin
|
||||||
left <= 0;
|
left <= 0;
|
||||||
right <= 0;
|
right <= 0;
|
||||||
|
@ -156,8 +160,31 @@ begin
|
||||||
wait for 100 ns;
|
wait for 100 ns;
|
||||||
assert txStb = '0' report "Not stopping send" severity error;
|
assert txStb = '0' report "Not stopping send" severity error;
|
||||||
|
|
||||||
wait for 100 ns; -- Margin
|
-- Test captor
|
||||||
|
front <= 1152;
|
||||||
|
back <= 11614;
|
||||||
|
|
||||||
|
report "TEST Receiving 'C'" severity note;
|
||||||
|
rxData <= x"43";
|
||||||
|
rxStb <= '1';
|
||||||
|
wait for TbPeriod;
|
||||||
|
rxStb <= '0';
|
||||||
|
|
||||||
|
shouldReceive(0 to 4) := (x"43", x"80", x"04", x"5E", x"2D");
|
||||||
|
for I in 0 to 4 loop
|
||||||
|
wait for 100 ns;
|
||||||
|
assert txData = shouldReceive(I) report "Not sent correct data, got " & integer'image(to_integer(unsigned(txData))) & ", expected " & integer'image(to_integer(unsigned(shouldReceive(I))))severity error;
|
||||||
|
assert txStb = '1' report "Not sending" severity error;
|
||||||
|
|
||||||
|
report "Acknowledging send" severity note;
|
||||||
|
wait for 100 ns;
|
||||||
|
txAck <= '1';
|
||||||
|
wait for TbPeriod;
|
||||||
|
txAck <= '0';
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
|
||||||
|
wait for 100 ns; -- Margin
|
||||||
|
|
||||||
TbSimEnded <= '1';
|
TbSimEnded <= '1';
|
||||||
wait;
|
wait;
|
||||||
|
|
Loading…
Reference in a new issue