1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-21 23:56:04 +01:00

FPGA : Pipelinage du module de communication

This commit is contained in:
Geoffrey Frogeye 2018-02-28 16:00:12 +01:00
parent 68c7223fe4
commit 6013d6c9a9
5 changed files with 133 additions and 134 deletions

View file

@ -174,11 +174,14 @@ build/%.o: %.vhd
build/%_tb: build/%_tb.o $(addprefix build/,$(subst .vhd,.o,$(VHDSOURCE))) build/%_tb: build/%_tb.o $(addprefix build/,$(subst .vhd,.o,$(VHDSOURCE)))
ghdl -e $(GHDL_FLAGS) --workdir="$(shell dirname "$@")" -o "$(shell echo "$@" | tr A-Z a-z)" "$(basename $(notdir $<))" ghdl -e $(GHDL_FLAGS) --workdir="$(shell dirname "$@")" -o "$(shell echo "$@" | tr A-Z a-z)" "$(basename $(notdir $<))"
%_test: build/%_tb
(cd "$(shell dirname "$<")"; time ghdl -r "$(basename $(notdir $<))")
build/%_tb.vcd: build/%_tb build/%_tb.vcd: build/%_tb
(cd "$(shell dirname "$<")"; time ghdl -r "$(basename $(notdir $<))" --vcd="../$@" ) (cd "$(shell dirname "$<")"; time ghdl -r "$(basename $(notdir $<))" --vcd="../$@")
build/%_tb.ghw: build/%_tb build/%_tb.ghw: build/%_tb
(cd "$(shell dirname "$<")"; time ghdl -r "$(basename $(notdir $<))" --wave="../$@" ) (cd "$(shell dirname "$<")"; time ghdl -r "$(basename $(notdir $<))" --wave="../$@")
%_wave: build/%_tb.ghw %_wave: build/%_tb.ghw
gtkwave --save "$(notdir $(basename $<)).gtkw" "$<" gtkwave --save "$(notdir $(basename $<)).gtkw" "$<"

View file

