Добавили аппаратный контроль таймаута в шине для готовности периферийный плат. Добавили в регистр контроля шины состояние передачи (бит 1). Уменьшили период такта по сихросигналу на четверть.
This commit is contained in:
parent
6b28fad4b1
commit
92fd7969bc
@ -43,7 +43,7 @@ signal addressToTransmit : std_logic_vector(7 downto 0) := x"00";
|
|||||||
signal dataToTransmit : std_logic_vector(15 downto 0) := x"0000";
|
signal dataToTransmit : std_logic_vector(15 downto 0) := x"0000";
|
||||||
signal dataFromDevices : std_logic_vector(15 downto 0) := x"0000";
|
signal dataFromDevices : std_logic_vector(15 downto 0) := x"0000";
|
||||||
|
|
||||||
type CommunicationState_start is (Waiting, TransmitAddress, TransmitData, TransmitCRC, TransmitCheck, ReceiveData, ReceiveCRC, ReceiveCheck);
|
type CommunicationState_start is (Waiting, TransmitAddress, TransmitData, TransmitCRC, TransmitCheck, ReceiveData, ReceiveCRC, ReceiveCheck, Timeout);
|
||||||
signal CommunicationState : CommunicationState_start := Waiting ;
|
signal CommunicationState : CommunicationState_start := Waiting ;
|
||||||
|
|
||||||
signal resetCRC : std_logic := '1';
|
signal resetCRC : std_logic := '1';
|
||||||
@ -110,7 +110,8 @@ begin
|
|||||||
|
|
||||||
process(clk) is
|
process(clk) is
|
||||||
variable count : integer range 0 to 255 := 0;
|
variable count : integer range 0 to 255 := 0;
|
||||||
variable countValue : integer range 0 to 255 := 50;
|
variable halfPeriod : integer range 0 to 255 := 50;
|
||||||
|
variable pause : integer range 0 to 255 := 200;
|
||||||
variable state : integer range 0 to 1 := 1;
|
variable state : integer range 0 to 1 := 1;
|
||||||
variable bitCnt : integer range -1 to 31 := 0;
|
variable bitCnt : integer range -1 to 31 := 0;
|
||||||
variable latch : integer range 0 to 1 := 0;
|
variable latch : integer range 0 to 1 := 0;
|
||||||
@ -122,9 +123,7 @@ begin
|
|||||||
bitCnt := 8;
|
bitCnt := 8;
|
||||||
latch := 0;
|
latch := 0;
|
||||||
resetCRC <= '1';
|
resetCRC <= '1';
|
||||||
sbdataout <= '0';
|
sbdataout <= '0';
|
||||||
lineBusy <= '0';
|
|
||||||
count := 0;
|
|
||||||
state := 1;
|
state := 1;
|
||||||
if start = '1' and startPrev = '0' then
|
if start = '1' and startPrev = '0' then
|
||||||
direction <= cmdBuf(15);
|
direction <= cmdBuf(15);
|
||||||
@ -132,11 +131,32 @@ begin
|
|||||||
addressToTransmit(7 downto 0) <= cmdBuf(7 downto 0);
|
addressToTransmit(7 downto 0) <= cmdBuf(7 downto 0);
|
||||||
dataCRC(23 downto 16) <= cmdBuf(7 downto 0);
|
dataCRC(23 downto 16) <= cmdBuf(7 downto 0);
|
||||||
dataToTransmit <= dataBufIn;
|
dataToTransmit <= dataBufIn;
|
||||||
dataCRC(15 downto 0) <= dataBufIn;
|
dataCRC(15 downto 0) <= dataBufIn;
|
||||||
CommunicationState <= TransmitAddress;
|
controlBuf(15 downto 2) <= (others => '0');
|
||||||
lineBusy <= '1';
|
controlBuf(1) <= '1';
|
||||||
controlBuf <= (others => '0');
|
controlBuf(0) <= '0';
|
||||||
|
if count < pause then
|
||||||
|
CommunicationState <= Timeout;
|
||||||
|
count := count + 1;
|
||||||
|
else
|
||||||
|
CommunicationState <= TransmitAddress;
|
||||||
|
count:= 0;
|
||||||
|
end if;
|
||||||
|
else
|
||||||
|
if count < pause then
|
||||||
|
count := count + 1;
|
||||||
|
controlBuf(1) <= '1';
|
||||||
|
else
|
||||||
|
controlBuf(1) <= '0';
|
||||||
|
end if;
|
||||||
end if;
|
end if;
|
||||||
|
when Timeout =>
|
||||||
|
if count < pause then
|
||||||
|
count := count + 1;
|
||||||
|
else
|
||||||
|
CommunicationState <= TransmitAddress;
|
||||||
|
count:= 0;
|
||||||
|
end if;
|
||||||
when TransmitAddress =>
|
when TransmitAddress =>
|
||||||
if bitCnt = -1 then
|
if bitCnt = -1 then
|
||||||
if direction = '1' then
|
if direction = '1' then
|
||||||
@ -147,7 +167,7 @@ begin
|
|||||||
end if;
|
end if;
|
||||||
bitCnt := 15;
|
bitCnt := 15;
|
||||||
else
|
else
|
||||||
if count < countValue and state = 1 then
|
if count < halfPeriod and state = 1 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
if latch = 0 then
|
if latch = 0 then
|
||||||
sbdataout <= direction;
|
sbdataout <= direction;
|
||||||
@ -157,16 +177,16 @@ begin
|
|||||||
sbclk <= '0';
|
sbclk <= '0';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 1 then
|
elsif count = halfPeriod and state = 1 then
|
||||||
latch := 1;
|
latch := 1;
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 0;
|
state := 0;
|
||||||
elsif count < countValue and state = 0 then
|
elsif count < halfPeriod and state = 0 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbclk <= '1';
|
sbclk <= '1';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 0 then
|
elsif count = halfPeriod and state = 0 then
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 1;
|
state := 1;
|
||||||
bitCnt := bitCnt - 1;
|
bitCnt := bitCnt - 1;
|
||||||
@ -177,21 +197,21 @@ begin
|
|||||||
CommunicationState <= TransmitCRC;
|
CommunicationState <= TransmitCRC;
|
||||||
bitCnt := 3;
|
bitCnt := 3;
|
||||||
else
|
else
|
||||||
if count < countValue and state = 1 then
|
if count < halfPeriod and state = 1 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbdataout <= dataToTransmit(bitCnt);
|
sbdataout <= dataToTransmit(bitCnt);
|
||||||
sbclk <= '0';
|
sbclk <= '0';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 1 then
|
elsif count = halfPeriod and state = 1 then
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 0;
|
state := 0;
|
||||||
elsif count < countValue and state = 0 then
|
elsif count < halfPeriod and state = 0 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbclk <= '1';
|
sbclk <= '1';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 0 then
|
elsif count = halfPeriod and state = 0 then
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 1;
|
state := 1;
|
||||||
bitCnt := bitCnt - 1;
|
bitCnt := bitCnt - 1;
|
||||||
@ -202,32 +222,33 @@ begin
|
|||||||
if bitCnt = -1 then
|
if bitCnt = -1 then
|
||||||
CommunicationState <= TransmitCheck;
|
CommunicationState <= TransmitCheck;
|
||||||
else
|
else
|
||||||
if count < countValue and state = 1 then
|
if count < halfPeriod and state = 1 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbdataout <= CRC(bitCnt);
|
sbdataout <= CRC(bitCnt);
|
||||||
sbclk <= '0';
|
sbclk <= '0';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 1 then
|
elsif count = halfPeriod and state = 1 then
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 0;
|
state := 0;
|
||||||
elsif count < countValue and state = 0 then
|
elsif count < halfPeriod and state = 0 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbclk <= '1';
|
sbclk <= '1';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 0 then
|
elsif count = halfPeriod and state = 0 then
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 1;
|
state := 1;
|
||||||
bitCnt := bitCnt - 1;
|
bitCnt := bitCnt - 1;
|
||||||
end if;
|
end if;
|
||||||
end if;
|
end if;
|
||||||
else
|
else
|
||||||
|
count := 0;
|
||||||
CommunicationState <= Waiting;
|
CommunicationState <= Waiting;
|
||||||
controlBuf(15) <= '1';
|
controlBuf(15) <= '1';
|
||||||
end if;
|
end if;
|
||||||
when TransmitCheck =>
|
when TransmitCheck =>
|
||||||
if count < countValue and state = 1 then
|
if count < halfPeriod and state = 1 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbclk <= '0';
|
sbclk <= '0';
|
||||||
end if;
|
end if;
|
||||||
@ -247,21 +268,21 @@ begin
|
|||||||
CommunicationState <= ReceiveCRC;
|
CommunicationState <= ReceiveCRC;
|
||||||
bitCnt := 3;
|
bitCnt := 3;
|
||||||
else
|
else
|
||||||
if count < countValue and state = 1 then
|
if count < halfPeriod and state = 1 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbclk <= '0';
|
sbclk <= '0';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 1 then
|
elsif count = halfPeriod and state = 1 then
|
||||||
dataFromDevices(bitCnt) <= sbdatain;
|
dataFromDevices(bitCnt) <= sbdatain;
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 0;
|
state := 0;
|
||||||
elsif count < countValue and state = 0 then
|
elsif count < halfPeriod and state = 0 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbclk <= '1';
|
sbclk <= '1';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 0 then
|
elsif count = halfPeriod and state = 0 then
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 1;
|
state := 1;
|
||||||
bitCnt := bitCnt - 1;
|
bitCnt := bitCnt - 1;
|
||||||
@ -271,12 +292,12 @@ begin
|
|||||||
if bitCnt = -1 then
|
if bitCnt = -1 then
|
||||||
CommunicationState <= ReceiveCheck;
|
CommunicationState <= ReceiveCheck;
|
||||||
else
|
else
|
||||||
if count < countValue and state = 1 then
|
if count < halfPeriod and state = 1 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbclk <= '0';
|
sbclk <= '0';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 1 then
|
elsif count = halfPeriod and state = 1 then
|
||||||
bufCRC(BitCnt) <= sbdatain;
|
bufCRC(BitCnt) <= sbdatain;
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 0;
|
state := 0;
|
||||||
@ -286,12 +307,12 @@ begin
|
|||||||
dataCRC(15 downto 0) <= dataFromDevices(15 downto 0);
|
dataCRC(15 downto 0) <= dataFromDevices(15 downto 0);
|
||||||
resetCRC <= '0';
|
resetCRC <= '0';
|
||||||
end if;
|
end if;
|
||||||
elsif count < countValue and state = 0 then
|
elsif count < halfPeriod and state = 0 then
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
sbclk <= '1';
|
sbclk <= '1';
|
||||||
end if;
|
end if;
|
||||||
count := count + 1;
|
count := count + 1;
|
||||||
elsif count = countValue and state = 0 then
|
elsif count = halfPeriod and state = 0 then
|
||||||
count := 0;
|
count := 0;
|
||||||
state := 1;
|
state := 1;
|
||||||
bitCnt := bitCnt - 1;
|
bitCnt := bitCnt - 1;
|
||||||
@ -308,8 +329,11 @@ begin
|
|||||||
else
|
else
|
||||||
controlBuf(12) <= '1';
|
controlBuf(12) <= '1';
|
||||||
end if;
|
end if;
|
||||||
|
count := 0;
|
||||||
CommunicationState <= Waiting;
|
CommunicationState <= Waiting;
|
||||||
when others =>
|
when others =>
|
||||||
|
count := 0;
|
||||||
|
CommunicationState <= Waiting;
|
||||||
end case;
|
end case;
|
||||||
startPrev <= start;
|
startPrev <= start;
|
||||||
end if;
|
end if;
|
||||||
|
Loading…
Reference in New Issue
Block a user