Skip to content

Commit 8dc62a8

Browse files
committed
Initial commit
1 parent 39ab9ce commit 8dc62a8

File tree

3 files changed

+203
-4
lines changed

3 files changed

+203
-4
lines changed

src/controlUnit.v

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
module controlUnit(
2+
// Signal kojim vanjski svijet dojavljuje da je spremna nova ul. znacajka
3+
input wire clk,
4+
input wire rst_n,
5+
input wire dataw_rdy,
6+
output wire [3:0] oe_reg;
7+
output wire [3:0] we_reg;
8+
);
9+
10+
// Counter for adressing the current line buffer being written to
11+
reg [1:0] current_write_buff;
12+
// Counts total number of lines loaded
13+
reg [9:0] line_cnt;
14+
// Counter for the number of input features
15+
reg [2:0] write_feature_cnt;
16+
17+
// Counter for multiplexing line buffer output enable ports
18+
reg [1:0] current_read_buff;
19+
// Read ready signal
20+
wire datar_rdy;
21+
// Counter for number of read features
22+
reg [2:0] read_feature_cnt;
23+
24+
// ============ write controller ============
25+
always @(posedge clk)
26+
begin
27+
if (!rst_n)
28+
write_feature_cnt <= 3'b0;
29+
else if (dataw_rdy)
30+
write_feature_cnt <= write_feature_cnt + 1;
31+
end
32+
33+
always @(posedge clk)
34+
begin
35+
if (!rst_n)
36+
begin
37+
current_write_buff <= 2'b0;
38+
line_cnt <= 10'b0;
39+
end
40+
else if (write_feature_cnt == 7 & dataw_rdy)
41+
begin
42+
current_write_buff <= current_write_buff + 1;
43+
line_cnt <= line_cnt + 1;
44+
end
45+
end
46+
47+
// Combo logic for write enable activation
48+
always @(*)
49+
begin
50+
we_reg = 3'b0;
51+
we_reg[current_write_buff] = 1;
52+
end
53+
// ============ end write controller ============
54+
55+
// ============ read controller =============
56+
always @(posedge clk)
57+
begin
58+
if (!rst_n)
59+
read_feature_cnt <= 3'b0;
60+
else if (datar_rdy)
61+
read_feature_cnt <= read_feature_cnt + 1;
62+
end
63+
64+
always @(posedge clk)
65+
begin
66+
if (!rst_n)
67+
current_read_buff <= 2'b0;
68+
else if (read_feature_cnt == 7 & datar_rdy)
69+
current_read_buff <= current_read_buff + 1;
70+
end
71+
72+
// Combo logic for read enable activation
73+
always @(*)
74+
begin
75+
case (current_read_buff)
76+
0: begin
77+
oe_reg[0] = datar_rdy;
78+
oe_reg[1] = datar_rdy;
79+
oe_reg[2] = datar_rdy;
80+
oe_reg[3] = 1'b0;
81+
end
82+
1: begin
83+
oe_reg[0] = 1'b0;
84+
oe_reg[1] = datar_rdy;
85+
oe_reg[2] = datar_rdy;
86+
oe_reg[3] = datar_rdy;
87+
end
88+
2: begin
89+
oe_reg[0] = datar_rdy;
90+
oe_reg[1] = 1'b0;
91+
oe_reg[2] = datar_rdy;
92+
oe_reg[3] = datar_rdy;
93+
end
94+
3: begin
95+
oe_reg[0] = datar_rdy;
96+
oe_reg[1] = datar_rdy;
97+
oe_reg[2] = 1'b0;
98+
oe_reg[3] = datar_rdy;
99+
end
100+
endcase
101+
end
102+
// ============ end read controller =============
103+
104+
endmodule

