-
Notifications
You must be signed in to change notification settings - Fork 67
Configurable UART #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
AgamemnonasKyriazis
wants to merge
7
commits into
lowRISC:main
Choose a base branch
from
AgamemnonasKyriazis:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cb47213
[rtl] removed original uart.sv file and added my uart implementation …
AgamemnonasKyriazis 66d920b
[core] edited the .core files to include my verilog file to compile p…
AgamemnonasKyriazis 7d9ad09
[sw] edited common header files to support configurable uart paramete…
AgamemnonasKyriazis b6ee853
[sw c]Deleted link.ld, it was a copy mistake and it shouldn't be ther…
AgamemnonasKyriazis 0850f84
almost full and almost empty condition flags
AgamemnonasKyriazis 7807f35
bugfix
AgamemnonasKyriazis 9eca9d0
Update main.c
AgamemnonasKyriazis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,97 @@ | ||
| `include "synchronizer.v" | ||
| `timescale 1ns/1ps | ||
|
|
||
| module async_fifo #( | ||
| parameter WIDTH = 32, // width of data bus | ||
| parameter DEPTH = 16 // depth of FIFO buffer | ||
| ) ( | ||
| input wire [WIDTH-1:0] wdata_i, | ||
| input wire wclk_i, | ||
| input wire rclk_i, | ||
| input wire rst_ni, | ||
| input wire we_i, | ||
| input wire re_i, | ||
| output wire [WIDTH-1:0] rdata_o, | ||
| output wire full_o, | ||
| output wire empty_o | ||
| ); | ||
|
|
||
| localparam ADDR_BITS = $clog2(DEPTH); // address width for buffer | ||
|
|
||
| reg [ADDR_BITS:0] w_ptr, r_ptr; | ||
| wire [ADDR_BITS:0] w_ptr_gray, r_ptr_gray; | ||
|
|
||
| wire [ADDR_BITS:0] w_ptr_next, r_ptr_next; | ||
| wire [ADDR_BITS:0] w_ptr_next_gray, r_ptr_next_gray; | ||
|
|
||
| wire [ADDR_BITS-1:0] w_addr, r_addr; | ||
|
|
||
| wire [ADDR_BITS:0] w_ptr_sync_gray, r_ptr_sync_gray; | ||
| reg [ADDR_BITS:0] w_ptr_sync_bin, r_ptr_sync_bin; | ||
|
|
||
| reg [WIDTH-1:0] mem [0:DEPTH-1]; | ||
|
|
||
| assign w_ptr_next = (we_i & ~full_o)? w_ptr + 1'b1 : w_ptr; | ||
| assign r_ptr_next = (re_i & ~empty_o)? r_ptr + 1'b1 : r_ptr; | ||
|
|
||
| assign w_addr = w_ptr[ADDR_BITS-1:0]; | ||
| assign r_addr = r_ptr[ADDR_BITS-1:0]; | ||
|
|
||
| assign w_ptr_gray = w_ptr ^ (w_ptr >> 1); | ||
| assign r_ptr_gray = r_ptr ^ (r_ptr >> 1); | ||
|
|
||
| assign w_ptr_next_gray = w_ptr_next ^ (w_ptr_next >> 1); | ||
| assign r_ptr_next_gray = r_ptr_next ^ (r_ptr_next >> 1); | ||
|
|
||
| ff2_sync #( | ||
| .WIDTH(ADDR_BITS+1) | ||
| ) sync_w2r_w_ptr ( | ||
| .clk_i(rclk_i), | ||
| .rst_ni(rst_ni), | ||
| .wdata_i(w_ptr_gray), | ||
| .rdata_o(w_ptr_sync_gray) | ||
| ); | ||
|
|
||
| ff2_sync #( | ||
| .WIDTH(ADDR_BITS+1) | ||
| ) sync_r2w_r_ptr ( | ||
| .clk_i(wclk_i), | ||
| .rst_ni(rst_ni), | ||
| .wdata_i(r_ptr_gray), | ||
| .rdata_o(r_ptr_sync_gray) | ||
| ); | ||
|
|
||
| integer i; | ||
| always @(*) begin : gray_to_bin_w_ptr | ||
| for(i=0; i<ADDR_BITS+1; i = i+1) | ||
| w_ptr_sync_bin[i] = ^(w_ptr_sync_gray >> i); | ||
| end | ||
|
|
||
| always @(*) begin : gray_to_bin_r_ptr | ||
| for(i=0; i<ADDR_BITS+1; i = i+1) | ||
| r_ptr_sync_bin[i] = ^(r_ptr_sync_gray >> i); | ||
| end | ||
|
|
||
| always @(posedge wclk_i, negedge rst_ni) | ||
| if(~rst_ni) | ||
| w_ptr <= 0; | ||
| else | ||
| w_ptr <= w_ptr_next; | ||
|
|
||
| always @(posedge wclk_i) begin : write | ||
| if(we_i & ~full_o) | ||
| mem[w_addr] <= wdata_i; | ||
| end | ||
|
|
||
| always @(posedge rclk_i, negedge rst_ni) begin : read | ||
| if(~rst_ni) | ||
| r_ptr <= 0; | ||
| else | ||
| r_ptr <= r_ptr_next; | ||
| end | ||
|
|
||
| assign full_o = w_ptr == {~r_ptr_sync_bin[ADDR_BITS], r_ptr_sync_bin[ADDR_BITS-1:0]}; | ||
| assign empty_o = r_ptr == w_ptr_sync_bin; | ||
| assign rdata_o = mem[r_addr]; | ||
|
|
||
| endmodule |
This file contains hidden or 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,56 @@ | ||
| `timescale 1ns/1ps | ||
|
|
||
| module sync_fifo #( | ||
| parameter WIDTH = 32, | ||
| parameter DEPTH = 128 | ||
| ) ( | ||
| input wire clk_i, | ||
| input wire rst_ni, | ||
| input wire [WIDTH-1:0] wdata_i, | ||
| input wire we_i, | ||
| input wire re_i, | ||
| output wire [WIDTH-1:0] rdata_o, | ||
| output wire full_o, | ||
| output wire empty_o | ||
| ); | ||
|
|
||
| localparam ADDR_BITS = $clog2(DEPTH); // address width for buffer | ||
|
|
||
| reg [ADDR_BITS:0] w_ptr, r_ptr; | ||
| wire [ADDR_BITS:0] w_ptr_next, r_ptr_next; | ||
|
|
||
| wire [ADDR_BITS-1:0] w_addr, r_addr; | ||
|
|
||
| wire full_next, empty_next; | ||
|
|
||
| reg [WIDTH-1:0] mem [0:DEPTH-1]; | ||
|
|
||
| assign w_ptr_next = (~full_o & we_i)? w_ptr + 1'b1 : w_ptr; | ||
| assign r_ptr_next = (~empty_o & re_i)? r_ptr + 1'b1 : r_ptr; | ||
|
|
||
| assign full_o = r_ptr == {~w_ptr[ADDR_BITS], w_ptr[ADDR_BITS-1:0]}; | ||
| assign empty_o = r_ptr == w_ptr; | ||
|
|
||
| assign rdata_o = mem[r_addr]; | ||
|
|
||
| assign w_addr = w_ptr[ADDR_BITS-1:0]; | ||
| assign r_addr = r_ptr[ADDR_BITS-1:0]; | ||
|
|
||
| always @(posedge clk_i, negedge rst_ni) begin | ||
| if(~rst_ni) begin | ||
| w_ptr <= 0; | ||
| r_ptr <= 0; | ||
| end | ||
| else begin | ||
| w_ptr <= w_ptr_next; | ||
| r_ptr <= r_ptr_next; | ||
| end | ||
| end | ||
|
|
||
| always @(posedge clk_i) begin | ||
| if(we_i & ~full_o) begin | ||
| mem[w_addr] <= wdata_i; | ||
| end | ||
| end | ||
|
|
||
| endmodule |
This file contains hidden or 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,26 @@ | ||
| /* | ||
| * 2 DFF sync clock domain crossing | ||
| * for async fifo queue | ||
| */ | ||
| `timescale 1ns/1ps | ||
|
|
||
| module ff2_sync #( | ||
| parameter WIDTH = 32 | ||
| ) ( | ||
| input wire clk_i, | ||
| input wire rst_ni, | ||
| input wire [WIDTH-1:0] wdata_i, | ||
| output reg [WIDTH-1:0] rdata_o | ||
| ); | ||
|
|
||
| reg [WIDTH-1:0] p0; | ||
|
|
||
| always @(posedge clk_i, negedge rst_ni) | ||
| if(~rst_ni) begin | ||
| p0 <= 0; | ||
| rdata_o <= 0; | ||
| end | ||
| else | ||
| {rdata_o, p0} <= {p0, wdata_i}; | ||
|
|
||
| endmodule |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.