From 1582bad2d65c9bae75ee3715b2737341b7fc63ee Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 13 Nov 2013 16:50:09 +0100 Subject: [PATCH] videomixer: filter PLL lock output --- software/libbase/time.c | 4 ++++ software/videomixer/dvisamplerX.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/software/libbase/time.c b/software/libbase/time.c index c1c2ea8b..c809dfd5 100644 --- a/software/libbase/time.c +++ b/software/libbase/time.c @@ -18,6 +18,10 @@ int elapsed(int *last_event, int period) timer0_update_value_write(1); t = timer0_reload_read() - timer0_value_read(); + if(period < 0) { + *last_event = t; + return 1; + } dt = t - *last_event; if(dt < 0) dt += timer0_reload_read(); diff --git a/software/videomixer/dvisamplerX.c b/software/videomixer/dvisamplerX.c index bdb486ac..c1570a8f 100644 --- a/software/videomixer/dvisamplerX.c +++ b/software/videomixer/dvisamplerX.c @@ -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) { + static int last_event; + if(dvisamplerX_connected) { if(!dvisamplerX_edid_hpd_notif_read()) { if(dvisamplerX_debug) @@ -246,8 +269,8 @@ void dvisamplerX_service(void) dvisamplerX_clocking_pll_reset_write(1); } else { if(dvisamplerX_locked) { - if(dvisamplerX_clocking_locked_read()) { - if(elapsed(&dvisamplerX_last_event, identifier_frequency_read()/2)) { + if(dvisamplerX_clocking_locked_filtered()) { + if(elapsed(&last_event, identifier_frequency_read()/2)) { dvisamplerX_adjust_phase(); if(dvisamplerX_debug) dvisamplerX_print_status(); @@ -258,7 +281,7 @@ void dvisamplerX_service(void) dvisamplerX_locked = 0; } } else { - if(dvisamplerX_clocking_locked_read()) { + if(dvisamplerX_clocking_locked_filtered()) { if(dvisamplerX_debug) printf("dvisamplerX: PLL locked\n"); dvisamplerX_phase_startup(); -- 2.30.2