From 2f7be482b19d34ec9bc86ce31d589430e2737e29 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Mon, 21 Dec 2015 16:49:54 +0000 Subject: Changes to Serial_USB, unfinished. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8630 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/hal_buffers.h | 56 +++++++++++++++++++++++++++++++++++++------- os/hal/include/serial_usb.h | 20 ++++++++++++---- 2 files changed, 63 insertions(+), 13 deletions(-) (limited to 'os/hal/include') diff --git a/os/hal/include/hal_buffers.h b/os/hal/include/hal_buffers.h index a256f02e2..e5d5fa7b9 100644 --- a/os/hal/include/hal_buffers.h +++ b/os/hal/include/hal_buffers.h @@ -51,7 +51,7 @@ typedef struct io_buffers_queue io_buffers_queue_t; * * @param[in] iodbp the buffers queue pointer */ -typedef void (*dbnotify_t)(io_buffers_queue_t *bqp); +typedef void (*bqnotify_t)(io_buffers_queue_t *bqp); /** * @brief Structure of a generic buffers queue. @@ -104,7 +104,7 @@ struct io_buffers_queue { /** * @brief Data notification callback. */ - dbnotify_t notify; + bqnotify_t notify; /** * @brief Application defined field. */ @@ -171,7 +171,7 @@ typedef io_buffers_queue_t output_buffers_queue_t; #define bqGetLinkX(bqp) ((bqp)->link) /** - * @brief Evaluates to @p TRUE if the specified input buffered queue is empty. + * @brief Evaluates to @p TRUE if the specified input buffers queue is empty. * * @param[in] ibqp pointer to an @p input_buffers_queue_t structure * @return The queue status. @@ -183,7 +183,7 @@ typedef io_buffers_queue_t output_buffers_queue_t; #define ibqIsEmptyI(ibqp) ((bool)(bqSpaceI(ibqp) == 0U)) /** - * @brief Evaluates to @p TRUE if the specified input buffered queue is full. + * @brief Evaluates to @p TRUE if the specified input buffers queue is full. * * @param[in] ibqp pointer to an @p input_buffers_queue_t structure * @return The queue status. @@ -194,6 +194,31 @@ typedef io_buffers_queue_t output_buffers_queue_t; */ #define ibqIsFullI(ibqp) ((bool)(((ibqp)->bwrptr == (ibqp)->brdptr) && \ ((ibqp)->bcounter != 0U))) + +/** + * @brief Evaluates to @p true if the specified output buffers queue is empty. + * + * @param[in] obqp pointer to an @p output_buffers_queue_t structure + * @return The queue status. + * @retval false if the queue is not empty. + * @retval true if the queue is empty. + * + * @iclass + */ +#define obqIsEmptyI(oqp) ((bool)(((obqp)->bwrptr == (obqp)->brdptr) && \ + ((obqp)->bcounter != 0U))) + +/** + * @brief Evaluates to @p true if the specified output buffers queue is full. + * + * @param[in] obqp pointer to an @p output_buffers_queue_t structure + * @return The queue status. + * @retval false if the queue is not full. + * @retval true if the queue is full. + * + * @iclass + */ +#define obqIsFullI(obqp) ((bool)(bqSpaceI(obqp) == 0U)) /** @} */ /*===========================================================================*/ @@ -205,15 +230,30 @@ extern "C" { #endif void ibqObjectInit(io_buffers_queue_t *ibqp, uint8_t *bp, size_t size, size_t n, - dbnotify_t infy, void *link); + bqnotify_t infy, void *link); void ibqResetI(input_buffers_queue_t *ibqp); uint8_t *ibqGetEmptyBufferI(input_buffers_queue_t *ibqp); - void ibqPostBufferI(input_buffers_queue_t *ibqp, size_t size); - msg_t ibqGetDataTimeoutI(input_buffers_queue_t *ibqp, systime_t timeout); - void ibqReleaseDataI(input_buffers_queue_t *ibqp); + void ibqPostFullBufferI(input_buffers_queue_t *ibqp, size_t size); + msg_t ibqGetFullBufferTimeoutS(input_buffers_queue_t *ibqp, + systime_t timeout); + void ibqReleaseEmptyBufferI(input_buffers_queue_t *ibqp); msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, systime_t timeout); size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp, size_t n, systime_t timeout); + void obqObjectInit(output_buffers_queue_t *obqp, uint8_t *bp, + size_t size, size_t n, + bqnotify_t onfy, void *link); + void obqResetI(output_buffers_queue_t *obqp); + uint8_t *obqGetFullBufferI(output_buffers_queue_t *obqp, + size_t *sizep); + void obqReleaseEmptyBufferI(output_buffers_queue_t *obqp); + msg_t obqGetEmptyBufferTimeoutS(output_buffers_queue_t *obqp, + systime_t timeout); + void obqPostFullBufferI(output_buffers_queue_t *obqp, size_t size); + msg_t obqPutTimeout(output_buffers_queue_t *obqp, uint8_t b, + systime_t timeout); + size_t obqWriteTimeout(output_buffers_queue_t *obqp, const uint8_t *bp, + size_t n, systime_t timeout); #ifdef __cplusplus } #endif diff --git a/os/hal/include/serial_usb.h b/os/hal/include/serial_usb.h index 22e873ea1..fca8d56ea 100644 --- a/os/hal/include/serial_usb.h +++ b/os/hal/include/serial_usb.h @@ -121,6 +121,14 @@ #if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__) #define SERIAL_USB_BUFFERS_SIZE 256 #endif + +/** + * @brief Serial over USB number of buffers. + * @note The default is 2 buffers. + */ +#if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__) +#define SERIAL_USB_BUFFERS_NUMBER 2 +#endif /** @} */ /*===========================================================================*/ @@ -192,14 +200,16 @@ typedef struct { _base_asynchronous_channel_data \ /* Driver state.*/ \ sdustate_t state; \ - /* Input queue.*/ \ - input_queue_t iqueue; \ + /* Input buffers queue.*/ \ + input_buffers_queue_t ibqueue; \ /* Output queue.*/ \ - output_queue_t oqueue; \ + output_buffers_queue_t obqueue; \ /* Input buffer.*/ \ - uint8_t ib[SERIAL_USB_BUFFERS_SIZE]; \ + uint8_t ib[BQ_BUFFER_SIZE(SERIAL_USB_BUFFERS_NUMBER, \ + SERIAL_USB_BUFFERS_SIZE)]; \ /* Output buffer.*/ \ - uint8_t ob[SERIAL_USB_BUFFERS_SIZE]; \ + uint8_t ob[BQ_BUFFER_SIZE(SERIAL_USB_BUFFERS_NUMBER, \ + SERIAL_USB_BUFFERS_SIZE)]; \ /* End of the mandatory fields.*/ \ /* Current configuration data.*/ \ const SerialUSBConfig *config; -- cgit v1.2.3