Skip to content

Commit 45c7b98

Browse files
committed
Merge branch 'master' of https://github.com/sy2002/QNICE-FPGA
2 parents ab11781 + ef66139 commit 45c7b98

File tree

5 files changed

+79
-19
lines changed

5 files changed

+79
-19
lines changed

test_programs/uart.asm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ _IO$GETC_LOOP MOVE @R0, R3 ; read status register
2424

2525
MOVE @R1, R8 ; store received character ...
2626
MOVE R8, @R12 ; ... and write it to TIL
27-
--MOVE 0, @R0 ; clear read latch
28-
27+
2928
_IO$SETC_WAIT MOVE @R0, R3 ; read status register
3029
AND 0x0002, R3 ; ready to transmit?
3130
RBRA _IO$SETC_WAIT, Z ; loop until ready

vhdl/block_ram.vhd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ end BRAM;
3333
architecture beh of BRAM is
3434

3535
type bram_t is array (0 to BLOCK_RAM_SIZE - 1) of std_logic_vector(15 downto 0);
36-
signal bram : bram_t := (others => x"baba");
36+
signal bram : bram_t := (others => x"0000");
3737

3838
signal output : std_logic_vector(15 downto 0);
3939

vhdl/env1.vhd

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ port (
151151
);
152152
end component;
153153

154+
component SyTargetCounter is
155+
generic (
156+
COUNTER_FINISH : integer;
157+
COUNTER_WIDTH : integer range 2 to 32
158+
);
159+
port (
160+
clk : in std_logic;
161+
reset : in std_logic;
162+
163+
cnt : out std_logic_vector(COUNTER_WIDTH - 1 downto 0);
164+
overflow : out std_logic := '0'
165+
);
166+
end component;
167+
154168
signal cpu_addr : std_logic_vector(15 downto 0);
155169
signal cpu_data : std_logic_vector(15 downto 0);
156170
signal cpu_data_dir : std_logic;
@@ -168,6 +182,12 @@ signal til_reg1_enable : std_logic;
168182
-- 50 MHz as long as we did not solve the timing issues of the register file
169183
signal SLOW_CLOCK : std_logic := '0';
170184

185+
-- reset generator: either use the button or the initial reset counter
186+
--signal reset_sig : std_logic;
187+
--signal reset_done : std_logic := '0';
188+
--signal reset_cnt : std_logic_vector(5 downto 0);
189+
--signal reset_overflow : std_logic;
190+
171191
begin
172192

173193
-- QNICE CPU
@@ -268,7 +288,33 @@ begin
268288
if rising_edge(CLK) then
269289
SLOW_CLOCK <= not SLOW_CLOCK;
270290
end if;
271-
end process;
272-
291+
end process;
292+
293+
-- reset_delay : SyTargetCounter
294+
-- generic map
295+
-- (
296+
-- COUNTER_FINISH => 63,
297+
-- COUNTER_WIDTH => 6
298+
-- )
299+
-- port map
300+
-- (
301+
-- clk => SLOW_CLOCK and not reset_done,
302+
-- reset => RESET_N,
303+
-- cnt => reset_cnt,
304+
-- overflow => reset_overflow
305+
-- );
306+
--
307+
-- reset_done_handler : process (reset_overflow, RESET_N)
308+
-- begin
309+
-- if RESET_N = '0' then
310+
-- reset_done <= '0';
311+
-- else
312+
-- if rising_edge(reset_overflow) then
313+
-- reset_done <= '1';
314+
-- end if;
315+
-- end if;
316+
-- end process;
317+
--
318+
-- reset_sig <= reset_cnt(0) or reset_cnt(1) or reset_cnt(2) or reset_cnt(3) or reset_cnt(4) or reset_cnt(5);
273319
end beh;
274320

vhdl/env1_globals.vhd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ constant ROM_SIZE : integer := 2233;
1515

1616
-- size of lower register bank: should be 256
1717
-- set to 16 during development for faster synthesis, routing, etc.
18-
constant SHADOW_REGFILE_SIZE : integer := 16;
18+
constant SHADOW_REGFILE_SIZE : integer := 256;
1919

