Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

videomixer: timeout on IDELAY busy

  • Loading branch information...
commit cd910b8658e9f34370fcd52243f546ceaeaee7c5 1 parent 279a145
Sébastien Bourdeauducq authored June 14, 2013
54  software/videomixer/dvisamplerX.c
@@ -85,14 +85,30 @@ void dvisamplerX_print_status(void)
85 85
 		dvisamplerX_resdetection_vres_read());
86 86
 }
87 87
 
88  
-void dvisamplerX_calibrate_delays(void)
  88
+static int wait_idelays(void)
  89
+{
  90
+	int ev;
  91
+
  92
+	ev = 0;
  93
+	elapsed(&ev, 1);
  94
+	while(dvisamplerX_data0_cap_dly_busy_read()
  95
+	  || dvisamplerX_data1_cap_dly_busy_read()
  96
+	  || dvisamplerX_data2_cap_dly_busy_read()) {
  97
+		if(elapsed(&ev, identifier_frequency_read() >> 6) == 0) {
  98
+			printf("IDELAY busy timeout\n");
  99
+			return 0;
  100
+		}
  101
+	}
  102
+	return 1;
  103
+}
  104
+
  105
+int dvisamplerX_calibrate_delays(void)
89 106
 {
90 107
 	dvisamplerX_data0_cap_dly_ctl_write(DVISAMPLER_DELAY_CAL);
91 108
 	dvisamplerX_data1_cap_dly_ctl_write(DVISAMPLER_DELAY_CAL);
92 109
 	dvisamplerX_data2_cap_dly_ctl_write(DVISAMPLER_DELAY_CAL);
93  
-	while(dvisamplerX_data0_cap_dly_busy_read()
94  
-		|| dvisamplerX_data1_cap_dly_busy_read()
95  
-		|| dvisamplerX_data2_cap_dly_busy_read());
  110
+	if(!wait_idelays())
  111
+		return 0;
96 112
 	dvisamplerX_data0_cap_dly_ctl_write(DVISAMPLER_DELAY_RST);
97 113
 	dvisamplerX_data1_cap_dly_ctl_write(DVISAMPLER_DELAY_RST);
98 114
 	dvisamplerX_data2_cap_dly_ctl_write(DVISAMPLER_DELAY_RST);
@@ -100,20 +116,23 @@ void dvisamplerX_calibrate_delays(void)
100 116
 	dvisamplerX_data1_cap_phase_reset_write(1);
101 117
 	dvisamplerX_data2_cap_phase_reset_write(1);
102 118
 	dvisamplerX_d0 = dvisamplerX_d1 = dvisamplerX_d2 = 0;
  119
+	return 1;
103 120
 }
104 121
 
105  
-void dvisamplerX_adjust_phase(void)
  122
