videomixer: filter PLL lock output

This commit is contained in:
Sebastien Bourdeauducq 2013-11-13 16:50:09 +01:00
parent 1a28690fa0
commit 1582bad2d6
2 changed files with 31 additions and 4 deletions

View File

@ -18,6 +18,10 @@ int elapsed(int *last_event, int period)
timer0_update_value_write(1); timer0_update_value_write(1);
t = timer0_reload_read() - timer0_value_read(); t = timer0_reload_read() - timer0_value_read();
if(period < 0) {
*last_event = t;
return 1;
}
dt = t - *last_event; dt = t - *last_event;
if(dt < 0) if(dt < 0)
dt += timer0_reload_read(); dt += timer0_reload_read();

View File

@ -233,10 +233,33 @@ static void dvisamplerX_check_overflow(void)
} }
} }
static int dvisamplerX_last_event; static int dvisamplerX_clocking_locked_filtered(void)
{
static int lock_start_time;
static int lock_status;
if(dvisamplerX_clocking_locked_read()) {
switch(lock_status) {
case 0:
elapsed(&lock_start_time, -1);
lock_status = 1;
break;
case 1:
if(elapsed(&lock_start_time, identifier_frequency_read()/4))
lock_status = 2;
break;
case 2:
return 1;
}
} else
lock_status = 0;
return 0;
}
void dvisamplerX_service(void) void dvisamplerX_service(void)
{ {
static int last_event;
if(dvisamplerX_connected) { if(dvisamplerX_connected) {
if(!dvisamplerX_edid_hpd_notif_read()) { if(!dvisamplerX_edid_hpd_notif_read()) {
if(dvisamplerX_debug) if(dvisamplerX_debug)
@ -246,8 +269,8 @@ void dvisamplerX_service(void)
dvisamplerX_clocking_pll_reset_write(1); dvisamplerX_clocking_pll_reset_write(1);
} else { } else {
if(dvisamplerX_locked) { if(dvisamplerX_locked) {
if(dvisamplerX_clocking_locked_read()) { if(dvisamplerX_clocking_locked_filtered()) {
if(elapsed(&dvisamplerX_last_event, identifier_frequency_read()/2)) { if(elapsed(&last_event, identifier_frequency_read()/2)) {
dvisamplerX_adjust_phase(); dvisamplerX_adjust_phase();
if(dvisamplerX_debug) if(dvisamplerX_debug)
dvisamplerX_print_status(); dvisamplerX_print_status();
@ -258,7 +281,7 @@ void dvisamplerX_service(void)
dvisamplerX_locked = 0; dvisamplerX_locked = 0;
} }
} else { } else {
if(dvisamplerX_clocking_locked_read()) { if(dvisamplerX_clocking_locked_filtered()) {
if(dvisamplerX_debug) if(dvisamplerX_debug)
printf("dvisamplerX: PLL locked\n"); printf("dvisamplerX: PLL locked\n");
dvisamplerX_phase_startup(); dvisamplerX_phase_startup();