diff --git a/Artix-7-HDMI-processing.xpr b/Artix-7-HDMI-processing.xpr
index d9b71b4..8ee608d 100644
--- a/Artix-7-HDMI-processing.xpr
+++ b/Artix-7-HDMI-processing.xpr
@@ -42,7 +42,7 @@
-
+
diff --git a/src/window_matcher.v b/src/window_matcher.v
index 863ae28..956c057 100644
--- a/src/window_matcher.v
+++ b/src/window_matcher.v
@@ -34,7 +34,7 @@ module window_matcher(
output [7:0] out_red, [7:0] out_green, [7:0] out_blue,
/* Overlay data IO */
- output win_hsync, win_vsync,
+ output reg win_hsync, reg win_vsync,
output win_blank,
output reg [11:0] win_w,
output reg [11:0] win_h,
@@ -92,8 +92,8 @@ module window_matcher(
/* Window matching state machine */
reg [11:0] scan_x;
reg [11:0] scan_y;
- reg [11:0] window_x;
- reg [11:0] window_y;
+ reg [11:0] win_x_int;
+ reg [11:0] win_y_int;
reg [11:0] win_w_int;
reg [11:0] win_h_int;
reg win_hsync_int, win_vsync_int;
@@ -109,8 +109,6 @@ module window_matcher(
always @(posedge clk) begin
if (rst == 1 || in_vsync == 0) begin
matcher_state <= ST_MAT_WAITING;
- window_x <= 0;
- window_y <= 0;
win_w_int <= 0;
win_h_int <= 0;
@@ -119,8 +117,8 @@ module window_matcher(
ST_MAT_WAITING: begin
if (in_pxd_pattern_match) begin
matcher_state <= ST_MAT_RX0;
- window_x <= scan_x_reg[2];
- window_y <= scan_y;
+ win_x_int <= scan_x_reg[2];
+ win_y_int <= scan_y;
end
end
ST_MAT_RX0: begin
@@ -142,8 +140,8 @@ module window_matcher(
win_hsync_int <= 1;
out_data_valid <= 1;
win_vsync_int <= 1;
- win_hsync_ctr <= 9;
- win_vsync_ctr <= 0;
+ win_hsync_ctr_int <= 9;
+ win_vsync_ctr_int <= 0;
end
endcase
end
@@ -202,69 +200,132 @@ module window_matcher(
end
/* Match locking process */
+ reg [11:0] win_x;
+ reg [11:0] win_y;
reg match_locked; /* Goes high after a frame with a marker has been fully received */
always @(posedge clk) begin
if (rst) begin
match_locked <= 0;
+ win_locked <= 0;
+ win_w <= 0;
+ win_h <= 0;
+ win_x <= 0;
+ win_y <= 0;
end else begin
if (in_vsync_reg == 1 && in_vsync == 0) begin
match_locked <= matched;
win_locked <= matched;
- win_w <= win_w_int;
- win_h <= win_h_int;
+
+ if (matched) begin
+ win_w <= win_w_int;
+ win_h <= win_h_int;
+ win_x <= win_x_int;
+ win_y <= win_y_int;
+ end else begin
+ win_w <= 0;
+ win_h <= 0;
+ win_x <= 0;
+ win_y <= 0;
+ end
end
end
end
/* Window sync generator */
- reg [11:0] win_hsync_ctr;
- reg [11:0] win_vsync_ctr;
+ reg [11:0] win_hsync_ctr_int;
+ reg [11:0] win_vsync_ctr_int;
- assign win_hsync = win_hsync_int && match_locked;
- assign win_vsync = win_vsync_int && match_locked && in_vsync;
always @(posedge clk) begin
if (rst == 1) begin
win_hsync_int <= 0;
win_vsync_int <= 0;
- win_hsync_ctr <= 0;
- win_vsync_ctr <= 0;
+ win_hsync_ctr_int <= 0;
+ win_vsync_ctr_int <= 0;
out_data_valid <= 0;
end else begin
if (matcher_state == ST_MAT_DATA) begin
/* hsync */
- if (scan_x == window_x && win_vsync_int == 1) begin
+ if (scan_x == win_x_int && win_vsync_int == 1) begin
win_hsync_int <= 1;
- win_hsync_ctr <= 1;
+ win_hsync_ctr_int <= 1;
out_data_valid <= 1;
end
if (win_hsync_int == 1) begin
- win_hsync_ctr <= win_hsync_ctr + 1;
+ win_hsync_ctr_int <= win_hsync_ctr_int + 1;
end
- if (win_hsync_ctr == win_w_int || in_hsync_reg == 0) begin
+ if (win_hsync_ctr_int == win_w_int || in_hsync_reg == 0) begin
win_hsync_int <= 0;
out_data_valid <= 0;
- win_hsync_ctr <= 0;
+ win_hsync_ctr_int <= 0;
end
if (in_hsync_reg == 1 && in_hsync == 0) begin
- if (scan_y == window_y) begin
+ if (scan_y == win_y_int) begin
win_vsync_int <= 1;
- win_vsync_ctr <= 0;
+ win_vsync_ctr_int <= 0;
end
- win_vsync_ctr <= win_vsync_ctr + 1;
+ win_vsync_ctr_int <= win_vsync_ctr_int + 1;
end
- if (win_vsync_ctr == win_h_int) begin
+ if (win_vsync_ctr_int == win_h_int) begin
win_vsync_int <= 0;
end
+ if (in_vsync_reg == 1 && in_vsync == 0) begin
+ win_vsync_ctr_int <= 0;
+ end
+ end
+ end
+ end
+
+ /* Window H/VSYNC outputs */
+ reg [11:0] win_hsync_ctr;
+ reg [11:0] win_vsync_ctr;
+
+ always @(posedge clk) begin
+ if (rst == 1) begin
+ win_hsync <= 0;
+ win_vsync <= 0;
+ win_hsync_ctr <= 0;
+ win_vsync_ctr <= 0;
+
+ end else begin
+ if (match_locked) begin
+ /* hsync */
+ if (scan_x == win_x && win_vsync == 1) begin
+ win_hsync <= 1;
+ win_hsync_ctr <= 1;
+ end
+
+ if (win_hsync == 1) begin
+ win_hsync_ctr <= win_hsync_ctr + 1;
+ end
+
+ if (win_hsync_ctr == win_w || in_hsync_reg == 0) begin
+ win_hsync <= 0;
+ win_hsync_ctr <= 0;
+ end
+
+ if (in_hsync_reg == 1 && in_hsync == 0 && win_vsync) begin
+ win_vsync_ctr <= win_vsync_ctr + 1;
+ end
+
+ if (scan_y == win_y) begin
+ win_vsync <= 1;
+ end
+
+ if (win_vsync_ctr == win_h) begin
+ win_vsync <= 0;
+ end
+
if (in_vsync_reg == 1 && in_vsync == 0) begin
win_vsync_ctr <= 0;
+ win_vsync <= 0;
end
end
end
diff --git a/test_bench/window_matcher_tb_gen.ipynb b/test_bench/window_matcher_tb_gen.ipynb
index 46a00cc..f212713 100644
--- a/test_bench/window_matcher_tb_gen.ipynb
+++ b/test_bench/window_matcher_tb_gen.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
- "id": "peaceful-dream",
+ "id": "brilliant-stations",
"metadata": {},
"source": [
"# Window Matcher Testcase Generator"
@@ -11,7 +11,7 @@
{
"cell_type": "code",
"execution_count": 67,
- "id": "sustained-reservoir",
+ "id": "worth-faith",
"metadata": {},
"outputs": [],
"source": [
@@ -32,7 +32,7 @@
{
"cell_type": "code",
"execution_count": 93,
- "id": "modular-partnership",
+ "id": "removed-rugby",
"metadata": {},
"outputs": [],
"source": [
@@ -121,7 +121,7 @@
{
"cell_type": "code",
"execution_count": 87,
- "id": "yellow-affiliate",
+ "id": "specialized-reporter",
"metadata": {},
"outputs": [
{
@@ -149,7 +149,7 @@
{
"cell_type": "code",
"execution_count": 94,
- "id": "quick-proposition",
+ "id": "voluntary-chancellor",
"metadata": {},
"outputs": [],
"source": [
@@ -173,7 +173,7 @@
{
"cell_type": "code",
"execution_count": 95,
- "id": "usual-flash",
+ "id": "familiar-classification",
"metadata": {},
"outputs": [
{
@@ -243,7 +243,7 @@
{
"cell_type": "code",
"execution_count": 54,
- "id": "surrounded-devon",
+ "id": "signed-garden",
"metadata": {},
"outputs": [],
"source": [
@@ -264,8 +264,8 @@
},
{
"cell_type": "code",
- "execution_count": 96,
- "id": "listed-addition",
+ "execution_count": 101,
+ "id": "packed-chapter",
"metadata": {},
"outputs": [
{
@@ -313,7 +313,7 @@
"for (read_pos=0; read_pos<{{fb_len}}; read_pos=read_pos+1) begin\n",
" \n",
" if (!(win_hsync == 0)) $finish;\n",
- " if (!(win_vsync == 0)) $finish;\n",
+ " if (!(!in_vsync || win_vsync == 0)) $finish;\n",
" if (!(in_blank == 1 || win_w == 0)) $finish;\n",
" if (!(in_blank == 1 || win_h == 0)) $finish;\n",
" if (!(!out_data_valid || out_data_en)) $finish;\n",
@@ -348,12 +348,15 @@
"\n",
"for (read_pos=0; read_pos<{{fb_len}}; read_pos=read_pos+1) begin\n",
" if (read_pos > 0) begin\n",
- " //if (!(win_hsync == {{mem}}[read_pos-1][{{ FLAG_WIN_HSYNC }}])) $finish;\n",
- " //if (!(win_vsync == {{mem}}[read_pos-1][{{ FLAG_WIN_VSYNC }}])) $finish;\n",
+ " if (!(win_hsync == win_hsync_exp_last)) $finish;\n",
+ " /* Only check win_vsync aligns with expected value during win_hsync */\n",
+ " if (!(!win_hsync_exp_last || win_vsync == win_vsync_exp_last)) $finish;\n",
" end\n",
" \n",
" in_hsync = {{mem}}[read_pos][{{ FLAG_HSYNC }}];\n",
" in_vsync = {{mem}}[read_pos][{{ FLAG_VSYNC }}];\n",
+ " win_hsync_exp_last = win_hsync_exp;\n",
+ " win_vsync_exp_last = win_vsync_exp;\n",
" win_hsync_exp = {{mem}}[read_pos][{{ FLAG_WIN_HSYNC }}];\n",
" win_vsync_exp = {{mem}}[read_pos][{{ FLAG_WIN_VSYNC }}];\n",
" win_header = {{mem}}[read_pos][{{ FLAG_WIN_HEADER }}];\n",
@@ -390,7 +393,7 @@
{
"cell_type": "code",
"execution_count": 8,
- "id": "protected-bronze",
+ "id": "sunset-saturday",
"metadata": {},
"outputs": [],
"source": [
@@ -402,7 +405,7 @@
{
"cell_type": "code",
"execution_count": 9,
- "id": "unknown-framing",
+ "id": "induced-tenant",
"metadata": {},
"outputs": [
{
@@ -425,7 +428,7 @@
{
"cell_type": "code",
"execution_count": 10,
- "id": "political-blink",
+ "id": "serious-advice",
"metadata": {},
"outputs": [
{
@@ -448,7 +451,7 @@
{
"cell_type": "code",
"execution_count": 11,
- "id": "intelligent-locator",
+ "id": "comparative-passion",
"metadata": {},
"outputs": [
{
@@ -486,7 +489,7 @@
{
"cell_type": "code",
"execution_count": 12,
- "id": "breeding-representation",
+ "id": "greatest-duration",
"metadata": {},
"outputs": [
{
@@ -526,7 +529,7 @@
{
"cell_type": "code",
"execution_count": 13,
- "id": "duplicate-riverside",
+ "id": "mysterious-michigan",
"metadata": {},
"outputs": [
{
@@ -566,7 +569,7 @@
{
"cell_type": "code",
"execution_count": 14,
- "id": "homeless-posting",
+ "id": "numerical-result",
"metadata": {},
"outputs": [
{
diff --git a/window_matcher_tb_behav.wcfg b/window_matcher_tb_behav.wcfg
index 24ebf3b..2bda606 100644
--- a/window_matcher_tb_behav.wcfg
+++ b/window_matcher_tb_behav.wcfg
@@ -11,15 +11,15 @@
-
-
-
+
+
+
-
+
clk
clk
@@ -68,16 +68,16 @@
out_green[7:0]
out_green[7:0]
-
- out_blue[7:0]
- out_blue[7:0]
-
win_hsync
win_hsync
#FFFF00
true
+
+ out_blue[7:0]
+ out_blue[7:0]
+
win_hsync_int
win_hsync_int
@@ -156,19 +156,25 @@
scan_y[11:0]
UNSIGNEDDECRADIX
-
- window_x[11:0]
- window_x[11:0]
+
+ win_x[11:0]
+ win_x[11:0]
UNSIGNEDDECRADIX
- #00FF7F
- true
-
- window_y[11:0]
- window_y[11:0]
+
+ win_y[11:0]
+ win_y[11:0]
+ UNSIGNEDDECRADIX
+
+
+ win_x_int[11:0]
+ win_x_int[11:0]
+ UNSIGNEDDECRADIX
+
+
+ win_y_int[11:0]
+ win_y_int[11:0]
UNSIGNEDDECRADIX
- #00FF7F
- true
win_w_int[11:0]
@@ -195,11 +201,21 @@
win_hsync_ctr[11:0]
UNSIGNEDDECRADIX
+
+ win_hsync_ctr_int[11:0]
+ win_hsync_ctr_int[11:0]
+ UNSIGNEDDECRADIX
+
win_vsync_ctr[11:0]
win_vsync_ctr[11:0]
UNSIGNEDDECRADIX
+
+ win_vsync_ctr_int[11:0]
+ win_vsync_ctr_int[11:0]
+ UNSIGNEDDECRADIX
+
matcher_state[5:0]
matcher_state[5:0]