📄 micro_tb.vhd
字号:
wait until clk'event and clk ='1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
end loop;
-- wait for MCF to indicate that transfer is complete
-- then write data to to Masters data register for transfer over I2C
for i in 1 to 6 loop
cycle <= cycle + 1;
wait until mcf = '1';
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
end loop;
-- generate stop once tranfer is complete
cycle <= cycle + 1;
wait until mcf = '1';
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
-- now read the status registers
write <= '0';
for i in 0 to 2 loop
cycle <= cycle + 1;
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
end loop;
-- The loop below writes the registers, sets the I2C header and
-- generates the START signal for a slave transmit/master receive cycle
write <= '1';
for i in 0 to 2 loop
cycle <= cycle + 1;
go <= '1';
wait until clk'event and clk ='1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
end loop;
-- wait for MCF to indicate that transfer is complete
-- then write data to to slave's data register for transfer over I2C
for i in 1 to 6 loop
cycle <= cycle + 1;
wait until mcf = '1';
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
end loop;
-- turn off Master's ACK
-- wait for MCF to negate again to insure no longer in ACK state
wait until mcf = '0';
cycle <= cycle + 1;
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
-- generate STOP
cycle <= cycle + 1;
wait until mcf = '1';
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
-- Beginning of Repeated START test
-- now read the status registers
write <= '0';
for i in 0 to 2 loop
cycle <= cycle + 1;
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
end loop;
-- The loop below writes the registers, sets the SMBUS header and
-- generates the START signal for a master transmit/slave receive cycle
write <= '1';
for i in 0 to 2 loop
cycle <= cycle + 1;
go <= '1';
wait until clk'event and clk ='1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
end loop;
-- wait for MCF to indicate that transfer is complete
-- then write one data byte to master's data register for transfer over SMBUS
cycle <= cycle + 1;
wait until mcf = '1';
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
-- wait for MCF to indicate that transfer is complete
-- then set the SMBUS header indicating slave read and
-- generates the REPEATED START signal for a slave transmit/master receive cycle
wait until mcf = '1';
for i in 0 to 2 loop
cycle <= cycle + 1;
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
end loop;
-- wait for MCF to indicate that transfer is complete
-- then write data to to slave's data register for transfer over SMBUS
for i in 1 to 6 loop
cycle <= cycle + 1;
wait until mcf = '1';
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
end loop;
-- turn off Master's ACK
-- wait for MCF to negate again to insure no longer in ACK state
wait until mcf = '0';
cycle <= cycle + 1;
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
-- generate STOP
cycle <= cycle + 1;
wait until mcf = '1';
go <= '1';
wait until clk'event and clk = '1';
wait until clk'event and clk = '1';
go <= '0';
wait until done = '1';
wait;
end process;
-- *********************************** Write State Machine Processes *********************************
-- Define the synchronous process of the state machines
-- the outputs get the value from the state machine that is active
ffs: process(reset, clk)
begin
if reset = RESET_ACTIVE then
state <= IDLE;
elsif clk'event and (clk = '1') then
state <= next_state;
end if;
end process;
-- Synthesize uProc write protocol
write_sm: process(state, dtack, go)
begin
next_state <= state;
done <= '1';
case state is
-------------- IDLE State -----------------
when IDLE =>
address <= (others => '0');
data_out <= (others => '0');
as <= '1';
ds <= '1';
data_in <= (others => '0');
if go = '1' then
next_state <= WAIT_DTACK;
address <= TST_ADDR_OUT(cycle);
if write = '1' then
data_out <= TST_DATA_OUT(cycle);
end if;
done <= '0';
else
next_state <= IDLE;
end if;
----------- WAIT_DTACK State --------------
when WAIT_DTACK =>
as <= '0';
ds <= '0';
address <= TST_ADDR_OUT(cycle);
if write = '1' then
data_out <= TST_DATA_OUT(cycle);
end if;
done <= '0';
-- Wait for assertion on dtack
if dtack /= '0' then
next_state <= WAIT_DTACK;
-- When dtack is asserted, transfer data
else
next_state <= DATA_TRS;
end if;
------------ DATA_TRS State ---------------
when DATA_TRS =>
as <= '1';
ds <= '1';
address <= TST_ADDR_OUT(cycle);
if write = '1' then
data_out <= TST_DATA_OUT(cycle);
else
data_in <= data_bus;
end if;
done <= '0';
-- Wait for de-assertion of dtack
if dtack = '0' then
next_state <= DATA_TRS;
else
next_state <= IDLE;
end if;
end case;
end process;
end RTL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -