Files
super6502/hw/efinix_fpga/divider_wrapper.sv
Byron Lathi 5f6657a227 Add divider
Adds a 16x16 divider to go with the multiplier.

The divider is a single stage with no pipelining, which works at the
slow 2MHz frequency. Doing this lowers the maximum clock frequency to 5.

This is acceptable for now but means that the cpu can't be run at 14,
which is the maximum frequency.
2023-01-05 18:35:42 -05:00

82 lines
1.2 KiB
Systemverilog

module divider_wrapper(
input clk,
input reset,
input [7:0] i_data,
output logic [7:0] o_data,
input cs,
input rwb,
input [2:0] addr
);
logic [15:0] numer, denom;
logic [15:0] quotient, remain;
logic clken, rfd;
assign clken = '1;
divider u_divider(
.numer ( numer ),
.denom ( denom ),
.clken ( clken ),
.clk ( clk ),
.reset ( reset ),
.quotient ( quotient ),
.remain ( remain ),
.rfd ( rfd )
);
always_ff @(negedge clk) begin
if (reset) begin
numer <= '0;
denom <= '0;
end
if (cs & ~rwb) begin
case (addr)
3'h0: begin
numer[7:0] <= i_data;
end
3'h1: begin
numer[15:8] <= i_data;
end
3'h2: begin
denom[7:0] <= i_data;
end
3'h3: begin
denom[15:8] <= i_data;
end
endcase
end
end
always_comb begin
case (addr)
3'h4: begin
o_data = quotient[7:0];
end
3'h5: begin
o_data = quotient[15:8];
end
3'h6: begin
o_data = remain[7:0];
end
3'h7: begin
o_data = remain[15:8];
end
endcase
end
endmodule