Remove framebuffer locking.

* Not needed anymore.
This commit is contained in:
iabdalkader 2016-02-09 01:11:25 +02:00
parent 74d084ee6b
commit dbd69a3a25
5 changed files with 16 additions and 59 deletions

View File

@ -8,14 +8,12 @@
*/
#ifndef __FRAMEBUFFER_H__
#define __FRAMEBUFFER_H__
#include "mutex.h"
extern char _fb_base;
static struct framebuffer {
int w,h;
int bpp;
int ready;
mutex_t lock;
int lock_tried;
int request;
uint8_t pixels[];
// Note all instances of fb point to the same memory address.
}*fb = (struct framebuffer *) &_fb_base;
@ -23,7 +21,7 @@ static struct framebuffer {
// The JPEG offset allows JPEG compression of the framebuffer without overwriting the pixels.
// The offset size may need to be adjusted depending on the quality, otherwise JPEG data may
// overwrite image pixels before they are compressed (see framebuffer.h)
#define FB_JPEG_OFFS_SIZE (1024)
#define FB_JPEG_OFFS_SIZE (1*1024)
// Use this macro to get a pointer to the free SRAM area located after the framebuffer.
// If JPEG is enabled, this macro returns (framebuffer->pixels + fb_width * fb_height).

View File

@ -160,9 +160,6 @@ void sensor_init0()
{
// Clear framebuffer
memset(fb, 0, sizeof(*fb));
// Init mutex
mutex_init(&fb->lock);
}
int sensor_init()
@ -261,12 +258,6 @@ int sensor_init()
return -4;
}
/* Init/re-init mutex */
mutex_init(&fb->lock);
/* Block usbdbg until the sensor is configured */
fb->ready=0;
/* All good! */
return 0;
}
@ -279,10 +270,6 @@ int sensor_reset()
sensor.framerate=0xFF;
sensor.gainceiling=0xFF;
mutex_lock(&fb->lock);
fb->ready=0;
mutex_unlock(&fb->lock);
/* Call sensor-specific reset function */
sensor.reset(&sensor);
@ -310,10 +297,6 @@ int sensor_set_pixformat(enum sensor_pixformat pixformat)
return 0;
}
mutex_lock(&fb->lock);
fb->ready = 0;
mutex_unlock(&fb->lock);
if (sensor.set_pixformat == NULL
|| sensor.set_pixformat(&sensor, pixformat) != 0) {
/* operation not supported */
@ -353,10 +336,6 @@ int sensor_set_framesize(enum sensor_framesize framesize)
return 0;
}
mutex_lock(&fb->lock);
fb->ready = 0;
mutex_unlock(&fb->lock);
/* call the sensor specific function */
if (sensor.set_framesize == NULL
|| sensor.set_framesize(&sensor, framesize) != 0) {
@ -500,8 +479,10 @@ int sensor_snapshot(struct image *image)
volatile uint16_t length;
uint32_t snapshot_start;
// Compress the framebuffer for the IDE
if (sensor.pixformat != PIXFORMAT_JPEG) {
// Compress the framebuffer for the IDE only for non-JPEG
// images and only if the IDE has requested a framebuffer.
// Note: This doesn't run unless the camera is connected to PC.
if (fb->request && sensor.pixformat != PIXFORMAT_JPEG) {
// The framebuffer is compressed in place.
// Assuming we have at least 128KBs of SRAM.
image_t src = {.w=fb->w, .h=fb->h, .bpp=fb->bpp, .pixels=fb->pixels+FB_JPEG_OFFS_SIZE};
@ -520,7 +501,7 @@ int sensor_snapshot(struct image *image)
// after all the image processing code has run (which possibily draws over the framebuffer).
// This fakes double buffering without having to allocate a second buffer and allows us to
// re-use the framebuffer for software JPEG compression.
while (fb->ready && fb->lock_tried) {
while (fb->ready && fb->request) {
// Note: This delay is only executed when the USB debug is active.
systick_sleep(2);
}
@ -540,9 +521,6 @@ int sensor_snapshot(struct image *image)
// Clear line counter
line = 0;
// Lock framebuffer mutex
mutex_lock(&fb->lock);
// Snapshot start tick
snapshot_start = HAL_GetTick();
@ -560,8 +538,7 @@ int sensor_snapshot(struct image *image)
while ((DCMI->CR & DCMI_CR_CAPTURE) != 0) {
if ((HAL_GetTick() - snapshot_start) >= 3000) {
// Sensor timeout, most likely a HW issue.
// unlock fb mutex and abort the DMA request
mutex_unlock(&fb->lock);
// Abort the DMA request.
HAL_DMA_Abort(&DMAHandle);
return -1;
}
@ -596,7 +573,5 @@ int sensor_snapshot(struct image *image)
}
}
// Unlock framebuffer mutex
mutex_unlock(&fb->lock);
return 0;
}

View File

@ -92,18 +92,13 @@ void usbdbg_data_in(void *buffer, int length)
}
case USBDBG_FRAME_SIZE:
memcpy(buffer, fb, length);
cmd = USBDBG_NONE;
break;
case USBDBG_FRAME_LOCK:
// try to lock FB, return fb hdr if locked
if (fb->ready && mutex_try_lock(&fb->lock)) {
fb->lock_tried = 0;
if (fb->ready) {
// Frame ready return header
fb->request = 0;
memcpy(buffer, fb, length);
} else {
// no valid frame or failed to lock, return 0
fb->lock_tried = 1;
// Frame not ready return 0
fb->request = 1;
((uint32_t*)buffer)[0] = 0;
}
cmd = USBDBG_NONE;
@ -114,7 +109,7 @@ void usbdbg_data_in(void *buffer, int length)
memcpy(buffer, fb->pixels+xfer_bytes, length);
xfer_bytes += length;
if (xfer_bytes == xfer_length) {
mutex_unlock(&fb->lock);
fb->request = 0;
cmd = USBDBG_NONE;
}
}
@ -225,11 +220,6 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t length)
xfer_length = length;
break;
case USBDBG_FRAME_LOCK:
xfer_bytes = 0;
xfer_length = length;
break;
case USBDBG_FRAME_UPDATE:
sensor_snapshot(NULL);
cmd = USBDBG_NONE;

View File

@ -18,7 +18,7 @@
* the IDE will Not connect if the major version number is different.
*/
#define FIRMWARE_VERSION_MAJOR (1)
#define FIRMWARE_VERSION_MINOR (2)
#define FIRMWARE_VERSION_MINOR (3)
#define FIRMWARE_VERSION_PATCH (0)
/**
@ -34,7 +34,6 @@ enum usbdbg_cmd {
USBDBG_FW_VERSION =0x80,
USBDBG_FRAME_SIZE =0x81,
USBDBG_FRAME_DUMP =0x82,
USBDBG_FRAME_LOCK =0x83,
USBDBG_FRAME_UPDATE =0x04,
USBDBG_SCRIPT_EXEC =0x05,
USBDBG_SCRIPT_STOP =0x06,

View File

@ -20,7 +20,6 @@ __USBDBG_CMD = 48
__USBDBG_FW_VERSION = 0x80
__USBDBG_FRAME_SIZE = 0x81
__USBDBG_FRAME_DUMP = 0x82
__USBDBG_FRAME_LOCK = 0x83
__USBDBG_FRAME_UPDATE = 0x04
__USBDBG_SCRIPT_EXEC = 0x05
__USBDBG_SCRIPT_STOP = 0x06
@ -50,12 +49,8 @@ def fb_size():
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_FRAME_SIZE, __FB_HDR_SIZE))
return struct.unpack("III", __serial.read(12))
def fb_lock():
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_FRAME_LOCK, __FB_HDR_SIZE))
return struct.unpack("III", __serial.read(12))
def fb_dump():
size = fb_lock()
size = fb_size()
if (not size[0]):
# frame not ready