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