📄 spi.vhd
字号:
if std_logic'(control_wr_strobe) = '1' then
iEOP_reg <= data_from_cpu(9);
iE_reg <= data_from_cpu(8);
iRRDY_reg <= data_from_cpu(7);
iTRDY_reg <= data_from_cpu(6);
iTMT_reg <= data_from_cpu(5);
iTOE_reg <= data_from_cpu(4);
iROE_reg <= data_from_cpu(3);
SSO_reg <= data_from_cpu(10);
end if;
end if;
end process;
spi_control <= Std_Logic_Vector'(A_ToStdLogicVector(SSO_reg) & A_ToStdLogicVector(iEOP_reg) & A_ToStdLogicVector(iE_reg) & A_ToStdLogicVector(iRRDY_reg) & A_ToStdLogicVector(iTRDY_reg) & A_ToStdLogicVector(std_logic'('0')) & A_ToStdLogicVector(iTOE_reg) & A_ToStdLogicVector(iROE_reg) & std_logic_vector'("000"));
-- IRQ output.
process (clk, reset_n)
begin
if reset_n = '0' then
irq_reg <= std_logic'('0');
elsif clk'event and clk = '1' then
if (std_logic_vector'("00000000000000000000000000000001")) /= std_logic_vector'("00000000000000000000000000000000") then
irq_reg <= ((((((EOP AND iEOP_reg)) OR ((((TOE OR ROE)) AND iE_reg))) OR ((RRDY AND iRRDY_reg))) OR ((TRDY AND iTRDY_reg))) OR ((TOE AND iTOE_reg))) OR ((ROE AND iROE_reg));
end if;
end if;
end process;
irq <= irq_reg;
-- Slave select register.
process (clk, reset_n)
begin
if reset_n = '0' then
spi_slave_select_reg <= std_logic_vector'("0000000000000001");
elsif clk'event and clk = '1' then
if std_logic'((write_shift_reg OR ((control_wr_strobe AND data_from_cpu(10)) AND NOT SSO_reg))) = '1' then
spi_slave_select_reg <= spi_slave_select_holding_reg;
end if;
end if;
end process;
-- Slave select holding register.
process (clk, reset_n)
begin
if reset_n = '0' then
spi_slave_select_holding_reg <= std_logic_vector'("0000000000000001");
elsif clk'event and clk = '1' then
if std_logic'(slaveselect_wr_strobe) = '1' then
spi_slave_select_holding_reg <= data_from_cpu;
end if;
end if;
end process;
-- slowclock is active once every 196 system clock pulses.
slowclock <= to_std_logic((slowcount = std_logic_vector'("11000011")));
p1_slowcount <= A_EXT (((((std_logic_vector'("0000000000000000000000000") & (A_REP(((transmitting AND NOT(slowclock))) , 8))) AND (((std_logic_vector'("0000000000000000000000000") & (slowcount)) + std_logic_vector'("000000000000000000000000000000001"))))) OR (std_logic_vector'("0") & ((((std_logic_vector'("000000000000000000000000") & (A_REP((NOT ((transmitting AND NOT(slowclock)))) , 8))) AND std_logic_vector'("00000000000000000000000000000000")))))), 8);
-- Divide counter for SPI clock.
process (clk, reset_n)
begin
if reset_n = '0' then
slowcount <= std_logic_vector'("00000000");
elsif clk'event and clk = '1' then
if (std_logic_vector'("00000000000000000000000000000001")) /= std_logic_vector'("00000000000000000000000000000000") then
slowcount <= p1_slowcount;
end if;
end if;
end process;
-- End-of-packet value register.
process (clk, reset_n)
begin
if reset_n = '0' then
endofpacketvalue_reg <= std_logic_vector'("0000000000000000");
elsif clk'event and clk = '1' then
if std_logic'(endofpacketvalue_wr_strobe) = '1' then
endofpacketvalue_reg <= data_from_cpu;
end if;
end if;
end process;
p1_data_to_cpu <= A_WE_StdLogicVector((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000010"))), (std_logic_vector'("00000") & (spi_status)), A_WE_StdLogicVector((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000011"))), (std_logic_vector'("00000") & (spi_control)), A_WE_StdLogicVector((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000110"))), endofpacketvalue_reg, A_WE_StdLogicVector((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000101"))), spi_slave_select_reg, (std_logic_vector'("00000000") & (rx_holding_reg))))));
process (clk, reset_n)
begin
if reset_n = '0' then
data_to_cpu <= std_logic_vector'("0000000000000000");
elsif clk'event and clk = '1' then
-- Data to cpu.
data_to_cpu <= p1_data_to_cpu;
end if;
end process;
-- 'state' counts from 0 to 17.
process (clk, reset_n)
begin
if reset_n = '0' then
state <= std_logic_vector'("00000");
stateZero <= std_logic'('1');
elsif clk'event and clk = '1' then
if std_logic'((transmitting AND slowclock)) = '1' then
stateZero <= to_std_logic(((std_logic_vector'("000000000000000000000000000") & (state)) = std_logic_vector'("00000000000000000000000000010001")));
if (std_logic_vector'("000000000000000000000000000") & (state)) = std_logic_vector'("00000000000000000000000000010001") then
state <= std_logic_vector'("00000");
else
state <= A_EXT (((std_logic_vector'("0000000000000000000000000000") & (state)) + std_logic_vector'("000000000000000000000000000000001")), 5);
end if;
end if;
end if;
end process;
enableSS <= transmitting AND NOT stateZero;
MOSI <= shift_reg(7);
SS_n <= Vector_To_Std_Logic(A_WE_StdLogicVector((std_logic'(((enableSS OR SSO_reg))) = '1'), NOT spi_slave_select_reg, (std_logic_vector'("000000000000000") & (A_TOSTDLOGICVECTOR(std_logic'('1'))))));
SCLK <= SCLK_reg;
-- As long as there's an empty spot somewhere,
--it's safe to write data.
TRDY <= NOT ((transmitting AND tx_holding_primed));
-- Enable write to tx_holding_register.
write_tx_holding <= data_wr_strobe AND TRDY;
-- Enable write to shift register.
write_shift_reg <= tx_holding_primed AND NOT transmitting;
process (clk, reset_n)
begin
if reset_n = '0' then
shift_reg <= std_logic_vector'("00000000");
rx_holding_reg <= std_logic_vector'("00000000");
EOP <= std_logic'('0');
RRDY <= std_logic'('0');
ROE <= std_logic'('0');
TOE <= std_logic'('0');
tx_holding_reg <= std_logic_vector'("00000000");
tx_holding_primed <= std_logic'('0');
transmitting <= std_logic'('0');
SCLK_reg <= std_logic'('0');
MISO_reg <= std_logic'('0');
elsif clk'event and clk = '1' then
if std_logic'(write_tx_holding) = '1' then
tx_holding_reg <= data_from_cpu (7 DOWNTO 0);
tx_holding_primed <= std_logic'('1');
end if;
if std_logic'((data_wr_strobe AND NOT TRDY)) = '1' then
-- You wrote when I wasn't ready.
TOE <= std_logic'('1');
end if;
-- EOP must be updated by the last (2nd) cycle of access.
if std_logic'((((p1_data_rd_strobe AND to_std_logic((((std_logic_vector'("00000000") & (rx_holding_reg)) = endofpacketvalue_reg))))) OR ((p1_data_wr_strobe AND to_std_logic((((std_logic_vector'("00000000") & (data_from_cpu(7 DOWNTO 0))) = endofpacketvalue_reg))))))) = '1' then
EOP <= std_logic'('1');
end if;
if std_logic'(write_shift_reg) = '1' then
shift_reg <= tx_holding_reg;
transmitting <= std_logic'('1');
end if;
if std_logic'((write_shift_reg AND NOT write_tx_holding)) = '1' then
-- Clear tx_holding_primed
tx_holding_primed <= std_logic'('0');
end if;
if std_logic'(data_rd_strobe) = '1' then
-- On data read, clear the RRDY bit.
RRDY <= std_logic'('0');
end if;
if std_logic'(status_wr_strobe) = '1' then
-- On status write, clear all status bits (ignore the data).
EOP <= std_logic'('0');
RRDY <= std_logic'('0');
ROE <= std_logic'('0');
TOE <= std_logic'('0');
end if;
if std_logic'(slowclock) = '1' then
if (std_logic_vector'("000000000000000000000000000") & (state)) = std_logic_vector'("00000000000000000000000000010001") then
transmitting <= std_logic'('0');
RRDY <= std_logic'('1');
rx_holding_reg <= shift_reg;
SCLK_reg <= std_logic'('0');
if std_logic'(RRDY) = '1' then
ROE <= std_logic'('1');
end if;
elsif (std_logic_vector'("000000000000000000000000000") & (state)) /= std_logic_vector'("00000000000000000000000000000000") then
if std_logic'(transmitting) = '1' then
SCLK_reg <= NOT SCLK_reg;
end if;
end if;
if ((((std_logic_vector'("0000000000000000000000000000000") & (A_TOSTDLOGICVECTOR(SCLK_reg))) XOR std_logic_vector'("00000000000000000000000000000000")) XOR std_logic_vector'("00000000000000000000000000000000"))) /= std_logic_vector'("00000000000000000000000000000000") then
if (std_logic_vector'("00000000000000000000000000000001")) /= std_logic_vector'("00000000000000000000000000000000") then
shift_reg <= Std_Logic_Vector'(shift_reg(6 DOWNTO 0) & A_ToStdLogicVector(MISO_reg));
end if;
else
MISO_reg <= MISO;
end if;
end if;
end if;
end process;
end europa;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -