generated from open-education-hub/oer-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [labcpu] Add the fpga implementation (#42)
* wip: blockram for cpu * wip: cpu debugger * wip: labcpu vivado and opensource * wip: second clock for ram and init data * fix: otp button * fix: reg PC display * fix: incPC and cheatsheet
- Loading branch information
Showing
31 changed files
with
6,779 additions
and
986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module clock_divider #( | ||
parameter p_divisor = 2 // Clock division factor | ||
) ( | ||
output reg o_w_clk, // Output divided clock | ||
input wire i_w_clk, // Input clock | ||
input wire i_w_reset // Reset signal | ||
); | ||
|
||
// Compute the size of the counter for the division | ||
localparam l_p_counter_width = $clog2(p_divisor) + 1; | ||
reg [l_p_counter_width:0] counter; | ||
|
||
always @(posedge i_w_clk or negedge i_w_reset) begin | ||
if (!i_w_reset) begin | ||
counter <= 0; | ||
o_w_clk <= 0; | ||
end else begin | ||
if (counter == (p_divisor - 1)) begin | ||
counter <= 0; | ||
o_w_clk <= ~o_w_clk; | ||
end else begin | ||
counter <= counter + 1; | ||
end | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module debouncer #( | ||
parameter p_no_cycles = 1000000 // Clock cycles for debouncing | ||
) ( | ||
output reg o_w_out, // Debounced output | ||
input wire i_w_in, // Input signal | ||
input wire i_w_clk, // Clock signal | ||
input wire i_w_reset // Reset signal | ||
); | ||
|
||
// Compute the size of the counter for the debouncing | ||
localparam l_p_counter_width = $clog2(p_no_cycles); | ||
reg[(l_p_counter_width - 1):0] l_r_counter; | ||
|
||
always @(posedge i_w_clk or negedge i_w_reset) begin | ||
if(!i_w_reset) begin | ||
l_r_counter <= 0; | ||
o_w_out <= 0; | ||
end else begin | ||
if(i_w_in == o_w_out) begin | ||
l_r_counter <= 0; | ||
end else begin | ||
if(l_r_counter == (p_no_cycles - 1)) begin | ||
o_w_out <= i_w_in; | ||
l_r_counter <= 0; | ||
end else begin | ||
l_r_counter <= l_r_counter + 1; | ||
end | ||
end | ||
end | ||
end | ||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module otp_button ( | ||
output wire o_w_button_press, | ||
input wire i_w_clk, | ||
input wire i_w_button | ||
); | ||
|
||
localparam l_p_state_ButtonReleased = 2'd0; | ||
localparam l_p_state_ButtonFirstPressed = 2'd1; | ||
localparam l_p_state_ButtonPressed = 2'd2; | ||
|
||
reg [1:0] l_r_state; | ||
reg [1:0] l_r_next_state; | ||
|
||
always @(posedge i_w_clk) begin | ||
l_r_state <= l_r_next_state; | ||
end | ||
|
||
always @(*) begin | ||
l_r_next_state = l_p_state_ButtonReleased; | ||
case(l_r_state) | ||
l_p_state_ButtonReleased: begin | ||
if (i_w_button) | ||
l_r_next_state = l_p_state_ButtonFirstPressed; | ||
else | ||
l_r_next_state = l_p_state_ButtonReleased; | ||
end | ||
l_p_state_ButtonFirstPressed: begin | ||
l_r_next_state = l_p_state_ButtonPressed; | ||
end | ||
l_p_state_ButtonPressed: begin | ||
if (i_w_button) | ||
l_r_next_state = l_p_state_ButtonPressed; | ||
else | ||
l_r_next_state = l_p_state_ButtonReleased; | ||
end | ||
default: l_r_next_state = l_p_state_ButtonReleased; | ||
endcase | ||
end | ||
|
||
assign o_w_button_press = (l_r_state == l_p_state_ButtonFirstPressed); | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
all: build | ||
|
||
build: build_project/build.xpr | ||
COMPILER=iverilog | ||
INTERPRETER=vvp | ||
SIMULATOR=gtkwave | ||
FLAGS=-Wall -Winfloop | ||
|
||
# TODO: use the command line to pass the following parameters | ||
TOP_MODULE=cpu_debugger | ||
OTHER_SOURCES=alu.v bus.v cpu.v control_unit.v cram.v state_display.v | ||
RAM_DATA_FILE=cram.data | ||
MEMORY_SOURCES=../memory/block_ram.v ../memory/block_dpram.v ../memory/register.v ../memory/regfile.v | ||
CORE_SOURCES=../core/clock_divider.v ../core/debouncer.v ../core/led7hex.v ../core/otp_button.v | ||
|
||
build_project/build.xpr: | ||
vivado -mode batch -source tcl_files/build.tcl | ||
# compute the filenames | ||
TOP_MODULE_FILE=$(TOP_MODULE).v | ||
TOP_SIM_MODULE_FILE=test_${TOP_MODULE}.v | ||
TOP_MODULE_BIN=$(TOP_MODULE).vvp | ||
|
||
run: build_project/build.xpr | ||
vivado -mode batch -source tcl_files/run.tcl | ||
all: build | ||
|
||
simulation: build_project/build.xpr | ||
vivado -mode batch -source tcl_files/simulation.tcl | ||
build: | ||
$(COMPILER) $(FLAGS) $(TOP_MODULE_FILE) $(TOP_SIM_MODULE_FILE) $(OTHER_SOURCES) $(MEMORY_SOURCES) $(CORE_SOURCES) -o $(TOP_MODULE_BIN) | ||
@echo "Build completed" | ||
|
||
vivado: build_project/build.xpr | ||
vivado build_project/build.xpr | ||
run: build | ||
$(INTERPRETER) $(TOP_MODULE_BIN) | ||
|
||
clean: | ||
rm $(TOP_MODULE_BIN) | ||
|
||
vivado: | ||
vivado -mode batch -source tcl_files/vivado.tcl | ||
|
||
clean_vivado: | ||
rm -rf vivado* | ||
rm -rf build_project | ||
rm -rf .Xil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.