Input buffers queue working now.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8629 35acf78f-673a-0410-8e92-d51de3d6d3f4master
parent
380ffdcb4c
commit
7979de6953
|
@ -125,6 +125,15 @@ typedef io_buffers_queue_t output_buffers_queue_t;
|
||||||
/* Driver macros. */
|
/* Driver macros. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Computes the size of a buffers queue buffer size.
|
||||||
|
*
|
||||||
|
* @param[in] n sumber of buffers in the queue
|
||||||
|
* @param[in] size size of the buffers
|
||||||
|
*/
|
||||||
|
#define BQ_BUFFER_SIZE(n, size) \
|
||||||
|
(((size_t)(size) + sizeof (size_t)) * (size_t)(n))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Macro Functions
|
* @name Macro Functions
|
||||||
* @{
|
* @{
|
||||||
|
@ -151,6 +160,16 @@ typedef io_buffers_queue_t output_buffers_queue_t;
|
||||||
*/
|
*/
|
||||||
#define bqSpaceI(bqp) ((bqp)->bcounter)
|
#define bqSpaceI(bqp) ((bqp)->bcounter)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the queue application-defined link.
|
||||||
|
*
|
||||||
|
* @param[in] bqp pointer to an @p io_buffers_queue_t structure
|
||||||
|
* @return The application-defined link.
|
||||||
|
*
|
||||||
|
* @special
|
||||||
|
*/
|
||||||
|
#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 buffered queue is empty.
|
||||||
*
|
*
|
||||||
|
@ -187,6 +206,7 @@ extern "C" {
|
||||||
void ibqObjectInit(io_buffers_queue_t *ibqp, uint8_t *bp,
|
void ibqObjectInit(io_buffers_queue_t *ibqp, uint8_t *bp,
|
||||||
size_t size, size_t n,
|
size_t size, size_t n,
|
||||||
dbnotify_t infy, void *link);
|
dbnotify_t infy, void *link);
|
||||||
|
void ibqResetI(input_buffers_queue_t *ibqp);
|
||||||
uint8_t *ibqGetEmptyBufferI(input_buffers_queue_t *ibqp);
|
uint8_t *ibqGetEmptyBufferI(input_buffers_queue_t *ibqp);
|
||||||
void ibqPostBufferI(input_buffers_queue_t *ibqp, size_t size);
|
void ibqPostBufferI(input_buffers_queue_t *ibqp, size_t size);
|
||||||
msg_t ibqGetDataTimeoutI(input_buffers_queue_t *ibqp, systime_t timeout);
|
msg_t ibqGetDataTimeoutI(input_buffers_queue_t *ibqp, systime_t timeout);
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes an input double buffer object.
|
* @brief Initializes an input buffers queue object.
|
||||||
*
|
*
|
||||||
* @param[out] ibqp pointer to the @p io_buffers_queue_t object
|
* @param[out] ibqp pointer to the @p io_buffers_queue_t object
|
||||||
* @param[in] bp pointer to a memory area allocated for buffers
|
* @param[in] bp pointer to a memory area allocated for buffers
|
||||||
|
@ -65,6 +65,7 @@ void ibqObjectInit(input_buffers_queue_t *ibqp, uint8_t *bp,
|
||||||
|
|
||||||
osalDbgCheck((ibqp != NULL) && (bp != NULL) && (size >= sizeof(size_t) + 2));
|
osalDbgCheck((ibqp != NULL) && (bp != NULL) && (size >= sizeof(size_t) + 2));
|
||||||
|
|
||||||
|
osalThreadQueueObjectInit(&ibqp->waiting);
|
||||||
ibqp->bcounter = 0;
|
ibqp->bcounter = 0;
|
||||||
ibqp->brdptr = bp;
|
ibqp->brdptr = bp;
|
||||||
ibqp->bwrptr = bp;
|
ibqp->bwrptr = bp;
|
||||||
|
@ -78,6 +79,29 @@ void ibqObjectInit(input_buffers_queue_t *ibqp, uint8_t *bp,
|
||||||
ibqp->link = link;
|
ibqp->link = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resets an input buffers queue.
|
||||||
|
* @details All the data in the input buffers queue is erased and lost, any
|
||||||
|
* waiting thread is resumed with status @p MSG_RESET.
|
||||||
|
* @note A reset operation can be used by a low level driver in order to
|
||||||
|
* obtain immediate attention from the high level layers.
|
||||||
|
*
|
||||||
|
* @param[in] ibqp pointer to the @p input_buffers_queue_t object
|
||||||
|
*
|
||||||
|
* @iclass
|
||||||
|
*/
|
||||||
|
void ibqResetI(input_buffers_queue_t *ibqp) {
|
||||||
|
|
||||||
|
osalDbgCheckClassI();
|
||||||
|
|
||||||
|
ibqp->bcounter = 0;
|
||||||
|
ibqp->brdptr = ibqp->buffers;
|
||||||
|
ibqp->bwrptr = ibqp->buffers;
|
||||||
|
ibqp->ptr = NULL;
|
||||||
|
ibqp->top = NULL;
|
||||||
|
osalThreadDequeueAllI(&ibqp->waiting, MSG_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the next empty buffer from the queue.
|
* @brief Gets the next empty buffer from the queue.
|
||||||
* @note The function always returns the same buffer if called repeatedly.
|
* @note The function always returns the same buffer if called repeatedly.
|
||||||
|
@ -152,7 +176,7 @@ msg_t ibqGetDataTimeoutI(input_buffers_queue_t *ibqp, systime_t timeout) {
|
||||||
|
|
||||||
while (ibqIsEmptyI(ibqp)) {
|
while (ibqIsEmptyI(ibqp)) {
|
||||||
msg_t msg = osalThreadEnqueueTimeoutS(&ibqp->waiting, timeout);
|
msg_t msg = osalThreadEnqueueTimeoutS(&ibqp->waiting, timeout);
|
||||||
if (msg < Q_OK) {
|
if (msg < MSG_OK) {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,7 +323,8 @@ size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp,
|
||||||
memcpy(bp, ibqp->ptr, size);
|
memcpy(bp, ibqp->ptr, size);
|
||||||
osalSysLock();
|
osalSysLock();
|
||||||
|
|
||||||
/* Updating the pointers.*/
|
/* Updating the pointers and the counter.*/
|
||||||
|
r += size;
|
||||||
bp += size;
|
bp += size;
|
||||||
ibqp->ptr += size;
|
ibqp->ptr += size;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue