1 ------------------------------------------------------------------------------
3 ---- ZPU Medium + PHI I/O + BRAM ----
5 ---- http://www.opencores.org/ ----
8 ---- ZPU is a 32 bits small stack cpu. This is a helper that joins the ----
9 ---- medium version, the PHI I/O basic layout and a program BRAM. ----
15 ---- - Salvador E. Tropea, salvador inti.gob.ar ----
17 ------------------------------------------------------------------------------
19 ---- Copyright (c) 2008 Salvador E. Tropea <salvador inti.gob.ar> ----
20 ---- Copyright (c) 2008 Instituto Nacional de TecnologĂa Industrial ----
22 ---- Distributed under the BSD license ----
24 ------------------------------------------------------------------------------
26 ---- Design unit: ZPU_Med1(Structural) (Entity and architecture) ----
27 ---- File name: zpu_med1.vhdl ----
29 ---- Limitations: None known ----
30 ---- Errors: None known ----
31 ---- Library: work ----
32 ---- Dependencies: IEEE.std_logic_1164 ----
33 ---- IEEE.numeric_std ----
35 ---- work.zpu_memory ----
36 ---- Target FPGA: Spartan 3 (XC3S1500-4-FG456) ----
37 ---- Language: VHDL ----
38 ---- Wishbone: No ----
39 ---- Synthesis tools: Xilinx Release 9.2.03i - xst J.39 ----
40 ---- Simulation tools: GHDL [Sokcho edition] (0.2x) ----
41 ---- Text editor: SETEdit 0.5.x ----
43 ------------------------------------------------------------------------------
46 use IEEE.std_logic_1164.all;
47 use IEEE.numeric_std.all;
54 use work.zpu_memory.all;
58 WORD_SIZE : natural:=32; -- 32 bits data path
59 D_CARE_VAL : std_logic:='X'; -- Fill value
60 CLK_FREQ : positive:=50; -- 50 MHz clock
61 BRATE : positive:=9600; -- RS232 baudrate
62 ADDR_W : natural:=18; -- 18 bits address space=256 kB, 128 kB I/O
63 BRAM_W : natural:=15); -- 15 bits RAM space=32 kB
65 clk_i : in std_logic; -- CPU clock
66 rst_i : in std_logic; -- Reset
67 break_o : out std_logic; -- Break executed
68 dbg_o : out zpu_dbgo_t; -- Debug info
69 rs232_tx_o : out std_logic; -- UART Tx
70 rs232_rx_i : in std_logic; -- UART Rx
71 gpio_in : in std_logic_vector(31 downto 0);
72 gpio_out : out std_logic_vector(31 downto 0);
73 gpio_dir : out std_logic_vector(31 downto 0) -- 1 = in, 0 = out
77 architecture Structural of ZPU_Med1 is
78 constant BYTE_BITS : integer:=WORD_SIZE/16; -- # of bits in a word that addresses bytes
79 constant IO_BIT : integer:=ADDR_W-1; -- Address bit to determine this is an I/O
80 constant BRDIVISOR : positive:=CLK_FREQ*1e6/BRATE/4;
83 signal mem_busy : std_logic;
84 signal mem_read : unsigned(WORD_SIZE-1 downto 0);
85 signal mem_write : unsigned(WORD_SIZE-1 downto 0);
86 signal mem_addr : unsigned(ADDR_W-1 downto 0);
87 signal mem_we : std_logic;
88 signal mem_re : std_logic;
90 -- Memory (SinglePort_RAM)
91 signal ram_busy : std_logic;
92 signal ram_read : unsigned(WORD_SIZE-1 downto 0);
93 signal ram_addr : unsigned(BRAM_W-1 downto BYTE_BITS);
94 signal ram_we : std_logic;
95 signal ram_re : std_logic;
96 signal ram_ready_r : std_logic:='0';
99 signal io_busy : std_logic;
100 signal io_re : std_logic;
101 signal io_we : std_logic;
102 signal io_read : unsigned(WORD_SIZE-1 downto 0);
103 signal io_ready : std_logic;
104 signal io_reading_r : std_logic:='0';
105 signal io_addr : unsigned(2 downto 0);
107 memory: SinglePortRAM
109 WORD_SIZE => WORD_SIZE, BYTE_BITS => BYTE_BITS, BRAM_W => BRAM_W)
112 we_i => ram_we, re_i => ram_re, addr_i => ram_addr,
113 write_i => mem_write, read_o => ram_read, busy_o => ram_busy);
114 ram_addr <= mem_addr(BRAM_W-1 downto BYTE_BITS);
115 ram_we <= mem_we and not(mem_addr(IO_BIT));
116 ram_re <= mem_re and not(mem_addr(IO_BIT));
121 BRDIVISOR => BRDIVISOR,
122 LOG_FILE => "zpu_med1_io.log"
133 rs232_rx_i => rs232_rx_i,
134 rs232_tx_o => rs232_tx_o,
137 gpio_out => gpio_out,
140 io_addr <= mem_addr(4 downto 2);
141 -- Here we decode 0x8xxxx as I/O and not just 0x80A00xx
142 -- Note: We define the address space as 256 kB, so writing to 0x80A00xx
143 -- will be as wrting to 0x200xx and hence we decode it as I/O space.
144 io_we <= mem_we and mem_addr(IO_BIT);
145 io_re <= mem_re and mem_addr(IO_BIT);
146 io_ready <= (io_reading_r or io_re) and not io_busy;
150 WORD_SIZE => WORD_SIZE, ADDR_W => ADDR_W, MEM_W => BRAM_W,
151 D_CARE_VAL => D_CARE_VAL)
153 clk_i => clk_i, reset_i => rst_i, enable_i => '1',
154 break_o => break_o, dbg_o => dbg_o,
156 mem_busy_i => mem_busy, data_i => mem_read, data_o => mem_write,
157 addr_o => mem_addr, write_en_o => mem_we, read_en_o => mem_re);
158 mem_busy <= io_busy or ram_busy;
160 -- Memory reads either come from IO or DRAM. We need to pick the right one.
162 process (ram_read, ram_ready_r, io_ready, io_read)
164 mem_read <= (others => '0');
165 if ram_ready_r='1' then
166 mem_read <= ram_read;
171 end process memory_control;
176 if rising_edge(clk_i) then
181 io_reading_r <= io_busy or io_re;
182 ram_ready_r <= ram_re;
185 end process memory_control_sync;
186 end architecture Structural; -- Entity: ZPU_Med1