2020
-- size of the block RAM in 16bit words: should be 32768
2121
-- set to 256 during development for tracability during simulation
@@ -26,10 +26,11 @@ constant BLOCK_RAM_SIZE : integer := 32768;
2626
-- UART_DIVISOR = 100,000,000 / (16 x BAUD_RATE)
2727
-- 2400 -> 2604
2828
-- 9600 -> 651
29+
-- 19200 -> 326
2930
-- 115200 -> 54
3031
-- 1562500 -> 4
3132
-- 2083333 -> 3
32-
constant UART_DIVISOR : natural := 325; -- as long as we are using SLOW_CLOCK with 50 MHz
33+
constant UART_DIVISOR : natural := 326; -- as long as we are using SLOW_CLOCK with 50 MHz
3334
constant UART_FIFO_SIZE : natural := 16;
3435

3536
end env1_globals;

vhdl/fifo_uart.vhd

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ end component;
6767

6868
-- FIFO
6969
type FIFO_RAM is array(0 to FIFO_SIZE - 1) of std_logic_vector(8 downto 0);
70-
signal FIFO : FIFO_RAM;
70+
signal FIFO : FIFO_RAM := (others => "000000000");
7171
signal FIFO_WP : unsigned(integer(ceil(log2(real(FIFO_SIZE)))) - 1 downto 0) := (others => '0');
7272
signal FIFO_RP : unsigned(integer(ceil(log2(real(FIFO_SIZE)))) - 1 downto 0) := (others => '0');
7373

@@ -101,10 +101,14 @@ begin
101101
tx => tx
102102
);
103103

104-
uart_rx : process(uart_rx_enable, uart_rx_data, rx_resetvalid, FIFO_RP, FIFO_WP)
104+
uart_rx : process(uart_rx_enable, uart_rx_data, rx_resetvalid, FIFO_RP, FIFO_WP, reset)
105105
begin
106-
if rx_resetvalid = '1' then
107-
FIFO(to_integer(FIFO_RP))(8) <= '0';
106+
if rx_resetvalid = '1' or reset = '1' then
107+
if reset = '1' then
108+
FIFO(0)(8) <= '0';
109+
else
110+
FIFO(to_integer(FIFO_RP))(8) <= '0';
111+
end if;
108112
else
109113
if rising_edge(uart_rx_enable) then
110114
FIFO(to_integer(FIFO_WP))(7 downto 0) <= uart_rx_data;
@@ -113,23 +117,31 @@ begin
113117
end if;
114118
end process;
115119

116-
uart_inc_wp : process(uart_rx_enable, FIFO_WP)
120+
uart_inc_wp : process(uart_rx_enable, FIFO_WP, reset)
117121
begin
118-
if falling_edge(uart_rx_enable) then
119-
FIFO_WP <= FIFO_WP + 1;
122+
if reset = '1' then
123+
FIFO_WP <= (others => '0');
124+
else
125+
if falling_edge(uart_rx_enable) then
126+
FIFO_WP <= FIFO_WP + 1;
127+
end if;
120128
end if;
121129
end process;
122130

123-
uart_inc_rp : process(rx_resetvalid, FIFO_RP)
124-
begin
125-
if falling_edge(rx_resetvalid) then
126-
FIFO_RP <= FIFO_RP + 1;
131+
uart_inc_rp : process(rx_resetvalid, FIFO_RP, reset)
132+
begin
133+
if reset = '1' then
134+
FIFO_RP <= (others => '0');
135+
else
136+
if falling_edge(rx_resetvalid) then
137+
FIFO_RP <= FIFO_RP + 1;
138+
end if;
127139
end if;
128140
end process;
129141

130142
uart_cts_controller : process (FIFO_RP, FIFO_WP)
131143
begin
132-
if abs(signed(FIFO_RP) - signed(FIFO_WP)) > 4 then
144+
if abs(signed(FIFO_RP) - signed(FIFO_WP)) > (FIFO_SIZE / 4) then
133145
cts <= '1';
134146
cts_led <= '1';
135147
else
@@ -177,5 +189,7 @@ begin
177189
end if;
178190
end process;
179191

192+
193+
180194
end beh;
181195

0 commit comments

Comments
 (0)