@ -9,11 +9,11 @@ entity communication is
reset : in std_logic; reset : in std_logic;
left : in integer; left : in integer;
right : in integer; right : in integer;
zerocoder : out std_logic; zerocoder : out std_logic := '0';
front : in integer; front : in integer;
back : in integer; back : in integer;
txData : out std_logic_vector(7 downto 0); txData : out std_logic_vector(7 downto 0) := x"00";
txStb : out std_logic; txStb : out std_logic := '0';
txAck : in std_logic; txAck : in std_logic;
rxData : in std_logic_vector(7 downto 0); rxData : in std_logic_vector(7 downto 0);
rxStb : in std_logic rxStb : in std_logic
@ -30,95 +30,73 @@ architecture Behavioral of communication is
constant F2AI_CAPT : std_logic_vector(7 downto 0) := x"43"; -- 'C' constant F2AI_CAPT : std_logic_vector(7 downto 0) := x"43"; -- 'C'
constant F2AT_CAPT : std_logic_vector(7 downto 0) := x"63"; -- 'c' constant F2AT_CAPT : std_logic_vector(7 downto 0) := x"63"; -- 'c'
type readMessages is (none, F2AT_CAPTs);
type sendMessages is (none, A2FD_PINGs, F2AI_CODERs, F2AI_CAPTs, F2AD_ERR_UNKNOWN_CODEs);
constant SENDQUEUE_SIZE : integer := 16;
type sendQueueMemorya is array (0 to SENDQUEUE_SIZE - 1) of sendMessages;
signal frontTrigger : integer := 0; signal frontTrigger : integer := 0;
signal backTrigger : integer := 0; signal backTrigger : integer := 0;
signal triggerSet : std_logic := '0'; signal triggerSet : std_logic := '0';
signal txStbs : std_logic := '0'; type readMessages is (F2AT_CAPTs);
signal readMessage : readMessages;
signal readSize : integer := 0;
signal readOffset : integer := 0;
signal readData : std_logic_vector(63 downto 0) := (others => '0'); -- Max message size (will be trimmed down by the synthetizer)
type sendMessages is (A2FD_PINGs, F2AI_CODERs, F2AI_CAPTs, F2AD_ERR_UNKNOWN_CODEs);
constant SENDQUEUE_SIZE : integer := 16;
type sendQueueMemorya is array (0 to SENDQUEUE_SIZE - 1) of sendMessages;
signal sendQueueMemory : sendQueueMemorya;
signal sendTail : integer := 0;
signal sendHead : integer := 0;
signal sendLooped : std_logic := '0';
signal sendAvailable: std_logic := '0';
signal sendBegun : std_logic := '0';
signal sendOffset : integer := 0;
signal sendSize : integer := 0;
signal sendData : std_logic_vector(63 downto 0) := (others => '0'); -- Max message size (will be trimmed down by the synthetizer)
begin begin
txStb <= txStbs;
readsendFA : process(clock, reset) readsendFA : process(clock, reset)
variable readMessage : readMessages := none;
variable readSize : integer := 0;
variable readOffset : integer := 0;
variable readData : std_logic_vector(63 downto 0); -- Max message size (will be trimmed down by the synthetizer)
variable sendMessage : sendMessages := none;
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
variable sendQueueMemory : sendQueueMemorya;
variable sendTail : integer := 0;
variable sendHead : integer := 0;
variable sendLooped : boolean := false;
procedure pushSend procedure pushSend
(message : in sendMessages) is (message : in sendMessages) is
begin begin
sendQueueMemory(sendHead) := message; sendQueueMemory(sendHead) <= message;
if sendHead < SENDQUEUE_SIZE - 1 then if sendHead < SENDQUEUE_SIZE - 1 then
sendHead := sendHead + 1; sendHead <= sendHead + 1;
else else
sendHead := 0; sendHead <= 0;
sendLooped := true; sendLooped <= '1';
end if; end if;
end pushSend; end pushSend;
procedure popSend
(message : out sendMessages) is
begin
if sendTail < sendHead or sendLooped then
message := sendQueueMemory(sendTail);
if sendTail < SENDQUEUE_SIZE - 1 then
sendTail := sendTail + 1;
else
sendTail := 0;
sendLooped := false;
end if;
else
message := none;
end if;
end popSend;
begin begin
if reset = '1' then if reset = '1' then
readMessage := none;
readOffset := 0;
readSize := 0;
sendMessage := none;
sendOffset := 0;
sendSize := 0;
sendTail := 0;
sendHead := 0;
sendLooped := false;
frontTrigger <= 0; frontTrigger <= 0;
backTrigger <= 0; backTrigger <= 0;
triggerSet <= '0';
readSize <= 0;
readOffset <= 0;
readData <= (others => '0');
sendTail <= 0;
sendHead <= 0;
sendLooped <= '0';
sendAvailable<= '0';
sendBegun <= '0';
sendOffset <= 0;
sendSize <= 0;
sendData <= (others => '0');
txStb <= '0';
zerocoder <= '0'; zerocoder <= '0';
txData <= x"00"; txData <= x"00";
triggerSet <= '0';
else else
if rising_edge(clock) then if rising_edge(clock) then
zerocoder <= '0'; zerocoder <= '0';
-- If read something -- If read something
if rxStb = '1' then if rxStb = '1' then -- Incomming character
if readSize = 0 then if readSize = 0 then -- Beginning of message
readSize := 0; readSize <= 0;
case rxData is case rxData is
when A2FD_PING => when A2FD_PING =>
pushSend(A2FD_PINGs); pushSend(A2FD_PINGs);
@ -127,80 +105,85 @@ begin
when F2AI_CAPT => when F2AI_CAPT =>
pushSend(F2AI_CAPTs); pushSend(F2AI_CAPTs);
when F2AT_CAPT => when F2AT_CAPT =>
readMessage := F2AT_CAPTs; readMessage <= F2AT_CAPTs;
readSize := 4; readSize <= 4;
when others => when others =>
pushSend(F2AD_ERR_UNKNOWN_CODEs); pushSend(F2AD_ERR_UNKNOWN_CODEs);
end case; end case;
else else -- Rest of message
readData((readOffset + 1) * 8 - 1 downto readOffset * 8) := rxData; if readOffset < readSize then
if readOffset = readSize - 1 then readData((readOffset + 1) * 8 - 1 downto readOffset * 8) <= rxData;
case readMessage is readOffset <= readOffset + 1;
when F2AT_CAPTs =>
frontTrigger <= to_integer(unsigned(readData(15 downto 0)));
backTrigger <= to_integer(unsigned(readData(31 downto 16)));
triggerSet <= '1';
when others =>
pushSend(F2AD_ERR_UNKNOWN_CODEs);
end case;
readMessage := none;
readOffset := 0;
readSize := 0;
else
readOffset := readOffset + 1;
end if; end if;
end if; end if;
end if; elsif readSize > 0 and readOffset = readSize then -- Rest of message ended
case readMessage is
if (triggerSet = '1' and ((front > frontTrigger) or (back > backTrigger))) then when F2AT_CAPTs =>
frontTrigger <= to_integer(unsigned(readData(15 downto 0)));
backTrigger <= to_integer(unsigned(readData(31 downto 16)));
triggerSet <= '1';
when others =>
pushSend(F2AD_ERR_UNKNOWN_CODEs);
end case;
readOffset <= 0;
readSize <= 0;
elsif (triggerSet = '1' and ((front > frontTrigger) or (back > backTrigger))) then
pushSend(F2AI_CAPTs); pushSend(F2AI_CAPTs);
triggerSet <= '0'; triggerSet <= '0';
end if; end if;
-- If what was sent is acknowledged or nothing is being sent atm if sendAvailable = '0' then -- If no message is being sent
if txStbs = '0' or txAck = '1' then if sendTail < sendHead or sendLooped = '1' then -- If there is a message in the queue
if sendSize = 0 then -- If no data to be sent
popSend(sendMessage); -- See if there a message in the message queue -- Update tail
case sendMessage is if sendTail < SENDQUEUE_SIZE - 1 then
when none => -- No message available, do nothing sendTail <= sendTail + 1;
else
sendTail <= 0;
sendLooped <= '0';
end if;
sendAvailable <= '1';
case sendQueueMemory(sendTail) is
when A2FD_PINGs => when A2FD_PINGs =>
sendData(7 downto 0) := A2FD_PING; sendData(7 downto 0) <= A2FD_PING;
sendSize := 1; sendSize <= 1;
when F2AI_CAPTs => when F2AI_CAPTs =>
sendData(7 downto 0) := F2AI_CAPT; sendData(7 downto 0) <= F2AI_CAPT;
sendData(23 downto 8) := std_logic_vector(to_signed(front, 16)); sendData(23 downto 8) <= std_logic_vector(to_signed(front, 16));
sendData(39 downto 24) := std_logic_vector(to_unsigned(back, 16)); sendData(39 downto 24) <= std_logic_vector(to_unsigned(back, 16));
sendSize := 5; sendSize <= 5;
when F2AI_CODERs => when F2AI_CODERs =>
zerocoder <= '1'; zerocoder <= '1';
sendData(7 downto 0) := F2AI_CODER; sendData(7 downto 0) <= F2AI_CODER;
sendData(23 downto 8) := std_logic_vector(to_signed(left, 16)); sendData(23 downto 8) <= std_logic_vector(to_signed(left, 16));
sendData(39 downto 24) := std_logic_vector(to_signed(right, 16)); sendData(39 downto 24) <= std_logic_vector(to_signed(right, 16));
sendSize := 5; sendSize <= 5;
when others => -- Including F2AD_ERR_UNKNOWN_CODEs when others => -- Including F2AD_ERR_UNKNOWN_CODEs
sendData(7 downto 0) := F2AD_ERR; sendData(7 downto 0) <= F2AD_ERR;
sendData(15 downto 8) := ERR_UNKNOWN_CODE; sendData(15 downto 8) <= ERR_UNKNOWN_CODE;
sendSize := 2; sendSize <= 2;
end case; end case;
end if; end if;
if sendSize > 0 then -- If data to be sent else -- If a message is being sent
txData <= sendData((sendOffset + 1) * 8 - 1 downto sendOffset * 8); if sendBegun = '0' or txAck = '1' then
txStbs <= '1'; sendBegun <= '1';
if sendOffset < sendSize then -- There is still data to send
if sendOffset = sendSize - 1 then -- If it was the last character sent txData <= sendData((sendOffset + 1) * 8 - 1 downto sendOffset * 8);
sendSize := 0; -- Make next iteration check for send queue txStb <= '1';
sendOffset := 0; sendOffset <= sendOffset + 1;
else -- Still data to be sent after that else -- There is no more data to send
sendOffset := sendOffset + 1; sendOffset <= 0;
txStb <= '0';
sendBegun <= '0';
sendAvailable <= '0';
end if; end if;
else -- If really no data to be sent
txStbs <= '0';
end if; end if;
end if; end if;
end if; end if;
end if; end if;
end process; end process;
end Behavioral; end Behavioral;

