Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

software/dvisampler: periodically reset PLL until locked + recalibrat…

…e IO every second
  • Loading branch information...
commit 6f11ddb079dd2aa072f2446708d71fa5fae34750 1 parent 546aa76
Sébastien Bourdeauducq authored May 09, 2013
30  software/videomixer/dvisamplerX.c
@@ -64,7 +64,7 @@ static int dvisamplerX_d0, dvisamplerX_d1, dvisamplerX_d2;
64 64
 
65 65
 void dvisamplerX_print_status(void)
66 66
 {
67  
-	printf("dvisamplerX ph:%4d %4d %4d // charsync:%d%d%d [%d %d %d] // chansync:%d // res:%dx%d\n",
  67
+	printf("dvisamplerX: ph:%4d %4d %4d // charsync:%d%d%d [%d %d %d] // chansync:%d // res:%dx%d\n",
68 68
 		dvisamplerX_d0, dvisamplerX_d1, dvisamplerX_d2,
69 69
 		dvisamplerX_data0_charsync_char_synced_read(),
70 70
 		dvisamplerX_data1_charsync_char_synced_read(),
@@ -153,14 +153,32 @@ int dvisamplerX_init_phase(void)
153 153
 
154 154
 static int dvisamplerX_locked;
155 155
 
  156
+static int elapsed(int period)
  157
+{
  158
+	static int last_event;
  159
+	int t, dt;
  160
+
  161
+	t = timer0_reload_read() - timer0_value_read(); // TODO: atomic read
  162
+	dt = t - last_event;
  163
+	if(dt < 0)
  164
+		dt += timer0_reload_read();
  165
+	if((dt > period) || (dt < 0)) {
  166
+		last_event = t;
  167
+		return 1;
  168
+	} else
  169
+		return 0;
  170
+}
  171
+
156 172
 void dvisamplerX_service(void)
157 173
 {
158 174
 	int ret;
159 175
 
160 176
 	if(dvisamplerX_locked) {
161 177
 		if(dvisamplerX_clocking_locked_read()) {
162  
-			dvisamplerX_adjust_phase();
163  
-			dvisamplerX_print_status();
  178
+			if(elapsed(identifier_frequency_read())) {
  179
+				dvisamplerX_adjust_phase();
  180
+				dvisamplerX_print_status();
  181
+			}
164 182
 		} else {
165 183
 			printf("dvisamplerX: lost PLL lock\n");
166 184
 			dvisamplerX_locked = 0;
@@ -177,6 +195,12 @@ void dvisamplerX_service(void)
177 195
 				printf("dvisamplerX: phase did not settle\n");
178 196
 			dvisamplerX_print_status();
179 197
 			dvisamplerX_locked = 1;
  198
+		} else {
  199
+			if(elapsed(identifier_frequency_read()/4)) {
  200
+				dvisamplerX_clocking_pll_reset_write(1);
  201
+				while(!elapsed(identifier_frequency_read()/16));
  202
+				dvisamplerX_clocking_pll_reset_write(0);
  203
+			}
180 204
 		}
181 205
 	}
182 206
 }
3  software/videomixer/main.c
@@ -17,6 +17,9 @@ int main(void)
17 17
 	
18 18
 	puts("Minimal video mixer software built "__DATE__" "__TIME__"\n");
19 19
 	
  20
+	timer0_reload_write(2*identifier_frequency_read());
  21
+	timer0_en_write(1);
  22
+
20 23
 	dvisampler0_init_video();
21 24
 	fb_enable_write(1);
22 25
 	while(1) dvisampler0_service();

0 notes on commit 6f11ddb

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