1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-12-22 05:30:37 +01:00

FPGA : Envoi de valeurs des capteurs

This commit is contained in:
Geoffrey Frogeye 2018-02-26 21:12:51 +01:00
parent d0e5842ca4
commit 23ef0c57dc
4 changed files with 75 additions and 35 deletions

View file

@ -163,11 +163,13 @@ isimgui: build/isim_$(TB)$(EXE)
# Testing (using ghdl and gtkwave)
###########################################################################
GHDL_FLAGS=--mb-comments
%_syntax: %.vhd
ghdl -s --mb-comments "$<"
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)))
ghdl -e --workdir="$(shell dirname "$@")" -o "$(shell echo "$@" | tr A-Z a-z)" "$(basename $(notdir $<))"

View file

@ -33,9 +33,9 @@ architecture Behavioral of communication is
signal readState : readStates := readIdle;
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;
signal frontTrigger : integer := 0;
@ -47,11 +47,12 @@ begin
txStb <= txStbs;
readsendFA : process(clock, reset)
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;
@ -98,37 +99,50 @@ begin
case rxData is
when A2FD_PING =>
pushSend(A2FD_PINGs);
when F2AI_CODER =>
pushSend(F2AI_CODERs);
when F2AI_CAPT =>
pushSend(F2AI_CAPTs);
when others =>
pushSend(F2AD_ERR_UNKNOWN_CODEs);
end case;
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 sendMessage = none then -- Reads a message if none is currently being sent
sendOffset := 0;
popSend(sendMessage);
else
sendOffset := sendOffset + 1;
if sendSize = 0 then -- If no data to be sent
popSend(sendMessage); -- See if there a message in the message queue
case sendMessage is
when none => -- No message available, do nothing
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;
txStbs <= '1';
case sendMessage is
when none => -- If no message available: don't send anything
txStbs <= '0';
when A2FD_PINGs =>
txData <= A2FD_PING;
sendMessage := none;
when F2AD_ERR_UNKNOWN_CODEs =>
case sendOffset is
when 0 =>
txData <= F2AD_ERR;
when others =>
txData <= ERR_UNKNOWN_CODE;
sendMessage := none;
end case;
end case;
if sendSize > 0 then -- If data to be sent
txData <= sendData((sendOffset + 1) * 8 - 1 downto sendOffset * 8);
txStbs <= '1';
if sendOffset = sendSize - 1 then -- If it was the last character sent
sendSize := 0; -- Make next iteration check for send queue
sendOffset := 0;
else -- Still data to be sent after that
sendOffset := sendOffset + 1;
end if;
else -- If really no data to be sent
txStbs <= '0';
end if;
end if;
end if;
end if;

View file

@ -1,15 +1,15 @@
[*]
[*] 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_mtime] "Mon Feb 26 17:03:51 2018"
[dumpfile_size] 3315
[dumpfile_mtime] "Mon Feb 26 19:15:01 2018"
[dumpfile_size] 4519
[savefile] "/home/geoffrey/Documents/Polytech/Robotech/2017-2018/CdF/cdf2018-principal/fpga/communication_tb.gtkw"
[timestart] 0
[size] 1680 1012
[size] 1600 862
[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.communication_tb.
[treeopen] top.communication_tb.dut.
@ -34,9 +34,6 @@ top.communication_tb.dut.rxstb
top.communication_tb.dut.readstate
[color] 6
top.communication_tb.dut.readoffset
@421
[color] 2
top.communication_tb.dut.a
@22
[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]

View file

@ -4,6 +4,7 @@
library ieee;
use ieee.std_logic_1164.all;
use IEEE.NUMERIC_STD.ALL;
entity communication_tb is
end communication_tb;
@ -40,6 +41,8 @@ architecture tb of communication_tb is
signal TbClock : std_logic := '0';
signal TbSimEnded : std_logic := '0';
type multipleChar is array (0 to 15) of std_logic_vector(7 downto 0);
begin
dut : communication
@ -61,6 +64,7 @@ begin
clock <= TbClock;
stimuli : process
variable shouldReceive : multipleChar;
begin
left <= 0;
right <= 0;
@ -156,8 +160,31 @@ begin
wait for 100 ns;
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';
wait;