Skip to content

Commit 9a13548

Browse files
committed
uart-no-param: simple Verilog without parameters to create simple macro tests
VERILOG_TOP_PARAMS does not work in conjunction with the BLOCKS makefile variable. This is a simple code-base suitable for non-trivial smoke-tests on e.g. ASAP7 Signed-off-by: Øyvind Harboe <[email protected]>
1 parent e1c925b commit 9a13548

File tree

5 files changed

+386
-0
lines changed

5 files changed

+386
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
3+
Copyright (c) 2014-2017 Alex Forencich
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
*/
24+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Summary
2+
3+
Basic Universal Asynchronous Receiver Transmitter, communications application
4+
5+
# Source
6+
7+
# Modifications
8+
9+
- Added sdc timing constraints.
10+
- Added LICENSE file.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
3+
Copyright (c) 2014-2017 Alex Forencich
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
*/
24+
25+
// Language: Verilog 2001
26+
27+
`timescale 1ns / 1ps
28+
29+
/*
30+
* AXI4-Stream UART
31+
*/
32+
module uart(
33+
input wire clk,
34+
input wire rst,
35+
36+
/*
37+
* AXI input
38+
*/
39+
input wire [8-1:0] s_axis_tdata,
40+
input wire s_axis_tvalid,
41+
output wire s_axis_tready,
42+
43+
/*
44+
* AXI output
45+
*/
46+
output wire [8-1:0] m_axis_tdata,
47+
output wire m_axis_tvalid,
48+
input wire m_axis_tready,
49+
50+
/*
51+
* UART interface
52+
*/
53+
input wire rxd,
54+
output wire txd,
55+
56+
/*
57+
* Status
58+
*/
59+
output wire tx_busy,
60+
output wire rx_busy,
61+
output wire rx_overrun_error,
62+
output wire rx_frame_error,
63+
64+
/*
65+
* Configuration
66+
*/
67+
input wire [15:0] prescale
68+
69+
);
70+
71+
uart_tx uart_tx_inst (
72+
.clk(clk),
73+
.rst(rst),
74+
// axi input
75+
.s_axis_tdata(s_axis_tdata),
76+
.s_axis_tvalid(s_axis_tvalid),
77+
.s_axis_tready(s_axis_tready),
78+
// output
79+
.txd(txd),
80+
// status
81+
.busy(tx_busy),
82+
// configuration
83+
.prescale(prescale)
84+
);
85+
86+
uart_rx uart_rx_inst (
87+
.clk(clk),
88+
.rst(rst),
89+
// axi output
90+
.m_axis_tdata(m_axis_tdata),
91+
.m_axis_tvalid(m_axis_tvalid),
92+
.m_axis_tready(m_axis_tready),
93+
// input
94+
.rxd(rxd),
95+
// status
96+
.busy(rx_busy),
97+
.overrun_error(rx_overrun_error),
98+
.frame_error(rx_frame_error),
99+
// configuration
100+
.prescale(prescale)
101+
);
102+
103+
endmodule
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
3+
Copyright (c) 2014-2017 Alex Forencich
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
*/
24+
25+
// Language: Verilog 2001
26+
27+
`timescale 1ns / 1ps
28+
29+
/*
30+
* AXI4-Stream UART
31+
*/
32+
module uart_rx(
33+
input wire clk,
34+
input wire rst,
35+
36+
/*
37+
* AXI output
38+
*/
39+
output wire [8-1:0] m_axis_tdata,
40+
output wire m_axis_tvalid,
41+
input wire m_axis_tready,
42+
43+
/*
44+
* UART interface
45+
*/
46+
input wire rxd,
47+
48+
/*
49+
* Status
50+
*/
51+
output wire busy,
52+
output wire overrun_error,
53+
output wire frame_error,
54+
55+
/*
56+
* Configuration
57+
*/
58+
input wire [15:0] prescale
59+
60+
);
61+
62+
reg [8-1:0] m_axis_tdata_reg = 0;
63+
reg m_axis_tvalid_reg = 0;
64+
65+
reg rxd_reg = 1;
66+
67+
reg busy_reg = 0;
68+
reg overrun_error_reg = 0;
69+
reg frame_error_reg = 0;
70+
71+
reg [8-1:0] data_reg = 0;
72+
reg [18:0] prescale_reg = 0;
73+
reg [3:0] bit_cnt = 0;
74+
75+
assign m_axis_tdata = m_axis_tdata_reg;
76+
assign m_axis_tvalid = m_axis_tvalid_reg;
77+
78+
assign busy = busy_reg;
79+
assign overrun_error = overrun_error_reg;
80+
assign frame_error = frame_error_reg;
81+
82+
always @(posedge clk) begin
83+
if (rst) begin
84+
m_axis_tdata_reg <= 0;
85+
m_axis_tvalid_reg <= 0;
86+
rxd_reg <= 1;
87+
prescale_reg <= 0;
88+
bit_cnt <= 0;
89+
busy_reg <= 0;
90+
overrun_error_reg <= 0;
91+
frame_error_reg <= 0;
92+
end else begin
93+
rxd_reg <= rxd;
94+
overrun_error_reg <= 0;
95+
frame_error_reg <= 0;
96+
97+
if (m_axis_tvalid && m_axis_tready) begin
98+
m_axis_tvalid_reg <= 0;
99+
end
100+
101+
if (prescale_reg > 0) begin
102+
prescale_reg <= prescale_reg - 1;
103+
end else if (bit_cnt > 0) begin
104+
if (bit_cnt > 8+1) begin
105+
if (!rxd_reg) begin
106+
bit_cnt <= bit_cnt - 1;
107+
prescale_reg <= (prescale << 3)-1;
108+
end else begin
109+
bit_cnt <= 0;
110+
prescale_reg <= 0;
111+
end
112+
end else if (bit_cnt > 1) begin
113+
bit_cnt <= bit_cnt - 1;
114+
prescale_reg <= (prescale << 3)-1;
115+
data_reg <= {rxd_reg, data_reg[8-1:1]};
116+
end else if (bit_cnt == 1) begin
117+
bit_cnt <= bit_cnt - 1;
118+
if (rxd_reg) begin
119+
m_axis_tdata_reg <= data_reg;
120+
m_axis_tvalid_reg <= 1;
121+
overrun_error_reg <= m_axis_tvalid_reg;
122+
end else begin
123+
frame_error_reg <= 1;
124+
end
125+
end
126+
end else begin
127+
busy_reg <= 0;
128+
if (!rxd_reg) begin
129+
prescale_reg <= (prescale << 2)-2;
130+
bit_cnt <= 8+2;
131+
data_reg <= 0;
132+
busy_reg <= 1;
133+
end
134+
end
135+
end
136+
end
137+
138+
endmodule
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
3+
Copyright (c) 2014-2017 Alex Forencich
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
*/
24+
25+
// Language: Verilog 2001
26+
27+
`timescale 1ns / 1ps
28+
29+
/*
30+
* AXI4-Stream UART
31+
*/
32+
module uart_tx(
33+
input wire clk,
34+
input wire rst,
35+
36+
/*
37+
* AXI input
38+
*/
39+
input wire [8-1:0] s_axis_tdata,
40+
input wire s_axis_tvalid,
41+
output wire s_axis_tready,
42+
43+
/*
44+
* UART interface
45+
*/
46+
output wire txd,
47+
48+
/*
49+
* Status
50+
*/
51+
output wire busy,
52+
53+
/*
54+
* Configuration
55+
*/
56+
input wire [15:0] prescale
57+
);
58+
59+
reg s_axis_tready_reg = 0;
60+
61+
reg txd_reg = 1;
62+
63+
reg busy_reg = 0;
64+
65+
reg [8:0] data_reg = 0;
66+
reg [18:0] prescale_reg = 0;
67+
reg [3:0] bit_cnt = 0;
68+
69+
assign s_axis_tready = s_axis_tready_reg;
70+
assign txd = txd_reg;
71+
72+
assign busy = busy_reg;
73+
74+
always @(posedge clk) begin
75+
if (rst) begin
76+
s_axis_tready_reg <= 0;
77+
txd_reg <= 1;
78+
prescale_reg <= 0;
79+
bit_cnt <= 0;
80+
busy_reg <= 0;
81+
end else begin
82+
if (prescale_reg > 0) begin
83+
s_axis_tready_reg <= 0;
84+
prescale_reg <= prescale_reg - 1;
85+
end else if (bit_cnt == 0) begin
86+
s_axis_tready_reg <= 1;
87+
busy_reg <= 0;
88+
89+
if (s_axis_tvalid) begin
90+
s_axis_tready_reg <= !s_axis_tready_reg;
91+
prescale_reg <= (prescale << 3)-1;
92+
bit_cnt <= 8+1;
93+
data_reg <= {1'b1, s_axis_tdata};
94+
txd_reg <= 0;
95+
busy_reg <= 1;
96+
end
97+
end else begin
98+
if (bit_cnt > 1) begin
99+
bit_cnt <= bit_cnt - 1;
100+
prescale_reg <= (prescale << 3)-1;
101+
{data_reg, txd_reg} <= {1'b0, data_reg};
102+
end else if (bit_cnt == 1) begin
103+
bit_cnt <= bit_cnt - 1;
104+
prescale_reg <= (prescale << 3);
105+
txd_reg <= 1;
106+
end
107+
end
108+
end
109+
end
110+
111+
endmodule

0 commit comments

Comments
 (0)