📄 parallel_flash_memory_uart_programmer.vhd
字号:
----------------------------------------------------------------------------------------------------------------------------------
-- KCPSM3 and the program memory
----------------------------------------------------------------------------------------------------------------------------------
--
processor: kcpsm3
port map( address => address,
instruction => instruction,
port_id => port_id,
write_strobe => write_strobe,
out_port => out_port,
read_strobe => read_strobe,
in_port => in_port,
interrupt => interrupt,
interrupt_ack => interrupt_ack,
reset => kcpsm3_reset,
clk => clk);
program_rom: progctrl
port map( address => address,
instruction => instruction,
proc_reset => kcpsm3_reset,
clk => clk);
--
----------------------------------------------------------------------------------------------------------------------------------
-- Interrupt
----------------------------------------------------------------------------------------------------------------------------------
--
--
-- Interrupt is used to detect when the UART receiver FIFO reaches half full and this is
-- then used to send XON and XOFF flow control characters back to the PC.
--
-- If 'rx_half_full' goes High, an interrupt is generated and the subsequent ISR will transmit
-- an XOFF character to stop the flow of new characters from the PC and allow the FIFO to start to empty.
--
-- If 'rx_half_full' goes Low, an interrupt is generated and the subsequent ISR will transmit
-- an XON character which will allow the PC to send new characters and allow the FIFO to start to fill.
--
interrupt_control: process(clk)
begin
if clk'event and clk='1' then
-- detect change in state of the 'rx_half_full' flag.
previous_rx_half_full <= rx_half_full;
rx_half_full_event <= previous_rx_half_full xor rx_half_full;
-- processor interrupt waits for an acknowledgement
if interrupt_ack='1' then
interrupt <= '0';
elsif rx_half_full_event='1' then
interrupt <= '1';
else
interrupt <= interrupt;
end if;
end if;
end process interrupt_control;
--
----------------------------------------------------------------------------------------------------------------------------------
-- KCPSM3 input ports
----------------------------------------------------------------------------------------------------------------------------------
--
--
-- UART FIFO status signals to form a bus
-- Also the status signal (STS) from the StrataFlash memory
status_port <= strataflash_sts & '0' & rx_full & rx_half_full & rx_data_present & tx_full & tx_half_full & tx_data_present;
--
-- The inputs connect via a pipelined multiplexer
--
input_ports: process(clk)
begin
if clk'event and clk='1' then
case port_id(1 downto 0) is
-- read status signals at address 00 hex
when "00" => in_port <= status_port;
-- read UART receive data at address 01 hex
when "01" => in_port <= rx_data;
-- read StrataFLASH memory data at address 02 hex
when "10" => in_port <= strataflash_d;
-- Don't care used for all other addresses to ensure minimum logic implementation
when others => in_port <= "XXXXXXXX";
end case;
-- Form read strobe for UART receiver FIFO buffer at address 01 hex.
-- The fact that the read strobe will occur after the actual data is read by
-- the KCPSM3 is acceptable because it is really means 'I have read you'!
if (read_strobe='1' and port_id(1 downto 0)="01") then
read_from_uart <= '1';
else
read_from_uart <= '0';
end if;
end if;
end process input_ports;
--
----------------------------------------------------------------------------------------------------------------------------------
-- KCPSM3 output ports
----------------------------------------------------------------------------------------------------------------------------------
--
-- adding the output registers to the processor
output_ports: process(clk)
begin
if clk'event and clk='1' then
if write_strobe='1' then
-- The 24-bit address to the StrataFLASH memory requires 3 ports.
-- Address [23:16] at port 80 hex
if port_id(7)='1' then
strataflash_a(23 downto 16) <= out_port;
end if;
-- Address [15:8] at port 40 hex
if port_id(6)='1' then
strataflash_a(15 downto 8) <= out_port;
end if;
-- Address [7:0] at port 20 hex
if port_id(5)='1' then
strataflash_a(7 downto 0) <= out_port;
end if;
-- Data to be written to StrataFlash at port 10 hex
if port_id(4)='1' then
write_data <= out_port;
end if;
-- StrataFlash control signals at port 08 hex
if port_id(3)='1' then
strataflash_read <= out_port(0); --Active High and used to control data bus direction and OE
strataflash_ce <= out_port(1); --Active Low StrataFLASH device enable
strataflash_we <= out_port(2); --Active Low StrataFLASH write enable
end if;
end if;
end if;
end process output_ports;
--
-- write to UART transmitter FIFO buffer at address 04 hex.
-- This is a combinatorial decode because the FIFO is the 'port register'.
--
write_to_uart <= '1' when (write_strobe='1' and port_id(2)='1') else '0';
--
----------------------------------------------------------------------------------------------------------------------------------
-- UART
----------------------------------------------------------------------------------------------------------------------------------
--
-- Connect the 8-bit, 1 stop-bit, no parity transmit and receive macros.
-- Each contains an embedded 16-byte FIFO buffer.
--
transmit: uart_tx_plus
port map ( data_in => out_port,
write_buffer => write_to_uart,
reset_buffer => '0',
en_16_x_baud => en_16_x_baud,
serial_out => tx_female,
buffer_data_present => tx_data_present,
buffer_full => tx_full,
buffer_half_full => tx_half_full,
clk => clk );
receive: uart_rx
port map ( serial_in => rx_female,
data_out => rx_data,
read_buffer => read_from_uart,
reset_buffer => '0',
en_16_x_baud => en_16_x_baud,
buffer_data_present => rx_data_present,
buffer_full => rx_full,
buffer_half_full => rx_half_full,
clk => clk );
--
-- Set baud rate to 115200 for the UART communications
-- Requires en_16_x_baud to be 1843200Hz which is a single cycle pulse every 27 cycles at 50MHz
--
baud_timer: process(clk)
begin
if clk'event and clk='1' then
if baud_count=26 then
baud_count <= 0;
en_16_x_baud <= '1';
else
baud_count <= baud_count + 1;
en_16_x_baud <= '0';
end if;
end if;
end process baud_timer;
--
----------------------------------------------------------------------------------------------------------------------------------
end Behavioral;
------------------------------------------------------------------------------------------------------------------------------------
--
-- END OF FILE parallel_flash_memory_uart_programmer.vhd
--
------------------------------------------------------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -