Line 40... |
Line 40... |
-- Signals used to control the configuration
|
-- Signals used to control the configuration
|
signal startConfigBaud : std_logic;
|
signal startConfigBaud : std_logic;
|
signal startConfigClk : std_logic;
|
signal startConfigClk : std_logic;
|
signal startDataSend : std_logic;
|
signal startDataSend : std_logic;
|
signal commBlocksInitiated : std_logic;
|
signal commBlocksInitiated : std_logic;
|
signal finishedDataSend : std_logic;
|
|
signal doneWriteReg : std_logic;
|
signal doneWriteReg : std_logic;
|
signal startReadReg : std_logic;
|
signal startReadReg : std_logic;
|
|
signal alreadyConfBaud : std_logic;
|
|
signal alreadyConfClk : std_logic;
|
|
|
-- Divisor component
|
-- Divisor component
|
component divisor is
|
component divisor is
|
Port ( rst : in STD_LOGIC;
|
Port ( rst : in STD_LOGIC;
|
clk : in STD_LOGIC;
|
clk : in STD_LOGIC;
|
Line 80... |
Line 81... |
byte_to_transmit <= (others => '0');
|
byte_to_transmit <= (others => '0');
|
startConfigBaud <= '0';
|
startConfigBaud <= '0';
|
startConfigClk <= '0';
|
startConfigClk <= '0';
|
startDataSend <= '0';
|
startDataSend <= '0';
|
doneWriteReg <= '0';
|
doneWriteReg <= '0';
|
|
alreadyConfClk <= '0';
|
|
alreadyConfBaud <= '0';
|
elsif (WE and start) = '1' then
|
elsif (WE and start) = '1' then
|
case reg_addr is
|
case reg_addr is
|
when "00" =>
|
when "00" =>
|
config_clk <= DAT_I;
|
config_clk <= DAT_I;
|
startConfigClk <= '1';
|
startConfigClk <= '1';
|
startDataSend <= '0';
|
startDataSend <= '0';
|
startConfigBaud <= '0';
|
startConfigBaud <= '0';
|
|
alreadyConfClk <= '1';
|
when "01" =>
|
when "01" =>
|
config_baud <= DAT_I;
|
config_baud <= DAT_I;
|
startConfigBaud <= '1';
|
startConfigBaud <= '1';
|
startDataSend <= '0';
|
startDataSend <= '0';
|
startConfigClk <= '0';
|
startConfigClk <= '0';
|
|
alreadyConfBaud <= '1';
|
when "10" =>
|
when "10" =>
|
-- If we have an overrun, discard the byte
|
-- If we have an overrun, discard the byte
|
if finishedDataSend = '1' then
|
|
byte_to_transmit <= DAT_I((nBits-1) downto 0);
|
byte_to_transmit <= DAT_I((nBits-1) downto 0);
|
else
|
|
byte_to_transmit <= byte_to_transmit;
|
|
end if;
|
|
startConfigBaud <= '0';
|
startConfigBaud <= '0';
|
startConfigClk <= '0';
|
startConfigClk <= '0';
|
startDataSend <= '1';
|
startDataSend <= '1';
|
when others =>
|
when others =>
|
startConfigBaud <= '0';
|
startConfigBaud <= '0';
|
Line 148... |
Line 149... |
received_byte <= received_byte;
|
received_byte <= received_byte;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
-- Process to send data over the serial transmitter
|
-- Process to send data over the serial transmitter
|
process (startDataSend, commBlocksInitiated, clk)
|
process (clk)
|
variable cont_steps : integer range 0 to 3;
|
variable cont_steps : integer range 0 to 3;
|
begin
|
begin
|
if (startDataSend = '0' and commBlocksInitiated = '0') then
|
if rising_edge(clk) then
|
data_byte_tx <= (others => '0');
|
if (rst = '1') then
|
tx_start <= '0';
|
cont_steps := 0;
|
finishedDataSend <= '1';
|
|
elsif rising_edge(clk) then
|
|
if cont_steps < 3 then
|
|
cont_steps := cont_steps + 1;
|
|
else
|
else
|
cont_steps := 3;
|
if commBlocksInitiated = '1' and startDataSend = '1' then
|
end if;
|
|
|
|
case cont_steps is
|
case cont_steps is
|
when 1 =>
|
when 0 =>
|
data_byte_tx <= byte_to_transmit;
|
data_byte_tx <= byte_to_transmit;
|
tx_start <= '0';
|
tx_start <= '0';
|
when 2 =>
|
when 1 =>
|
tx_start <= '1';
|
tx_start <= '1';
|
when others =>
|
when others =>
|
null;
|
null;
|
end case;
|
end case;
|
|
if cont_steps < 3 then
|
if tx_data_sent = '1' then
|
cont_steps := cont_steps + 1;
|
finishedDataSend <= '1';
|
|
else
|
else
|
finishedDataSend <= '0';
|
cont_steps := 3;
|
|
end if;
|
|
end if;
|
end if;
|
end if;
|
|
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
-- Process to send the ACK signal, remember that optimally this ACK should be as fast as possible
|
-- Process to send the ACK signal, remember that optimally this ACK should be as fast as possible
|
-- to avoid locking the bus, on this case if you send a more bytes then you can transmit the ideal
|
-- to avoid locking the bus, on this case if you send a more bytes then you can transmit the ideal
|
Line 221... |
Line 216... |
|
|
-- Process to calculate the amount of cycles to wait (clock_speed / desired_baud), and initiate the board
|
-- Process to calculate the amount of cycles to wait (clock_speed / desired_baud), and initiate the board
|
process (startConfigBaud,startConfigClk, clk)
|
process (startConfigBaud,startConfigClk, clk)
|
variable cont_steps : integer range 0 to 3;
|
variable cont_steps : integer range 0 to 3;
|
begin
|
begin
|
if (startConfigBaud and startConfigClk) = '0' then
|
if (alreadyConfClk and alreadyConfBaud) = '0' then
|
sigDivRst <= '1';
|
sigDivRst <= '1';
|
cont_steps := 0;
|
cont_steps := 0;
|
baud_wait <= (others => '0');
|
baud_wait <= (others => '0');
|
commBlocksInitiated <= '0';
|
commBlocksInitiated <= '0';
|
elsif rising_edge(clk) then
|
elsif rising_edge(clk) then
|