+int dvisamplerX_adjust_phase(void)
106 123
 {
107 124
 	switch(dvisamplerX_data0_cap_phase_read()) {
108 125
 		case DVISAMPLER_TOO_LATE:
109 126
 			dvisamplerX_data0_cap_dly_ctl_write(DVISAMPLER_DELAY_DEC);
110  
-			while(dvisamplerX_data0_cap_dly_busy_read());
  127
+			if(!wait_idelays())
  128
+				return 0;
111 129
 			dvisamplerX_d0--;
112 130
 			dvisamplerX_data0_cap_phase_reset_write(1);
113 131
 			break;
114 132
 		case DVISAMPLER_TOO_EARLY:
115 133
 			dvisamplerX_data0_cap_dly_ctl_write(DVISAMPLER_DELAY_INC);
116  
-			while(dvisamplerX_data0_cap_dly_busy_read());
  134
+			if(!wait_idelays())
  135
+				return 0;
117 136
 			dvisamplerX_d0++;
118 137
 			dvisamplerX_data0_cap_phase_reset_write(1);
119 138
 			break;
@@ -121,13 +140,15 @@ void dvisamplerX_adjust_phase(void)
121 140
 	switch(dvisamplerX_data1_cap_phase_read()) {
122 141
 		case DVISAMPLER_TOO_LATE:
123 142
 			dvisamplerX_data1_cap_dly_ctl_write(DVISAMPLER_DELAY_DEC);
124  
-			while(dvisamplerX_data1_cap_dly_busy_read());
  143
+			if(!wait_idelays())
  144
+				return 0;
125 145
 			dvisamplerX_d1--;
126 146
 			dvisamplerX_data1_cap_phase_reset_write(1);
127 147
 			break;
128 148
 		case DVISAMPLER_TOO_EARLY:
129 149
 			dvisamplerX_data1_cap_dly_ctl_write(DVISAMPLER_DELAY_INC);
130  
-			while(dvisamplerX_data1_cap_dly_busy_read());
  150
+			if(!wait_idelays())
  151
+				return 0;
131 152
 			dvisamplerX_d1++;
132 153
 			dvisamplerX_data1_cap_phase_reset_write(1);
133 154
 			break;
@@ -135,17 +156,20 @@ void dvisamplerX_adjust_phase(void)
135 156
 	switch(dvisamplerX_data2_cap_phase_read()) {
136 157
 		case DVISAMPLER_TOO_LATE:
137 158
 			dvisamplerX_data2_cap_dly_ctl_write(DVISAMPLER_DELAY_DEC);
138  
-			while(dvisamplerX_data2_cap_dly_busy_read());
  159
+			if(!wait_idelays())
  160
+				return 0;
139 161
 			dvisamplerX_d2--;
140 162
 			dvisamplerX_data2_cap_phase_reset_write(1);
141 163
 			break;
142 164
 		case DVISAMPLER_TOO_EARLY:
143 165
 			dvisamplerX_data2_cap_dly_ctl_write(DVISAMPLER_DELAY_INC);
144  
-			while(dvisamplerX_data2_cap_dly_busy_read());
  166
+			if(!wait_idelays())
  167
+				return 0;
145 168
 			dvisamplerX_d2++;
146 169
 			dvisamplerX_data2_cap_phase_reset_write(1);
147 170
 			break;
148 171
 	}
  172
+	return 1;
149 173
 }
150 174
 
151 175
 int dvisamplerX_init_phase(void)
@@ -157,8 +181,10 @@ int dvisamplerX_init_phase(void)
157 181
 		o_d0 = dvisamplerX_d0;
158 182
 		o_d1 = dvisamplerX_d1;
159 183
 		o_d2 = dvisamplerX_d2;
160  
-		for(j=0;j<1000;j++)
161  
-			dvisamplerX_adjust_phase();
  184
+		for(j=0;j<1000;j++) {
  185
+			if(!dvisamplerX_adjust_phase())
  186
+				return 0;
  187
+		}
162 188
 		if((abs(dvisamplerX_d0 - o_d0) < 4) && (abs(dvisamplerX_d1 - o_d1) < 4) && (abs(dvisamplerX_d2 - o_d2) < 4))
163 189
 			return 1;
164 190
 	}
@@ -180,7 +206,7 @@ int dvisamplerX_phase_startup(void)
180 206
 			printf("dvisamplerX: phase init OK\n");
181 207
 			return 1;
182 208
 		} else {
183  
-			printf("dvisamplerX: phase did not settle\n");
  209
+			printf("dvisamplerX: phase init failed\n");
184 210
 			if(attempts > 3) {
185 211
 				printf("dvisamplerX: giving up\n");
186 212
 				dvisamplerX_calibrate_delays();
4  software/videomixer/dvisamplerX.h
@@ -4,8 +4,8 @@
4 4
 void dvisamplerX_isr(void);
5 5
 void dvisamplerX_init_video(void);
6 6
 void dvisamplerX_print_status(void);
7  
-void dvisamplerX_calibrate_delays(void);
8  
-void dvisamplerX_adjust_phase(void);
  7
+int dvisamplerX_calibrate_delays(void);
  8
+int dvisamplerX_adjust_phase(void);
9 9
 int dvisamplerX_init_phase(void);
10 10
 int dvisamplerX_phase_startup(void);
11 11
 void dvisamplerX_service(void);

0 notes on commit cd910b8

Please sign in to comment.
Something went wrong with that request. Please try again.