-
Notifications
You must be signed in to change notification settings - Fork 1
/
topmodule.v
146 lines (127 loc) · 2.85 KB
/
topmodule.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
`timescale 1ns / 1ps
module topmodule #(parameter H = 752, parameter V = 480) (
input RST,
input CLK,
//DEBUG
output [13:0] debug,
//UART
input UART_RXD,
output UART_TXD,
//CAMERA
input CAM_PIXCLK,
input CAM_FRAME_VALID,
input CAM_LINE_VALID,
input [9:0] CAM_DATA,
output CAM_SYSCLK
);
reg [$clog2(V)-1:0] selected_line = 0;
reg [$clog2(H)-1:0] selected_column = 0;
wire [9:0] CAPTURED_DATA;
wire [$clog2(V)-1:0] CAPTURED_CURRENT_LINE;
wire [$clog2(H)-1:0] CAPTURED_CURRENT_COLUMN;
wire CAPTURED_PIXEL_VALID;
assign CAM_SYSCLK = CLK;
camera #(H,V) camera (
//inputs:
.PIXCLK(CAM_PIXCLK),
.FRAME_VALID(CAM_FRAME_VALID),
.LINE_VALID(CAM_LINE_VALID),
.DATA_IN(CAM_DATA),
//outputs:
.DATA_OUT(CAPTURED_DATA),
.CURRENT_LINE(CAPTURED_CURRENT_LINE),
.CURRENT_COLUMN(CAPTURED_CURRENT_COLUMN),
.PIXEL_VALID(CAPTURED_PIXEL_VALID)
);
(* keep="soft" *)
wire [1:0] CAPTURED_DATA_unused_bits = CAPTURED_DATA[1:0];
wire [7:0] SELECTED_PIXEL_DATA;
reg reset_buffer_ready_flag;
line_buffer #(H,V) line_buffer (
//inputs:
.CLK(CLK),
.VALID_DATA(CAPTURED_PIXEL_VALID),
.CURRENT_COLUMN(CAPTURED_CURRENT_COLUMN),
.CURRENT_LINE(CAPTURED_CURRENT_LINE),
.INTERESTING_LINE(selected_line),
.DATA_IN(CAPTURED_DATA[9:2]),
.READ_ADDRESS(selected_column),
.WHOLE_LINE_READY_FLAG(WHOLE_LINE_READY_FLAG),
//outputs:
.RESET_READY_FLAG(reset_buffer_ready_flag),
.DATA_OUT(SELECTED_PIXEL_DATA)
);
reg [7:0] uart_tx_data;
reg uart_tx_data_ready = 0;
uart_send uart_send (
//inputs:
.RST(RST),
.CLK(CLK),
.DATA(uart_tx_data),
.DATA_READY(uart_tx_data_ready),
//outputs:
.TXD(UART_TXD),
.IDLE(uart_tx_idle)
);
(* keep="soft" *)
wire [7:0] unconnected_received_data;
uart_receive uart_receive (
//inputs:
.RST(RST),
.CLK(CLK),
.RXD(UART_RXD),
//outputs:
.DATA(unconnected_received_data),
.RXD_READY(rxd_ready)
);
reg prev_rxd_ready;
wire byte_just_received = rxd_ready&&!prev_rxd_ready;
always@(posedge CLK)
begin
prev_rxd_ready <= rxd_ready;
end
reg sending_frame = 0;
always@(posedge CLK)
begin
if(byte_just_received && !sending_frame)
begin
sending_frame <= 1;
reset_buffer_ready_flag <= 0;
end
else
if(WHOLE_LINE_READY_FLAG && uart_tx_idle && sending_frame)
begin
uart_tx_data_ready<=1;
uart_tx_data<=SELECTED_PIXEL_DATA;
if(selected_column+1 != H)
begin
selected_column <= selected_column+1'b1;
reset_buffer_ready_flag <= 0;
end
else
begin
selected_column <= 0;
if(selected_line+1 == V)
begin
sending_frame <= 0;
selected_line <= 0;
reset_buffer_ready_flag <= 0;
end
else
begin
selected_line <= selected_line+1'b1;
reset_buffer_ready_flag <= 1;
end
end
end
else
begin
uart_tx_data_ready <= 0;
reset_buffer_ready_flag <= !sending_frame;
end
end
assign debug[0] = 1'b1;
assign debug[1] = sending_frame;
assign debug[2] = WHOLE_LINE_READY_FLAG;
assign debug[13:3] = 0;
endmodule