src/lineBuffer.v

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
module lineBuffer(
2+
input wire clk,
3+
input wire rst_n, // low to reset
4+
input wire we, // write enable
5+
input wire oe, // output enable
6+
input wire [7:0] wr_data,
7+
output wire [23:0] rd_data // output data consists of three consecutive values stored in memory
8+
);
9+
10+
// line buffer with eight 8-bit locations
11+
reg [7:0] buffer [7:0];
12+
13+
// counter register for writing
14+
reg [2:0] w_ptr; // 0-7
15+
16+
// counter register for reading
17+
reg [2:0] r_ptr; // 0-7
18+
19+
/*
20+
line buffer modeled like single-port RAM:
21+
https://yosyshq.readthedocs.io/projects/yosys/en/latest/using_yosys/synthesis/memory.html#single-port-ram-memory-patterns
22+
*/
23+
// write logic
24+
always @(posedge clk)
25+
begin
26+
if (we)
27+
buffer[w_ptr] <= wr_data;
28+
end
29+
30+
// read logic
31+
assign rd_data = {buffer[rd_data], buffer[rd_data + 1], buffer[rd_data + 2]};
32+
33+
// write counter logic
34+
always @(posedge clk)
35+
begin
36+
if (!rst_n)
37+
w_ptr <= 3'b0;
38+
else if (we)
39+
w_ptr <= w_ptr + 1'b1;
40+
else
41+
w_ptr <= w_ptr; // done to prevent a latch from inferring
42+
end
43+
44+
// read counter logic
45+
always @(posedge clk)
46+
begin
47+
if (!rst_n)
48+
r_ptr <= 3'b0;
49+
else if (oe)
50+
r_ptr <= r_ptr + 1'b1;
51+
else
52+
r_ptr <= r_ptr; // done to prevent a latch from inferring
53+
end
54+
55+
endmodule

src/project.v

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
`default_nettype none
77

8-
module tt_um_example (
8+
module tt_um_koderchina_conv (
99
input wire [7:0] ui_in, // Dedicated inputs
1010
output wire [7:0] uo_out, // Dedicated outputs
1111
input wire [7:0] uio_in, // IOs: Input path
@@ -17,9 +17,49 @@ module tt_um_example (
1717
);
1818

1919
// All output pins must be assigned. If not used, assign to 0.
20-
assign uo_out = ui_in + uio_in; // Example: ou_out is the sum of ui_in and uio_in
21-
assign uio_out = 0;
22-
assign uio_oe = 0;
20+
wire we = ui_in[0]; // use bit 0 as write enable
21+
wire oe = ui_in[1]; // use bit 1 as output enable
22+
wire [7:0] wr_data = ui_in[7:0]; // could use all 8 input bits as data
23+
assign uio_oe = 8'hFF; // all uio pins drive outputs
24+
25+
wire[3:0] we_reg;
26+
wire[3:0] oe_reg;
27+
28+
lineBuffer b0(
29+
.clk(clk),
30+
.rst_n(rst_n),
31+
.we(we_reg[0]),
32+
.oe(oe_reg[0]),
33+
.wr_data(data_in),
34+
.rd_data()
35+
);
36+
37+
lineBuffer b1(
38+
.clk(clk),
39+
.rst_n(rst_n),
40+
.we(we_reg[1]),
41+
.oe(oe_reg[1]),
42+
.wr_data(data_in),
43+
.rd_data()
44+
);
45+
46+
lineBuffer b2(
47+
.clk(clk),
48+
.rst_n(rst_n),
49+
.we(we_reg[2]),
50+
.oe(oe_reg[2]),
51+
.wr_data(data_in),
52+
.rd_data()
53+
);
54+
55+
lineBuffer b3(
56+
.clk(clk),
57+
.rst_n(rst_n),
58+
.we(we_reg[3]),
59+
.oe(oe_reg[3]),
60+
.wr_data(data_in),
61+
.rd_data()
62+
);
2363

2464
// List all unused inputs to prevent warnings
2565
wire _unused = &{ena, clk, rst_n, 1'b0};

0 commit comments

Comments
 (0)