From 899ec65507d6f36eb8d804fabefd047e7e49db4d Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 31 Oct 2014 13:57:17 +0200 Subject: [PATCH] Add delay if IDE tried to lock FB * Fix #27 --- src/omv/framebuffer.h | 4 ++-- src/omv/sensor.c | 4 ++++ src/omv/usbdbg.c | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/omv/framebuffer.h b/src/omv/framebuffer.h index 9124b1dbc..9308f3473 100644 --- a/src/omv/framebuffer.h +++ b/src/omv/framebuffer.h @@ -11,11 +11,11 @@ #include "mutex.h" extern char _fb_base; static struct framebuffer { - int w; - int h; + int w,h; int bpp; int ready; mutex_t lock; + int lock_tried; uint8_t pixels[]; // Note all instances of fb point to the same memory address. }*fb = (struct framebuffer *) &_fb_base; diff --git a/src/omv/sensor.c b/src/omv/sensor.c index cf631f370..4e686f93a 100644 --- a/src/omv/sensor.c +++ b/src/omv/sensor.c @@ -336,6 +336,10 @@ int sensor_snapshot(struct image *image) /* unlock framebuffer mutex */ mutex_unlock(&fb->lock); + + if (fb->lock_tried) { + systick_sleep(1); + } return 0; } diff --git a/src/omv/usbdbg.c b/src/omv/usbdbg.c index 9ee41ee23..90154dd43 100644 --- a/src/omv/usbdbg.c +++ b/src/omv/usbdbg.c @@ -44,6 +44,7 @@ void usbdbg_clr_script() { script_ready =0; vstr_reset(&script); + fb->lock_tried=0; mutex_unlock(&fb->lock); } @@ -128,7 +129,9 @@ void usbdbg_control(void *buffer, uint8_t request, uint16_t length) ((uint8_t*)buffer)[0] = 0; } else { // try to lock FB, return 1 if locked - ((uint8_t*)buffer)[0] = mutex_try_lock(&fb->lock); + int locked = mutex_try_lock(&fb->lock); + fb->lock_tried = !locked; + ((uint8_t*)buffer)[0] = locked; } break;