View file

@ -1,20 +1,20 @@
[*] [*]
[*] GTKWave Analyzer v3.3.86 (w)1999-2017 BSI [*] GTKWave Analyzer v3.3.86 (w)1999-2017 BSI
[*] Tue Feb 27 20:44:59 2018 [*] Wed Feb 28 14:53:10 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] "Tue Feb 27 20:44:10 2018" [dumpfile_mtime] "Wed Feb 28 14:51:41 2018"
[dumpfile_size] 6988 [dumpfile_size] 7845
[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] 1600 862 [size] 1600 862
[pos] -1 -1 [pos] -1 -1
*-29.975166 2184000000 -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 *-30.009827 1783000000 -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.
[sst_width] 213 [sst_width] 213
[signals_width] 126 [signals_width] 198
[sst_expanded] 1 [sst_expanded] 1
[sst_vpaned_height] 200 [sst_vpaned_height] 200
@28 @28
@ -29,6 +29,17 @@ top.communication_tb.reset
@28 @28
[color] 5 [color] 5
top.communication_tb.dut.rxstb top.communication_tb.dut.rxstb
@420
[color] 3
top.communication_tb.dut.sendhead
[color] 3
top.communication_tb.dut.sendtail
[color] 3
top.communication_tb.dut.sendsize
[color] 3
top.communication_tb.dut.sendavailable
[color] 3
top.communication_tb.dut.sendbegun
@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]
@ -44,12 +55,15 @@ top.communication_tb.dut.txack
top.communication_tb.dut.zerocoder top.communication_tb.dut.zerocoder
@420 @420
[color] 2 [color] 2
top.communication_tb.dut.left
[color] 2
top.communication_tb.dut.right
[color] 2
top.communication_tb.dut.fronttrigger top.communication_tb.dut.fronttrigger
[color] 2 [color] 2
top.communication_tb.dut.backtrigger top.communication_tb.dut.backtrigger
[color] 2 [color] 2
top.communication_tb.dut.front top.communication_tb.dut.front
@421
[color] 2 [color] 2
top.communication_tb.dut.back top.communication_tb.dut.back
[pattern_trace] 1 [pattern_trace] 1

