Merge from master
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
module addr_decode
|
||||
(
|
||||
input [24:0] i_addr,
|
||||
|
||||
input config_reg_sel,
|
||||
|
||||
output o_rom_cs,
|
||||
output o_leds_cs,
|
||||
output o_timer_cs,
|
||||
output o_multiplier_cs,
|
||||
output o_divider_cs,
|
||||
output o_uart_cs,
|
||||
output o_spi_cs,
|
||||
output o_sdram_cs
|
||||
);
|
||||
|
||||
assign o_rom_cs = (i_addr >= 25'hf000 && i_addr <= 25'hffff) && ~config_reg_sel;
|
||||
assign o_timer_cs = (i_addr >= 25'heff8 && i_addr <= 25'heffb) && ~config_reg_sel;
|
||||
assign o_multiplier_cs = (i_addr >= 25'heff0 && i_addr <= 25'heff7) && ~config_reg_sel;
|
||||
assign o_divider_cs = (i_addr >= 25'hefe8 && i_addr <= 25'hefef) && ~config_reg_sel;
|
||||
assign o_uart_cs = (i_addr >= 25'hefe6 && i_addr <= 25'hefe7) && ~config_reg_sel;
|
||||
assign o_spi_cs = (i_addr >= 25'hefd8 && i_addr <= 25'hefdb) && ~config_reg_sel;
|
||||
assign o_leds_cs = (i_addr == 25'hefff) && ~config_reg_sel;
|
||||
assign o_sdram_cs = (i_addr < 25'he000 || i_addr >= 25'h10000) && ~config_reg_sel;
|
||||
|
||||
endmodule
|
||||
@@ -70,10 +70,11 @@ assign o_sdr_DQM = w_sdr_DQM[0+:2];
|
||||
// But basically if we are in access, and cpuclk goes low, go back to wait.
|
||||
// If something actually happened, we would be in one of the read/write states.
|
||||
|
||||
enum bit [1:0] {ACCESS, READ_WAIT, WRITE_WAIT, WAIT} state, next_state;
|
||||
enum bit [2:0] {ACCESS, PRE_READ, READ_WAIT, PRE_WRITE, WRITE_WAIT, WAIT} state, next_state;
|
||||
|
||||
logic w_read, w_write, w_last;
|
||||
logic [23:0] w_addr, r_addr;
|
||||
logic [23:0] w_read_addr, w_write_addr;
|
||||
logic [23:0] r_read_addr, r_write_addr;
|
||||
logic [31:0] w_data_i, w_data_o;
|
||||
logic [3:0] w_dm, r_dm;
|
||||
|
||||
@@ -86,25 +87,15 @@ logic [31:0] r_write_data;
|
||||
|
||||
logic [1:0] counter, next_counter;
|
||||
|
||||
always @(posedge i_sysclk) begin
|
||||
if (i_arst) begin
|
||||
state <= WAIT;
|
||||
counter <= '0;
|
||||
end else begin
|
||||
state <= next_state;
|
||||
counter <= next_counter;
|
||||
r_write_data <= w_data_i;
|
||||
r_addr <= w_addr;
|
||||
r_dm <= w_dm;
|
||||
end
|
||||
|
||||
if (w_data_valid)
|
||||
o_data <= _data;
|
||||
end
|
||||
logic [7:0] o_data_next;
|
||||
|
||||
logic [23:0] addr_mux_out;
|
||||
|
||||
logic slow_mem;
|
||||
|
||||
logic r_wait;
|
||||
logic _r_wait;
|
||||
assign o_wait = r_wait;
|
||||
assign o_wait = (r_wait | slow_mem) & i_cs;
|
||||
|
||||
// we need to assert rdy low until a falling edge if a reset happens
|
||||
|
||||
@@ -126,6 +117,20 @@ always @(posedge i_sysclk or posedge i_arst) begin
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (i_arst) begin
|
||||
state <= WAIT;
|
||||
counter <= '0;
|
||||
end else begin
|
||||
state <= next_state;
|
||||
counter <= next_counter;
|
||||
r_write_data <= w_data_i;
|
||||
r_read_addr <= w_read_addr;
|
||||
r_write_addr <= w_write_addr;
|
||||
r_dm <= w_dm;
|
||||
end
|
||||
|
||||
o_data <= o_data_next;
|
||||
end
|
||||
|
||||
//because of timing issues, We really need to trigger
|
||||
@@ -157,10 +162,12 @@ end
|
||||
|
||||
|
||||
always_comb begin
|
||||
slow_mem = '0;
|
||||
next_state = state;
|
||||
next_counter = counter;
|
||||
|
||||
w_addr = '0;
|
||||
w_read_addr = '0;
|
||||
w_write_addr = '0;
|
||||
w_dm = '0;
|
||||
w_read = '0;
|
||||
w_write = '0;
|
||||
@@ -171,65 +178,81 @@ always_comb begin
|
||||
|
||||
unique case (state)
|
||||
WAIT: begin
|
||||
if (i_cs & i_cpuclk)
|
||||
if (i_cs & ~i_cpuclk)
|
||||
next_state = ACCESS;
|
||||
end
|
||||
|
||||
ACCESS: begin
|
||||
// only do something if selected
|
||||
if (i_cs) begin
|
||||
w_addr = {{i_addr[24:2]}, {1'b0}};; // divide by 2, set last bit to 0
|
||||
|
||||
w_read_addr = {{i_addr[24:2]}, {1'b0}}; // divide by 2, set last bit to 0
|
||||
w_write_addr = {{i_addr[24:2]}, {1'b0}}; // divide by 2, set last bit to 0
|
||||
addr_mux_out = w_read_addr;
|
||||
if (i_rwb) begin //read
|
||||
w_read = '1;
|
||||
w_last = '1;
|
||||
// dm is not needed for reads?
|
||||
if (w_rd_ack) next_state = READ_WAIT;
|
||||
next_state = PRE_READ;
|
||||
end else begin //write
|
||||
w_data_i = i_data << (8*i_addr[1:0]);
|
||||
//w_data_i = {4{i_data}}; //does anything get through?
|
||||
w_dm = ~(4'b1 << i_addr[1:0]);
|
||||
if (~i_cpuclk) begin
|
||||
w_write = '1;
|
||||
w_last = '1;
|
||||
next_state = WRITE_WAIT;
|
||||
end
|
||||
next_state = PRE_WRITE;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
PRE_WRITE: begin
|
||||
w_data_i = r_write_data;
|
||||
w_write_addr = r_write_addr;
|
||||
addr_mux_out = w_write_addr;
|
||||
w_dm = r_dm;
|
||||
//w_data_i = {4{i_data}}; //does anything get through?
|
||||
if (~i_cpuclk) begin
|
||||
w_write = '1;
|
||||
w_last = '1;
|
||||
next_state = WRITE_WAIT;
|
||||
end
|
||||
end
|
||||
|
||||
WRITE_WAIT: begin
|
||||
// stay in this state until write is acknowledged.
|
||||
w_write_addr = r_write_addr;
|
||||
addr_mux_out = w_write_addr;
|
||||
w_write = '1;
|
||||
w_last = '1;
|
||||
w_data_i = r_write_data;
|
||||
w_dm = r_dm;
|
||||
w_addr = r_addr;
|
||||
if (w_wr_ack) next_state = WAIT;
|
||||
end
|
||||
|
||||
PRE_READ: begin
|
||||
w_read_addr = r_read_addr;
|
||||
addr_mux_out = w_read_addr;
|
||||
w_read = '1;
|
||||
w_last = '1;
|
||||
slow_mem = '1;
|
||||
// dm is not needed for reads?
|
||||
if (w_rd_ack) next_state = READ_WAIT;
|
||||
end
|
||||
|
||||
READ_WAIT: begin
|
||||
w_read_addr = r_read_addr;
|
||||
addr_mux_out = w_read_addr;
|
||||
slow_mem = '1;
|
||||
if (w_rd_valid) begin
|
||||
w_data_valid = '1;
|
||||
_data = w_data_o[8*i_addr[1:0]+:8];
|
||||
end
|
||||
|
||||
// you must wait until the next cycle!
|
||||
if (~i_cpuclk) begin
|
||||
if (w_data_valid) begin
|
||||
next_state = WAIT;
|
||||
end
|
||||
end
|
||||
|
||||
endcase
|
||||
end
|
||||
|
||||
//this seems scuffed
|
||||
logic [23:0] addr_mux_out;
|
||||
always_comb begin
|
||||
if (state == ACCESS) begin
|
||||
addr_mux_out = w_addr;
|
||||
if (w_data_valid) begin
|
||||
o_data_next = _data;
|
||||
end else begin
|
||||
addr_mux_out = r_addr;
|
||||
o_data_next = o_data;
|
||||
end
|
||||
end
|
||||
|
||||
@@ -245,10 +268,11 @@ logic [3:0] o_dbg_BA;
|
||||
logic [25:0] o_dbg_ADDR;
|
||||
logic [31:0] o_dbg_DATA_out;
|
||||
logic [31:0] o_dbg_DATA_in;
|
||||
logic o_sdr_init_done;
|
||||
logic sdr_init_done;
|
||||
logic [3:0] o_sdr_state;
|
||||
|
||||
assign o_ref_req = o_dbg_ref_req;
|
||||
assign o_sdr_init_done = sdr_init_done;
|
||||
|
||||
|
||||
sdram_controller u_sdram_controller(
|
||||
@@ -265,7 +289,7 @@ sdram_controller u_sdram_controller(
|
||||
.i_din(r_write_data), //Data to write to SDRAM. Twice normal width when running at half speed (hence the even addresses)
|
||||
.i_dm(r_dm), //dm (r_dm)
|
||||
.o_dout(w_data_o), //Data read from SDRAM, doubled as above.
|
||||
.o_sdr_init_done(o_sdr_init_done), //Indicates that the SDRAM initialization is done.
|
||||
.o_sdr_init_done(sdr_init_done), //Indicates that the SDRAM initialization is done.
|
||||
.o_wr_ack(w_wr_ack), //Write acknowledge, handshake with we
|
||||
.o_rd_ack(w_rd_ack), //Read acknowledge, handshake with re
|
||||
.o_rd_valid(w_rd_valid),//Read valid. The data on o_dout is valid
|
||||
|
||||
@@ -90,6 +90,7 @@ always_comb begin
|
||||
1: o_data = r_input_data;
|
||||
2:;
|
||||
3: o_data = {active, r_control[6:0]};
|
||||
default: o_data = 'x;
|
||||
endcase
|
||||
end
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ module super6502
|
||||
input button_reset,
|
||||
input pll_cpu_locked,
|
||||
input clk_50,
|
||||
input clk_2,
|
||||
input clk_cpu,
|
||||
input logic [15:0] cpu_addr,
|
||||
output logic [7:0] cpu_data_out,
|
||||
output logic [7:0] cpu_data_oe,
|
||||
@@ -60,11 +60,11 @@ assign cpu_nmib = '1;
|
||||
logic w_wait;
|
||||
assign cpu_rdy = ~w_wait;
|
||||
|
||||
assign cpu_phi2 = clk_2;
|
||||
assign cpu_phi2 = clk_cpu;
|
||||
|
||||
logic w_sdr_init_done;
|
||||
|
||||
always @(posedge clk_2) begin
|
||||
always @(posedge clk_cpu) begin
|
||||
if (button_reset == '0) begin
|
||||
cpu_resb <= '0;
|
||||
end
|
||||
@@ -94,18 +94,6 @@ logic w_uart_cs;
|
||||
logic w_mapper_cs;
|
||||
logic w_spi_cs;
|
||||
|
||||
addr_decode u_addr_decode(
|
||||
.i_addr(w_sdram_addr),
|
||||
.config_reg_sel(w_control_reg_cs),
|
||||
.o_rom_cs(w_rom_cs),
|
||||
.o_leds_cs(w_leds_cs),
|
||||
.o_timer_cs(w_timer_cs),
|
||||
.o_multiplier_cs(w_multiplier_cs),
|
||||
.o_divider_cs(w_divider_cs),
|
||||
.o_uart_cs(w_uart_cs),
|
||||
.o_spi_cs(w_spi_cs),
|
||||
.o_sdram_cs(w_sdram_cs)
|
||||
);
|
||||
|
||||
logic [7:0] w_rom_data_out;
|
||||
logic [7:0] w_leds_data_out;
|
||||
@@ -118,6 +106,16 @@ logic [7:0] w_mapper_data_out;
|
||||
logic [7:0] w_sdram_data_out;
|
||||
|
||||
always_comb begin
|
||||
w_rom_cs = cpu_addr >= 16'hf000 && cpu_addr <= 16'hffff;
|
||||
w_timer_cs = cpu_addr >= 16'heff8 && cpu_addr <= 16'heffb;
|
||||
w_multiplier_cs = cpu_addr >= 16'heff0 && cpu_addr <= 16'heff7;
|
||||
w_divider_cs = cpu_addr >= 16'hefe8 && cpu_addr <= 16'hefef;
|
||||
w_uart_cs = cpu_addr >= 16'hefe6 && cpu_addr <= 16'hefe7;
|
||||
w_spi_cs = cpu_addr >= 16'hefd8 && cpu_addr <= 16'hefdb;
|
||||
w_leds_cs = cpu_addr == 16'hefff;
|
||||
w_sdram_cs = cpu_addr < 16'he000;
|
||||
|
||||
|
||||
if (w_rom_cs)
|
||||
cpu_data_out = w_rom_data_out;
|
||||
else if (w_leds_cs)
|
||||
@@ -154,13 +152,13 @@ mapper u_mapper(
|
||||
);
|
||||
|
||||
rom #(.DATA_WIDTH(8), .ADDR_WIDTH(12)) u_rom(
|
||||
.addr(w_sdram_addr[11:0]),
|
||||
.clk(clk_2),
|
||||
.addr(cpu_addr[11:0]),
|
||||
.clk(clk_cpu),
|
||||
.data(w_rom_data_out)
|
||||
);
|
||||
|
||||
leds u_leds(
|
||||
.clk(clk_2),
|
||||
.clk(clk_cpu),
|
||||
.i_data(cpu_data_in),
|
||||
.o_data(w_leds_data_out),
|
||||
.cs(w_leds_cs),
|
||||
@@ -171,7 +169,7 @@ leds u_leds(
|
||||
logic w_timer_irqb;
|
||||
|
||||
timer u_timer(
|
||||
.clk(clk_2),
|
||||
.clk(clk_cpu),
|
||||
.reset(~cpu_resb),
|
||||
.i_data(cpu_data_in),
|
||||
.o_data(w_timer_data_out),
|
||||
@@ -182,7 +180,7 @@ timer u_timer(
|
||||
);
|
||||
|
||||
multiplier u_multiplier(
|
||||
.clk(clk_2),
|
||||
.clk(clk_cpu),
|
||||
.reset(~cpu_resb),
|
||||
.i_data(cpu_data_in),
|
||||
.o_data(w_multiplier_data_out),
|
||||
@@ -192,7 +190,7 @@ multiplier u_multiplier(
|
||||
);
|
||||
|
||||
divider_wrapper u_divider(
|
||||
.clk(clk_2),
|
||||
.clk(clk_cpu),
|
||||
.divclk(clk_50),
|
||||
.reset(~cpu_resb),
|
||||
.i_data(cpu_data_in),
|
||||
@@ -205,7 +203,7 @@ divider_wrapper u_divider(
|
||||
logic w_uart_irqb;
|
||||
|
||||
uart_wrapper u_uart(
|
||||
.clk(clk_2),
|
||||
.clk(clk_cpu),
|
||||
.clk_50(clk_50),
|
||||
.reset(~cpu_resb),
|
||||
.i_data(cpu_data_in),
|
||||
@@ -219,7 +217,7 @@ uart_wrapper u_uart(
|
||||
);
|
||||
|
||||
spi_controller spi_controller(
|
||||
.i_clk(clk_2),
|
||||
.i_clk(clk_cpu),
|
||||
.i_rst(~cpu_resb),
|
||||
.i_cs(w_spi_cs),
|
||||
.i_rwb(cpu_rwb),
|
||||
@@ -235,7 +233,7 @@ spi_controller spi_controller(
|
||||
|
||||
|
||||
sdram_adapter u_sdram_adapter(
|
||||
.i_cpuclk(clk_2),
|
||||
.i_cpuclk(clk_cpu),
|
||||
.i_arst(~button_reset),
|
||||
.i_sysclk(i_sysclk),
|
||||
.i_sdrclk(i_sdrclk),
|
||||
@@ -265,7 +263,7 @@ sdram_adapter u_sdram_adapter(
|
||||
);
|
||||
|
||||
interrupt_controller u_interrupt_controller(
|
||||
.clk(clk_2),
|
||||
.clk(clk_cpu),
|
||||
.reset(~cpu_resb),
|
||||
.i_data(cpu_data_in),
|
||||
.o_data(w_irq_data_out),
|
||||
|
||||
@@ -123,6 +123,8 @@ always_comb begin
|
||||
o_data = status;
|
||||
end
|
||||
|
||||
default: o_data = 'x;
|
||||
|
||||
endcase
|
||||
end
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ enum bit [1:0] {READY, WAIT, TRANSMIT} state, next_state;
|
||||
|
||||
always_ff @(posedge clk_50) begin
|
||||
if (reset) begin
|
||||
state = READY;
|
||||
state <= READY;
|
||||
irqb <= '1;
|
||||
end else begin
|
||||
state <= next_state;
|
||||
@@ -54,23 +54,27 @@ always_ff @(posedge clk_50) begin
|
||||
end
|
||||
|
||||
always_ff @(negedge clk) begin
|
||||
status[1] <= tx_busy | tx_en;
|
||||
if (reset) begin
|
||||
status <= '0;
|
||||
end else begin
|
||||
status[1] <= tx_busy | tx_en;
|
||||
|
||||
status[0] <= status[0] | rx_data_valid;
|
||||
if (cs & ~addr & rwb) begin
|
||||
status[0] <= 0;
|
||||
end
|
||||
status[0] <= status[0] | rx_data_valid;
|
||||
if (cs & ~addr & rwb) begin
|
||||
status[0] <= 0;
|
||||
end
|
||||
|
||||
if (cs & ~rwb) begin
|
||||
case (addr)
|
||||
1'b0: begin
|
||||
tx_data <= i_data;
|
||||
end
|
||||
if (cs & ~rwb) begin
|
||||
case (addr)
|
||||
1'b0: begin
|
||||
tx_data <= i_data;
|
||||
end
|
||||
|
||||
1'b1: begin
|
||||
control <= i_data;
|
||||
end
|
||||
endcase
|
||||
1'b1: begin
|
||||
control <= i_data;
|
||||
end
|
||||
endcase
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -79,7 +83,7 @@ always_comb begin
|
||||
case (addr)
|
||||
1'b0: begin
|
||||
o_data = rx_data;
|
||||
end
|
||||
end
|
||||
|
||||
1'b1: begin
|
||||
o_data = status;
|
||||
|
||||
Reference in New Issue
Block a user