Skip to content

Commit 0f922ed

Browse files
committed
Update current progress
1 parent cf4ef1a commit 0f922ed

File tree

6 files changed

+138
-76
lines changed

6 files changed

+138
-76
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ work/
4141
ip_cores/
4242
*.jam
4343
*.svf
44+
greybox_tmp/
45+
*.qip
46+
*.ppf
47+
qmegawiz_errors_log.txt

pll/mem_pll.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ module mem_pll (
9191
.vcounderrange ());
9292
defparam
9393
altpll_component.bandwidth_type = "AUTO",
94-
altpll_component.clk0_divide_by = 48,
94+
altpll_component.clk0_divide_by = 12,
9595
altpll_component.clk0_duty_cycle = 50,
96-
altpll_component.clk0_multiply_by = 143,
96+
altpll_component.clk0_multiply_by = 25,
9797
altpll_component.clk0_phase_shift = "0",
9898
altpll_component.compensate_clock = "CLK0",
9999
altpll_component.inclk0_input_frequency = 20833,
@@ -169,7 +169,7 @@ endmodule
169169
// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING "Any"
170170
// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC "1"
171171
// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING "50.00000000"
172-
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING "143.000000"
172+
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING "100.000000"
173173
// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING "0"
174174
// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING "0"
175175
// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING "1"
@@ -194,7 +194,7 @@ endmodule
194194
// Retrieval info: PRIVATE: MIRROR_CLK0 STRING "0"
195195
// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC "1"
196196
// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING "1"
197-
// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING "143.00000000"
197+
// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING "100.00000000"
198198
// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING "1"
199199
// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING "MHz"
200200
// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING "1"
@@ -233,9 +233,9 @@ endmodule
233233
// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING "0"
234234
// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
235235
// Retrieval info: CONSTANT: BANDWIDTH_TYPE STRING "AUTO"
236-
// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC "48"
236+
// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC "12"
237237
// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC "50"
238-
// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC "143"
238+
// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC "25"
239239
// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING "0"
240240
// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING "CLK0"
241241
// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC "20833"

top/mkrvidor4000/Manifest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
files = [
22
"mkrvidor4000_top.sv",
3-
"MIPI_RX_ST.v",
43
"arbiter.sv"
54
]
65

@@ -11,7 +10,7 @@
1110
"git@github.com:hdl-util/vga-text-mode.git::master",
1211
"git@github.com:hdl-util/mipi-ccs.git::master",
1312
"git@github.com:hdl-util/mipi-csi-2.git::master",
14-
"git@github.com:hdl-util/as4c4m16sa.git::master",
13+
"git@github.com:hdl-util/sdram-controller.git::master",
1514
]
1615
}
1716

top/mkrvidor4000/arbiter.sv

Lines changed: 107 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ logic [15:0] data_read;
2828
logic data_read_valid;
2929
logic data_write_done;
3030

31-
as4c4m16sa #(
31+
as4c4m16sa_controller #(
32+
.CLK_RATE(100_000_000),
3233
.SPEED_GRADE(7),
3334
.READ_BURST_LENGTH(8),
3435
.WRITE_BURST(1),
@@ -52,86 +53,144 @@ as4c4m16sa #(
5253
.dq(dq),
5354
);
5455

55-
logic [15:0] mipi_buffer [0:31];
56-
logic [4:0] mipi_producer = 5'd0;
57-
logic [4:0] mipi_consumer = 5'd0;
56+
logic [31:0] mipi_buff_data;
57+
logic [3:0] mipi_buff_used;
58+
logic mipi_buff_read = 1'b0;
59+
dcfifo mipi_dcfifo (
60+
.data ({mipi_data[3], mipi_data[2], mipi_data[1], mipi_data[0]}),
61+
.rdclk (sdram_clk),
62+
.rdreq (mipi_buff_read),
63+
.wrclk (mipi_clk),
64+
.wrreq (mipi_data_enable),
65+
.q (mipi_buff_data),
66+
.rdempty (),
67+
.wrusedw (),
68+
.aclr (),
69+
.eccstatus (),
70+
.rdfull (),
71+
.rdusedw (mipi_buff_used),
72+
.wrempty (),
73+
.wrfull ());
74+
defparam
75+
mipi_dcfifo.intended_device_family = "Cyclone 10 LP",
76+
mipi_dcfifo.lpm_numwords = 16,
77+
mipi_dcfifo.lpm_showahead = "ON",
78+
mipi_dcfifo.lpm_type = "dcfifo",
79+
mipi_dcfifo.lpm_width = 32,
80+
mipi_dcfifo.lpm_widthu = 4,
81+
mipi_dcfifo.overflow_checking = "ON",
82+
mipi_dcfifo.rdsync_delaypipe = 4,
83+
mipi_dcfifo.underflow_checking = "ON",
84+
mipi_dcfifo.use_eab = "ON",
85+
mipi_dcfifo.wrsync_delaypipe = 4;
5886