View file

@ -69,10 +69,10 @@ begin
stimuli : process stimuli : process
variable tampon : multipleChar; variable tampon : multipleChar;
begin begin
left <= 0;
right <= 0;
front <= 0; front <= 0;
back <= 0; back <= 0;
left <= 1152;
right <= 11614;
txAck <= '0'; txAck <= '0';
rxData <= (others => '0'); rxData <= (others => '0');
rxStb <= '0'; rxStb <= '0';
@ -185,24 +185,23 @@ begin
assert txStb = '0' report "Not stopping send" severity error; assert txStb = '0' report "Not stopping send" severity error;
-- Test encoder -- Test encoder
left <= 1152;
right <= 11614;
report "TEST Receiving 'D'" severity note; report "TEST Receiving 'D'" severity note;
rxData <= x"44"; rxData <= x"44";
rxStb <= '1'; rxStb <= '1';
wait for TbPeriod; wait for TbPeriod;
rxStb <= '0';
wait for TbPeriod;
assert zerocoder = '1' report "Not reseting coder values" severity error; assert zerocoder = '1' report "Not reseting coder values" severity error;
left <= 0; left <= 0;
right <= 0; right <= 0;
rxStb <= '0';
wait for TbPeriod; wait for TbPeriod;
assert zerocoder = '0' report "Not stopping reseting coder values" severity error; assert zerocoder = '0' report "Not stopping reseting coder values" severity error;
tampon(0 to 4) := (x"44", x"80", x"04", x"5E", x"2D"); tampon(0 to 4) := (x"44", x"80", x"04", x"5E", x"2D");
for I in 0 to 4 loop for I in 0 to 4 loop
wait for 100 ns; wait for 100 ns;
assert txData = tampon(I) report "Not sent correct data, got " & integer'image(to_integer(unsigned(txData))) & ", expected " & integer'image(to_integer(unsigned(tampon(I))))severity error; assert txData = tampon(I) report "Not sent correct data, got " & integer'image(to_integer(unsigned(txData))) & ", expected " & integer'image(to_integer(unsigned(tampon(I)))) severity error;
assert txStb = '1' report "Not sending" severity error; assert txStb = '1' report "Not sending" severity error;
wait for 100 ns; wait for 100 ns;

View file

@ -1,10 +1,10 @@
[*] [*]
[*] GTKWave Analyzer v3.3.86 (w)1999-2017 BSI [*] GTKWave Analyzer v3.3.86 (w)1999-2017 BSI
[*] Wed Feb 28 09:53:14 2018 [*] Wed Feb 28 11:47:06 2018
[*] [*]
[dumpfile] "/home/geoffrey/Documents/Polytech/Robotech/2017-2018/CdF/cdf2018-principal/fpga/build/fir_tb.ghw" [dumpfile] "/home/geoffrey/Documents/Polytech/Robotech/2017-2018/CdF/cdf2018-principal/fpga/build/fir_tb.ghw"
[dumpfile_mtime] "Wed Feb 28 09:53:10 2018" [dumpfile_mtime] "Wed Feb 28 11:46:54 2018"
[dumpfile_size] 595494 [dumpfile_size] 458919
[savefile] "/home/geoffrey/Documents/Polytech/Robotech/2017-2018/CdF/cdf2018-principal/fpga/fir_tb.gtkw" [savefile] "/home/geoffrey/Documents/Polytech/Robotech/2017-2018/CdF/cdf2018-principal/fpga/fir_tb.gtkw"
[timestart] 0 [timestart] 0
[size] 1600 862 [size] 1600 862