videomixer: filter PLL lock output
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Wed, 13 Nov 2013 15:50:09 +0000 (16:50 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Wed, 13 Nov 2013 15:50:09 +0000 (16:50 +0100)
software/libbase/time.c
software/videomixer/dvisamplerX.c

index c1c2ea8b8beec806ab8903dacd28bd26bbb85d48..c809dfd54a72e9b223930deee696e8bea2346bb9 100644 (file)
@@ -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();
index bdb486ac38fd22add315a4f54116fe2cdd926ddf..c1570a8fc41c449e3e05f472e1369a3c0cd303f2 100644 (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)
 {
+       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();