📄 spi.vhd
字号:
--Legal Notice: (C)2007 Altera Corporation. All rights reserved. Your
--use of Altera Corporation's design tools, logic functions and other
--software and tools, and its AMPP partner logic functions, and any
--output files any of the foregoing (including device programming or
--simulation files), and any associated documentation or information are
--expressly subject to the terms and conditions of the Altera Program
--License Subscription Agreement or other applicable license agreement,
--including, without limitation, that your use is for the sole purpose
--of programming logic devices manufactured by Altera and sold by Altera
--or its authorized distributors. Please refer to the applicable
--agreement for further details.
-- turn off superfluous VHDL processor warnings
-- altera message_level Level1
-- altera message_off 10034 10035 10036 10037 10230 10240 10030
library altera;
use altera.altera_europa_support_lib.all;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--Register map:
--addr register type
--0 read data r
--1 write data w
--2 status r/w
--3 control r/w
--4 reserved
--5 slave-enable r/w
--6 end-of-packet-value r/w
--INPUT_CLOCK: 50000000
--ISMASTER: 1
--DATABITS: 8
--TARGETCLOCK: 128000
--NUMSLAVES: 1
--CPOL: 0
--CPHA: 0
--LSBFIRST: 0
--EXTRADELAY: 0
--TARGETSSDELAY: 0
entity spi is
port (
-- inputs:
signal MISO : IN STD_LOGIC;
signal clk : IN STD_LOGIC;
signal data_from_cpu : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
signal mem_addr : IN STD_LOGIC_VECTOR (2 DOWNTO 0);
signal read_n : IN STD_LOGIC;
signal reset_n : IN STD_LOGIC;
signal spi_select : IN STD_LOGIC;
signal write_n : IN STD_LOGIC;
-- outputs:
signal MOSI : OUT STD_LOGIC;
signal SCLK : OUT STD_LOGIC;
signal SS_n : OUT STD_LOGIC;
signal data_to_cpu : OUT STD_LOGIC_VECTOR (15 DOWNTO 0);
signal dataavailable : OUT STD_LOGIC;
signal endofpacket : OUT STD_LOGIC;
signal irq : OUT STD_LOGIC;
signal readyfordata : OUT STD_LOGIC
);
end entity spi;
architecture europa of spi is
signal E : STD_LOGIC;
signal EOP : STD_LOGIC;
signal MISO_reg : STD_LOGIC;
signal ROE : STD_LOGIC;
signal RRDY : STD_LOGIC;
signal SCLK_reg : STD_LOGIC;
signal SSO_reg : STD_LOGIC;
signal TMT : STD_LOGIC;
signal TOE : STD_LOGIC;
signal TRDY : STD_LOGIC;
signal control_wr_strobe : STD_LOGIC;
signal data_rd_strobe : STD_LOGIC;
signal data_wr_strobe : STD_LOGIC;
signal enableSS : STD_LOGIC;
signal endofpacketvalue_reg : STD_LOGIC_VECTOR (15 DOWNTO 0);
signal endofpacketvalue_wr_strobe : STD_LOGIC;
signal iEOP_reg : STD_LOGIC;
signal iE_reg : STD_LOGIC;
signal iROE_reg : STD_LOGIC;
signal iRRDY_reg : STD_LOGIC;
signal iTMT_reg : STD_LOGIC;
signal iTOE_reg : STD_LOGIC;
signal iTRDY_reg : STD_LOGIC;
signal irq_reg : STD_LOGIC;
signal p1_data_rd_strobe : STD_LOGIC;
signal p1_data_to_cpu : STD_LOGIC_VECTOR (15 DOWNTO 0);
signal p1_data_wr_strobe : STD_LOGIC;
signal p1_rd_strobe : STD_LOGIC;
signal p1_slowcount : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal p1_wr_strobe : STD_LOGIC;
signal rd_strobe : STD_LOGIC;
signal rx_holding_reg : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal shift_reg : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal slaveselect_wr_strobe : STD_LOGIC;
signal slowclock : STD_LOGIC;
signal slowcount : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal spi_control : STD_LOGIC_VECTOR (10 DOWNTO 0);
signal spi_slave_select_holding_reg : STD_LOGIC_VECTOR (15 DOWNTO 0);
signal spi_slave_select_reg : STD_LOGIC_VECTOR (15 DOWNTO 0);
signal spi_status : STD_LOGIC_VECTOR (10 DOWNTO 0);
signal state : STD_LOGIC_VECTOR (4 DOWNTO 0);
signal stateZero : STD_LOGIC;
signal status_wr_strobe : STD_LOGIC;
signal transmitting : STD_LOGIC;
signal tx_holding_primed : STD_LOGIC;
signal tx_holding_reg : STD_LOGIC_VECTOR (7 DOWNTO 0);
signal wr_strobe : STD_LOGIC;
signal write_shift_reg : STD_LOGIC;
signal write_tx_holding : STD_LOGIC;
begin
--spi_control_port, which is an e_avalon_slave
p1_rd_strobe <= (NOT rd_strobe AND spi_select) AND NOT read_n;
-- Read is a two-cycle event.
process (clk, reset_n)
begin
if reset_n = '0' then
rd_strobe <= std_logic'('0');
elsif clk'event and clk = '1' then
if (std_logic_vector'("00000000000000000000000000000001")) /= std_logic_vector'("00000000000000000000000000000000") then
rd_strobe <= p1_rd_strobe;
end if;
end if;
end process;
p1_data_rd_strobe <= p1_rd_strobe AND to_std_logic((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000000"))));
process (clk, reset_n)
begin
if reset_n = '0' then
data_rd_strobe <= std_logic'('0');
elsif clk'event and clk = '1' then
if (std_logic_vector'("00000000000000000000000000000001")) /= std_logic_vector'("00000000000000000000000000000000") then
data_rd_strobe <= p1_data_rd_strobe;
end if;
end if;
end process;
p1_wr_strobe <= (NOT wr_strobe AND spi_select) AND NOT write_n;
-- Write is a two-cycle event.
process (clk, reset_n)
begin
if reset_n = '0' then
wr_strobe <= std_logic'('0');
elsif clk'event and clk = '1' then
if (std_logic_vector'("00000000000000000000000000000001")) /= std_logic_vector'("00000000000000000000000000000000") then
wr_strobe <= p1_wr_strobe;
end if;
end if;
end process;
p1_data_wr_strobe <= p1_wr_strobe AND to_std_logic((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000001"))));
process (clk, reset_n)
begin
if reset_n = '0' then
data_wr_strobe <= std_logic'('0');
elsif clk'event and clk = '1' then
if (std_logic_vector'("00000000000000000000000000000001")) /= std_logic_vector'("00000000000000000000000000000000") then
data_wr_strobe <= p1_data_wr_strobe;
end if;
end if;
end process;
control_wr_strobe <= wr_strobe AND to_std_logic((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000011"))));
status_wr_strobe <= wr_strobe AND to_std_logic((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000010"))));
slaveselect_wr_strobe <= wr_strobe AND to_std_logic((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000101"))));
endofpacketvalue_wr_strobe <= wr_strobe AND to_std_logic((((std_logic_vector'("00000000000000000000000000000") & (mem_addr)) = std_logic_vector'("00000000000000000000000000000110"))));
TMT <= NOT transmitting AND NOT tx_holding_primed;
E <= ROE OR TOE;
spi_status <= std_logic_vector'("0") & (Std_Logic_Vector'(A_ToStdLogicVector(EOP) & A_ToStdLogicVector(E) & A_ToStdLogicVector(RRDY) & A_ToStdLogicVector(TRDY) & A_ToStdLogicVector(TMT) & A_ToStdLogicVector(TOE) & A_ToStdLogicVector(ROE) & std_logic_vector'("000")));
-- Streaming data ready for pickup.
dataavailable <= RRDY;
-- Ready to accept streaming data.
readyfordata <= TRDY;
-- Endofpacket condition detected.
endofpacket <= EOP;
process (clk, reset_n)
begin
if reset_n = '0' then
iEOP_reg <= std_logic'('0');
iE_reg <= std_logic'('0');
iRRDY_reg <= std_logic'('0');
iTRDY_reg <= std_logic'('0');
iTMT_reg <= std_logic'('0');
iTOE_reg <= std_logic'('0');
iROE_reg <= std_logic'('0');
SSO_reg <= std_logic'('0');
elsif clk'event and clk = '1' then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -