From 53c66dafb031bef47949803d4ab6107b5747d1de Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Thu, 18 Jul 2019 02:15:33 +0200 Subject: [PATCH] fix(streams): Allow poll_stream to be NULL Signed-off-by: Rahix <rahix@rahix.de> --- epicardium/modules/stream.c | 14 ++++++++------ epicardium/modules/stream.h | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/epicardium/modules/stream.c b/epicardium/modules/stream.c index 63e63070..4b36cce7 100644 --- a/epicardium/modules/stream.c +++ b/epicardium/modules/stream.c @@ -52,20 +52,22 @@ int epic_stream_read(int sd, void *buf, size_t count) return -ENODEV; } - /* Poll the stream */ - int ret = stream->poll_stream(); - if (ret < 0) { - return ret; + /* Poll the stream, if a poll_stream function exists */ + if (stream->poll_stream != NULL) { + int ret = stream->poll_stream(); + if (ret < 0) { + return ret; + } } - /* Check buffer sizing */ + /* Check buffer size is a multiple of the data packet size */ if (count % stream->item_size != 0) { return -EINVAL; } size_t i; for (i = 0; i < count; i += stream->item_size) { - if (!xQueueReceive(stream->queue, buf + i, 10)) { + if (!xQueueReceive(stream->queue, buf + i, STREAM_QUEUE_WAIT)) { break; } } diff --git a/epicardium/modules/stream.h b/epicardium/modules/stream.h index 5cf0dcc0..5bbb327d 100644 --- a/epicardium/modules/stream.h +++ b/epicardium/modules/stream.h @@ -7,6 +7,8 @@ #include "FreeRTOS.h" #include "queue.h" +#define STREAM_QUEUE_WAIT pdMS_TO_TICKS(10) + /** * **Stream Descriptors**: * -- GitLab