59-
always @(posedge mipi_clk)
60-
begin
61-
if (mipi_data_enable)
62-
begin
63-
mipi_buffer[mipi_producer] <= {mipi_data[0], mipi_data[1]};
64-
mipi_buffer[mipi_producer + 1'd1] <= {mipi_data[2], mipi_data[3]};
65-
mipi_producer <= mipi_producer + 5'd2;
66-
end
67-
end
68-
69-
70-
logic [15:0] pixel_buffer [0:31];
71-
logic [4:0] pixel_producer = 5'd0;
72-
logic [4:0] pixel_consumer = 5'd0;
73-
logic pixel_countup = 1'd0;
74-
assign pixel = pixel_countup ? pixel_buffer[pixel_consumer][15:8] : pixel_buffer[pixel_consumer][7:0];
75-
76-
always @(posedge pixel_clk)
77-
begin
78-
if (pixel_enable)
79-
begin
80-
if (pixel_countup == 1'd1)
81-
pixel_consumer <= pixel_consumer + 1'd1;
82-
pixel_countup <= !pixel_countup;
83-
end
84-
end
8587

86-
logic [4:0] mipi_diff;
87-
assign mipi_diff = mipi_producer >= mipi_consumer ? mipi_producer - mipi_consumer : (~5'd0 - mipi_consumer) + mipi_producer;
88-
logic [4:0] pixel_diff;
89-
assign pixel_diff = pixel_producer >= pixel_consumer ? pixel_producer - pixel_consumer : (~5'd0 - pixel_consumer) + pixel_producer;
88+
logic [21:0] mipi_address = 22'd0;
89+
logic [21:0] pixel_address = 22'd0;
90+
logic [2:0] sdram_countup = 3'd0;
9091

91-
logic [17:0] mipi_address;
92-
logic [17:0] pixel_address;
92+
logic pixel_buff_write = 1'b0;
93+
logic [15:0] pixel_buff_data = 16'd0;
94+
logic [4:0] pixel_buff_used;
9395

94-
logic [2:0] sdram_countup = 3'd0;
9596
always @(posedge sdram_clk)
9697
begin
98+
mipi_buff_read <= 1'b0;
99+
pixel_buff_write <= 1'b0;
100+
pixel_buff_data <= 16'dx;
97101
if (command == 2'd0)
98102
begin
99-
if (pixel_diff < 5'd8) // Read is approaching starvation
103+
if (!pixel_buff_used[4]) // Read burst possible
100104
begin
101105
command <= 2'd2;
106+
data_write <= 16'dx;
102107
data_address <= pixel_address;
108+
sdram_countup <= 1'd0;
103109
end
104-
else if (mipi_diff >= 5'd15) // Ready to write
110+
else if (mipi_buff_used[3]) // Write burst possible
105111
begin
106112
command <= 2'd1;
107-
data_write <= mipi_buffer[mipi_consumer];
113+
data_write <= mipi_buff_data[15:0];
108114
data_address <= mipi_address;
109-
mipi_consumer <= mipi_consumer + 1'd1;
110-
sdram_countup <= sdram_countup + 1'd1;
115+
sdram_countup <= 1'd1;
116+
end
117+
else // Idle
118+
begin
119+
command <= 2'd0;
120+
data_write <= 16'dx;
121+
data_address <= 22'dx;
122+
sdram_countup <= 3'dx;
111123
end
112124
end
113125
else if (command == 2'd2 && data_read_valid)
114126
begin
115-
pixel_buffer[pixel_producer] <= data_read;
116-
pixel_producer <= pixel_producer + 1'd1;
127+
pixel_buff_data <= data_read;
128+
pixel_buff_write <= 1'b1;
117129
sdram_countup <= sdram_countup + 1'd1;
118130
if (sdram_countup == 3'd7) // Last read
119131
begin
120132
command <= 2'd0;
121-
pixel_address <= pixel_address + 8'd8 == 18'(VIDEO_END) ? 18'd0 : pixel_address + 18'd8;
133+
pixel_address <= pixel_address + 22'd8 == 22'(VIDEO_END) ? 22'd0 : pixel_address + 22'd8;
122134
end
123135
end
124136
else if (command == 2'd1 && data_write_done)
125137
begin
126-
data_write <= mipi_buffer[mipi_consumer];
127-
mipi_consumer <= mipi_consumer + 1'd1;
128138
sdram_countup <= sdram_countup + 1'd1;
139+
if (sdram_countup[0])
140+
begin
141+
data_write <= mipi_buff_data[31:16];
142+
mipi_buff_read <= 1'b1;
143+
end
144+
else
145+
begin
146+
data_write <= mipi_buff_data[15:0];
147+
mipi_buff_read <= 1'b0;
148+
end
149+
129150
if (sdram_countup == 3'd7) // Last write
130151
begin
131152
command <= 2'd0;
132-
mipi_address <= mipi_address + 8'd8 == 18'(VIDEO_END) ? 18'd0 : mipi_address + 18'd8;
153+
mipi_address <= mipi_address + 22'd8 == 22'(VIDEO_END) ? 22'd0 : mipi_address + 22'd8;
133154
end
134155
end
135156
end
136157

158+
159+
logic [15:0] internal_pixel;
160+
logic pixel_countup = 1'd0;
161+
assign pixel = pixel_countup ? internal_pixel[15:8] : internal_pixel[7:0];
162+
always @(posedge pixel_clk)
163+
begin
164+
if (pixel_enable)
165+
pixel_countup <= !pixel_countup;
166+
end
167+
168+
dcfifo pixel_dcfifo (
169+
.data (pixel_buff_data),
170+
.rdclk (pixel_clk),
171+
.rdreq (pixel_enable && pixel_countup == 1'b1),
172+
.wrclk (sdram_clk),
173+
.wrreq (pixel_buff_write),
174+
.q (internal_pixel),
175+
.rdempty (),
176+
.wrusedw (pixel_buff_used),
177+
.aclr (),
178+
.eccstatus (),
179+
.rdfull (),
180+
.rdusedw (),
181+
.wrempty (),
182+
.wrfull ());
183+
defparam
184+
pixel_dcfifo.intended_device_family = "Cyclone 10 LP",
185+
pixel_dcfifo.lpm_numwords = 32,
186+
pixel_dcfifo.lpm_showahead = "ON",
187+
pixel_dcfifo.lpm_type = "dcfifo",
188+
pixel_dcfifo.lpm_width = 16,
189+
pixel_dcfifo.lpm_widthu = 5,
190+
pixel_dcfifo.overflow_checking = "ON",
191+
pixel_dcfifo.rdsync_delaypipe = 4,
192+
pixel_dcfifo.underflow_checking = "ON",
193+
pixel_dcfifo.use_eab = "ON",
194+
pixel_dcfifo.wrsync_delaypipe = 4;
195+
137196
endmodule

top/mkrvidor4000/mkrvidor4000_top.sv

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,34 @@ module mkrvidor4000_top
100100

101101
);
102102

103-
// signal declaration
104-
wire OSC_CLK;
105-
106-
wire FLASH_CLK;
107-
108103
// internal oscillator
104+
wire OSC_CLK;
109105
cyclone10lp_oscillator osc (
110106
.clkout(OSC_CLK),
111107
.oscena(1'b1)
112108
);
113109

114-
mem_pll mem_pll (
115-
.inclk0(CLK_48MHZ),
116-
.c0(SDRAM_CLK)
117-
);
110+
// mem_pll mem_pll (
111+
// .inclk0(CLK_48MHZ),
112+
// .c0(SDRAM_CLK)
113+
// );
118114

119115
wire clk_pixel_x5;
120116
wire clk_pixel;
121117
wire clk_audio;
118+
assign SDRAM_CLK = clk_pixel_x5;
122119
hdmi_pll hdmi_pll(.inclk0(CLK_48MHZ), .c0(clk_pixel), .c1(clk_pixel_x5), .c2(clk_audio));
123120

124121
localparam AUDIO_BIT_WIDTH = 16;
125122
localparam AUDIO_RATE = 48000;
126123
localparam WAVE_RATE = 480;
127124

128-
logic [AUDIO_BIT_WIDTH-1:0] audio_sample_word;
125+
logic [AUDIO_BIT_WIDTH-1:0] audio_sample_word = AUDIO_BIT_WIDTH'(0);
129126
// sawtooth #(.BIT_WIDTH(AUDIO_BIT_WIDTH), .SAMPLE_RATE(AUDIO_RATE), .WAVE_RATE(WAVE_RATE)) sawtooth (.clk_audio(clk_audio), .level(audio_sample_word));
130127

131128
logic [23:0] rgb;
132129
logic [9:0] cx, cy, screen_start_x, screen_start_y;
133-
hdmi #(.VIDEO_ID_CODE(1),
134-
.DDRIO(1), .AUDIO_RATE(AUDIO_RATE), .AUDIO_BIT_WIDTH(AUDIO_BIT_WIDTH)) hdmi(.clk_pixel_x10(clk_pixel_x5), .clk_pixel(clk_pixel), .clk_audio(clk_audio), .rgb(rgb), .audio_sample_word('{audio_sample_word, audio_sample_word}), .tmds_p(HDMI_TX), .tmds_clock_p(HDMI_CLK), .tmds_n(HDMI_TX_N), .tmds_clock_n(HDMI_CLK_N), .cx(cx), .cy(cy), .screen_start_x(screen_start_x), .screen_start_y(screen_start_y));
130+
hdmi #(.VIDEO_ID_CODE(1), .DDRIO(1), .AUDIO_RATE(AUDIO_RATE), .AUDIO_BIT_WIDTH(AUDIO_BIT_WIDTH)) hdmi(.clk_pixel_x10(clk_pixel_x5), .clk_pixel(clk_pixel), .clk_audio(clk_audio), .rgb(rgb), .audio_sample_word('{audio_sample_word, audio_sample_word}), .tmds_p(HDMI_TX), .tmds_clock_p(HDMI_CLK), .tmds_n(HDMI_TX_N), .tmds_clock_n(HDMI_CLK_N), .cx(cx), .cy(cy), .screen_start_x(screen_start_x), .screen_start_y(screen_start_y));
135131

136132
logic [1:0] mode = 2'd0;
137133
logic [1:0] resolution = 2'd3; // 640x480 @ 30FPS
@@ -140,7 +136,7 @@ logic ready;
140136
logic model_err;
141137
logic nack_err;
142138

143-
ov5647 #(.TARGET_SCL_RATE(100000)) ov5647 (
139+
ov5647 #(.INPUT_CLK_RATE(48_000_000), .TARGET_SCL_RATE(100_000)) ov5647 (
144140
.clk_in(CLK_48MHZ),
145141
.scl(MIPI_SCL),
146142
.sda(MIPI_SDA),
@@ -153,12 +149,11 @@ ov5647 #(.TARGET_SCL_RATE(100000)) ov5647 (
153149
.nack_err(nack_err)
154150
);
155151

156-
logic [7:0] image_data [0:3];
152+
logic [7:0] image_data [0:3] = '{8'hff, 8'hff, 8'hff, 8'hff};
157153
logic [5:0] image_data_type;
158-
logic image_data_enable;
154+
logic image_data_enable = 1'b1;
159155
logic [15:0] word_count;
160156
logic frame_start, frame_end;
161-
logic [1:0] enable;
162157
camera #(.NUM_LANES(2)) camera (
163158
.clock_p(MIPI_CLK),
164159
.data_p(MIPI_D),
@@ -208,8 +203,7 @@ arbiter arbiter (
208203

209204
always @(posedge clk_pixel)
210205
begin
211-
if (pixel_enable)
212-
rgb <= {pixel, pixel, pixel};
206+
rgb <= {pixel, pixel, pixel};
213207
end
214208

215209
// logic [7:0] codepoints [0:3];

top/mkrvidor4000/pinout.tcl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ set_global_assignment -name OPTIMIZATION_MODE "AGGRESSIVE PERFORMANCE"
1414
set_global_assignment -name CYCLONEII_OPTIMIZATION_TECHNIQUE SPEED
1515
set_global_assignment -name ADV_NETLIST_OPT_SYNTH_WYSIWYG_REMAP ON
1616
set_global_assignment -name REMOVE_REDUNDANT_LOGIC_CELLS ON
17-
set_global_assignment -name PHYSICAL_SYNTHESIS_COMBO_LOGIC_FOR_AREA ON
18-
set_global_assignment -name PHYSICAL_SYNTHESIS_MAP_LOGIC_TO_MEMORY_FOR_AREA ON
17+
# set_global_assignment -name PHYSICAL_SYNTHESIS_COMBO_LOGIC_FOR_AREA ON
18+
# set_global_assignment -name PHYSICAL_SYNTHESIS_MAP_LOGIC_TO_MEMORY_FOR_AREA ON
19+
set_global_assignment -name PHYSICAL_SYNTHESIS_COMBO_LOGIC ON
20+
set_global_assignment -name PHYSICAL_SYNTHESIS_REGISTER_DUPLICATION ON
21+
set_global_assignment -name PHYSICAL_SYNTHESIS_REGISTER_RETIMING ON
22+
set_global_assignment -name ROUTER_CLOCKING_TOPOLOGY_ANALYSIS ON
23+
set_global_assignment -name PHYSICAL_SYNTHESIS_ASYNCHRONOUS_SIGNAL_PIPELINING ON
24+
# set_global_assignment -name ROUTER_TIMING_OPTIMIZATION_LEVEL MAXIMUM
1925

2026
set_global_assignment -name ERROR_CHECK_FREQUENCY_DIVISOR 1
2127
set_global_assignment -name NOMINAL_CORE_SUPPLY_VOLTAGE 1.2V

0 commit comments

Comments
 (0)