From d9973ea126e8eb0a740312e70b8b41efe12f1112 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 23 Dec 2015 14:21:42 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8636 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal_buffers.c | 62 +++++++++++++++------- ...M32F4xx-USB_CDC (OpenOCD, Flash and Run).launch | 4 +- testhal/STM32/STM32F4xx/USB_CDC/main.c | 9 ++-- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/os/hal/src/hal_buffers.c b/os/hal/src/hal_buffers.c index 7c309305f..a7cc5c79a 100644 --- a/os/hal/src/hal_buffers.c +++ b/os/hal/src/hal_buffers.c @@ -295,6 +295,7 @@ msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, systime_t timeout) { * - @a TIME_INFINITE no timeout. * . * @return The number of bytes effectively transferred. + * @retval 0 if a timeout occurred. * * @api */ @@ -316,20 +317,30 @@ size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp, /* This condition indicates that a new buffer must be acquired.*/ if (ibqp->ptr == NULL) { - systime_t next_timeout = deadline - osalOsGetSystemTimeX(); + msg_t msg; - /* Handling the case where the system time went past the deadline, - in this case next becomes a very high number because the system - time is an unsigned type.*/ - if (next_timeout > timeout) { - ibqp->accessed = false; - return MSG_TIMEOUT; + if (timeout == TIME_IMMEDIATE) { + msg = MSG_TIMEOUT; + } + else if (timeout == TIME_INFINITE) { + msg = ibqGetFullBufferTimeout(ibqp, timeout); + } + else { + systime_t next_timeout = deadline - osalOsGetSystemTimeX(); + + /* Handling the case where the system time went past the deadline, + in this case next becomes a very high number because the system + time is an unsigned type.*/ + if (next_timeout > timeout) { + msg = MSG_TIMEOUT; + } + else { + msg = ibqGetFullBufferTimeout(ibqp, next_timeout); + } } - - msg_t msg = ibqGetFullBufferTimeout(ibqp, next_timeout); if (msg != MSG_OK) { ibqp->accessed = false; - return msg; + return 0; } } @@ -611,6 +622,7 @@ msg_t obqPutTimeout(output_buffers_queue_t *obqp, uint8_t b, * - @a TIME_INFINITE no timeout. * . * @return The number of bytes effectively transferred. + * @retval 0 if a timeout occurred. * * @api */ @@ -632,20 +644,30 @@ size_t obqWriteTimeout(output_buffers_queue_t *obqp, const uint8_t *bp, /* This condition indicates that a new buffer must be acquired.*/ if (obqp->ptr == NULL) { - systime_t next_timeout = deadline - osalOsGetSystemTimeX(); + msg_t msg; - /* Handling the case where the system time went past the deadline, - in this case next becomes a very high number because the system - time is an unsigned type.*/ - if (next_timeout > timeout) { - obqp->accessed = false; - return MSG_TIMEOUT; + if (timeout == TIME_IMMEDIATE) { + msg = MSG_TIMEOUT; + } + else if (timeout == TIME_INFINITE) { + msg = obqGetEmptyBufferTimeout(obqp, timeout); + } + else { + systime_t next_timeout = deadline - osalOsGetSystemTimeX(); + + /* Handling the case where the system time went past the deadline, + in this case next becomes a very high number because the system + time is an unsigned type.*/ + if (next_timeout > timeout) { + msg = MSG_TIMEOUT; + } + else { + msg = obqGetEmptyBufferTimeout(obqp, next_timeout); + } } - - msg_t msg = obqGetEmptyBufferTimeout(obqp, next_timeout); if (msg != MSG_OK) { obqp->accessed = false; - return msg; + return 0; } } diff --git a/testhal/STM32/STM32F4xx/USB_CDC/debug/STM32F4xx-USB_CDC (OpenOCD, Flash and Run).launch b/testhal/STM32/STM32F4xx/USB_CDC/debug/STM32F4xx-USB_CDC (OpenOCD, Flash and Run).launch index a7cd1292e..4b14790e0 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC/debug/STM32F4xx-USB_CDC (OpenOCD, Flash and Run).launch +++ b/testhal/STM32/STM32F4xx/USB_CDC/debug/STM32F4xx-USB_CDC (OpenOCD, Flash and Run).launch @@ -33,13 +33,13 @@ - + - + diff --git a/testhal/STM32/STM32F4xx/USB_CDC/main.c b/testhal/STM32/STM32F4xx/USB_CDC/main.c index 49c5a1b98..4bcec83e3 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F4xx/USB_CDC/main.c @@ -84,6 +84,7 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { chThdWait(tp); } +/* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { static uint8_t buf[] = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" @@ -112,12 +113,12 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) { #if 1 /* Writing in stream mode.*/ - chSequentialStreamWrite(&SDU1, buf, sizeof buf - 1); + streamWrite(&SDU1, buf, sizeof buf - 1); #else /* Writing in buffer mode.*/ (void) obqGetEmptyBufferTimeout(&SDU1.obqueue, TIME_INFINITE); - memcpy(SDU1.obqueue.ptr, buf, 256); - obqPostFullBuffer(&SDU1.obqueue, 256); + memcpy(SDU1.obqueue.ptr, buf, SERIAL_USB_BUFFERS_SIZE); + obqPostFullBuffer(&SDU1.obqueue, SERIAL_USB_BUFFERS_SIZE); #endif } chprintf(chp, "\r\n\nstopped\r\n"); @@ -141,7 +142,7 @@ static const ShellConfig shell_cfg1 = { /*===========================================================================*/ /* - * Red LED blinker thread, times are in milliseconds. + * LED blinker thread, times are in milliseconds. */ static THD_WORKING_AREA(waThread1, 128); static THD_FUNCTION(Thread1, arg) { -- cgit v1.2.3