Updated queues.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6112 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
8576e8da6a
commit
7b51712449
|
@ -346,16 +346,16 @@ typedef GenericQueue OutputQueue;
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void iqInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy,
|
||||
void *link);
|
||||
void iqObjectInit(InputQueue *iqp, uint8_t *bp, size_t size,
|
||||
qnotify_t infy, void *link);
|
||||
void iqResetI(InputQueue *iqp);
|
||||
msg_t iqPutI(InputQueue *iqp, uint8_t b);
|
||||
msg_t iqGetTimeout(InputQueue *iqp, systime_t time);
|
||||
size_t iqReadTimeout(InputQueue *iqp, uint8_t *bp,
|
||||
size_t n, systime_t time);
|
||||
|
||||
void oqInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy,
|
||||
void *link);
|
||||
void oqObjectInit(OutputQueue *oqp, uint8_t *bp, size_t size,
|
||||
qnotify_t onfy, void *link);
|
||||
void oqResetI(OutputQueue *oqp);
|
||||
msg_t oqPutTimeout(OutputQueue *oqp, uint8_t b, systime_t time);
|
||||
msg_t oqGetI(OutputQueue *oqp);
|
||||
|
@ -383,12 +383,14 @@ extern "C" {
|
|||
#define oqIsEmptyI(oqp) chOQIsEmptyI(oqp)
|
||||
#define oqIsFullI(oqp) chOQIsFullI(oqp)
|
||||
#define oqPut(oqp, b) chOQPut(oqp, b)
|
||||
#define iqInit(iqp, bp, size, infy, link) chIQInit(iqp, bp, size, infy, link)
|
||||
#define iqObjectInit(iqp, bp, size, infy, link) \
|
||||
chIQObjectInit(iqp, bp, size, infy, link)
|
||||
#define iqResetI(iqp) chIQResetI(iqp)
|
||||
#define iqPutI(iqp, b) chIQPutI(iqp, b)
|
||||
#define iqGetTimeout(iqp, time) chIQGetTimeout(iqp, time)
|
||||
#define iqReadTimeout(iqp, bp, n, time) chIQReadTimeout(iqp, bp, n, time)
|
||||
#define oqInit(oqp, bp, size, onfy, link) chOQInit(oqp, bp, size, onfy, link)
|
||||
#define oqObjectInit(oqp, bp, size, onfy, link) \
|
||||
chOQObjectInit(oqp, bp, size, onfy, link)
|
||||
#define oqResetI(oqp) chOQResetI(oqp)
|
||||
#define oqPutTimeout(oqp, b, time) chOQPutTimeout(oqp, b, time)
|
||||
#define oqGetI(oqp) chOQGetI(oqp)
|
||||
|
|
|
@ -190,7 +190,7 @@ static void serve_interrupt(SerialDriver *sdp) {
|
|||
}
|
||||
|
||||
#if STM32_SERIAL_USE_USART1 || defined(__DOXYGEN__)
|
||||
static void notify1(GenericQueue *qp) {
|
||||
static void notify1(io_queue_t *qp) {
|
||||
|
||||
(void)qp;
|
||||
USART1->CR1 |= USART_CR1_TXEIE;
|
||||
|
@ -198,7 +198,7 @@ static void notify1(GenericQueue *qp) {
|
|||
#endif
|
||||
|
||||
#if STM32_SERIAL_USE_USART2 || defined(__DOXYGEN__)
|
||||
static void notify2(GenericQueue *qp) {
|
||||
static void notify2(io_queue_t *qp) {
|
||||
|
||||
(void)qp;
|
||||
USART2->CR1 |= USART_CR1_TXEIE;
|
||||
|
@ -206,7 +206,7 @@ static void notify2(GenericQueue *qp) {
|
|||
#endif
|
||||
|
||||
#if STM32_SERIAL_USE_USART3 || defined(__DOXYGEN__)
|
||||
static void notify3(GenericQueue *qp) {
|
||||
static void notify3(io_queue_t *qp) {
|
||||
|
||||
(void)qp;
|
||||
USART3->CR1 |= USART_CR1_TXEIE;
|
||||
|
@ -214,7 +214,7 @@ static void notify3(GenericQueue *qp) {
|
|||
#endif
|
||||
|
||||
#if STM32_SERIAL_USE_UART4 || defined(__DOXYGEN__)
|
||||
static void notify4(GenericQueue *qp) {
|
||||
static void notify4(io_queue_t *qp) {
|
||||
|
||||
(void)qp;
|
||||
UART4->CR1 |= USART_CR1_TXEIE;
|
||||
|
@ -222,7 +222,7 @@ static void notify4(GenericQueue *qp) {
|
|||
#endif
|
||||
|
||||
#if STM32_SERIAL_USE_UART5 || defined(__DOXYGEN__)
|
||||
static void notify5(GenericQueue *qp) {
|
||||
static void notify5(io_queue_t *qp) {
|
||||
|
||||
(void)qp;
|
||||
UART5->CR1 |= USART_CR1_TXEIE;
|
||||
|
@ -230,7 +230,7 @@ static void notify5(GenericQueue *qp) {
|
|||
#endif
|
||||
|
||||
#if STM32_SERIAL_USE_USART6 || defined(__DOXYGEN__)
|
||||
static void notify6(GenericQueue *qp) {
|
||||
static void notify6(io_queue_t *qp) {
|
||||
|
||||
(void)qp;
|
||||
USART6->CR1 |= USART_CR1_TXEIE;
|
||||
|
|
|
@ -240,9 +240,9 @@ typedef struct {
|
|||
/* Driver state.*/ \
|
||||
sdstate_t state; \
|
||||
/* Input queue.*/ \
|
||||
InputQueue iqueue; \
|
||||
input_queue_t iqueue; \
|
||||
/* Output queue.*/ \
|
||||
OutputQueue oqueue; \
|
||||
output_queue_t oqueue; \
|
||||
/* Input circular buffer.*/ \
|
||||
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
|
||||
/* Output circular buffer.*/ \
|
||||
|
|
|
@ -59,8 +59,8 @@
|
|||
*
|
||||
* @init
|
||||
*/
|
||||
void iqInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy,
|
||||
void *link) {
|
||||
void iqObjectInit(InputQueue *iqp, uint8_t *bp, size_t size,
|
||||
qnotify_t infy, void *link) {
|
||||
|
||||
osalQueueObjectInit(&iqp->q_waiting);
|
||||
iqp->q_counter = 0;
|
||||
|
@ -237,8 +237,8 @@ size_t iqReadTimeout(InputQueue *iqp, uint8_t *bp,
|
|||
*
|
||||
* @init
|
||||
*/
|
||||
void oqInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy,
|
||||
void *link) {
|
||||
void oqObjectInit(OutputQueue *oqp, uint8_t *bp, size_t size,
|
||||
qnotify_t onfy, void *link) {
|
||||
|
||||
osalQueueObjectInit(&oqp->q_waiting);
|
||||
oqp->q_counter = size;
|
||||
|
|
|
@ -134,8 +134,8 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) {
|
|||
sdp->vmt = &vmt;
|
||||
osalEventObjectInit(&sdp->event);
|
||||
sdp->state = SD_STOP;
|
||||
iqInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify, sdp);
|
||||
oqInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify, sdp);
|
||||
iqObjectInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify, sdp);
|
||||
oqObjectInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify, sdp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
|
||||
#if CH_CFG_USE_QUEUES || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name Queue functions returned status value
|
||||
* @{
|
||||
|
@ -42,13 +46,25 @@
|
|||
#define Q_FULL -4 /**< @brief Queue full, */
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Type of a generic I/O queue structure.
|
||||
*/
|
||||
typedef struct GenericQueue GenericQueue;
|
||||
typedef struct io_queue io_queue_t;
|
||||
|
||||
/** @brief Queue notification callback type.*/
|
||||
typedef void (*qnotify_t)(GenericQueue *qp);
|
||||
typedef void (*qnotify_t)(io_queue_t *qp);
|
||||
|
||||
/**
|
||||
* @brief Generic I/O queue structure.
|
||||
|
@ -59,7 +75,7 @@ typedef void (*qnotify_t)(GenericQueue *qp);
|
|||
* lock zone (see <b>I-Locked</b> and <b>S-Locked</b> states in
|
||||
* @ref system_states) and is non-blocking.
|
||||
*/
|
||||
struct GenericQueue {
|
||||
struct io_queue {
|
||||
threads_queue_t q_waiting; /**< @brief Queue of waiting threads. */
|
||||
size_t q_counter; /**< @brief Resources counter. */
|
||||
uint8_t *q_buffer; /**< @brief Pointer to the queue buffer.*/
|
||||
|
@ -72,45 +88,7 @@ struct GenericQueue {
|
|||
};
|
||||
|
||||
/**
|
||||
* @name Macro Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Returns the queue's buffer size.
|
||||
*
|
||||
* @param[in] qp pointer to a @p GenericQueue structure.
|
||||
* @return The buffer size.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chQSizeI(qp) ((size_t)((qp)->q_top - (qp)->q_buffer))
|
||||
|
||||
/**
|
||||
* @brief Queue space.
|
||||
* @details Returns the used space if used on an input queue or the empty
|
||||
* space if used on an output queue.
|
||||
*
|
||||
* @param[in] qp pointer to a @p GenericQueue structure.
|
||||
* @return The buffer space.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chQSpaceI(qp) ((qp)->q_counter)
|
||||
|
||||
/**
|
||||
* @brief Returns the queue application-defined link.
|
||||
* @note This function can be called in any context.
|
||||
*
|
||||
* @param[in] qp pointer to a @p GenericQueue structure.
|
||||
* @return The application-defined link.
|
||||
*
|
||||
* @special
|
||||
*/
|
||||
#define chQGetLink(qp) ((qp)->q_link)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @extends GenericQueue
|
||||
* @extends io_queue_t
|
||||
*
|
||||
* @brief Type of an input queue structure.
|
||||
* @details This structure represents a generic asymmetrical input queue.
|
||||
|
@ -120,73 +98,24 @@ struct GenericQueue {
|
|||
* Reading the queue can be a blocking operation and is supposed to
|
||||
* be performed by a system thread.
|
||||
*/
|
||||
typedef GenericQueue InputQueue;
|
||||
typedef io_queue_t input_queue_t;
|
||||
|
||||
/**
|
||||
* @name Macro Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Returns the filled space into an input queue.
|
||||
* @extends io_queue_t
|
||||
*
|
||||
* @param[in] iqp pointer to an @p InputQueue structure
|
||||
* @return The number of full bytes in the queue.
|
||||
* @retval 0 if the queue is empty.
|
||||
*
|
||||
* @iclass
|
||||
* @brief Type of an output queue structure.
|
||||
* @details This structure represents a generic asymmetrical output queue.
|
||||
* Reading from the queue is non-blocking and can be performed from
|
||||
* interrupt handlers or from within a kernel lock zone (see
|
||||
* <b>I-Locked</b> and <b>S-Locked</b> states in @ref system_states).
|
||||
* Writing the queue can be a blocking operation and is supposed to
|
||||
* be performed by a system thread.
|
||||
*/
|
||||
#define chIQGetFullI(iqp) chQSpaceI(iqp)
|
||||
typedef io_queue_t output_queue_t;
|
||||
|
||||
/**
|
||||
* @brief Returns the empty space into an input queue.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p InputQueue structure
|
||||
* @return The number of empty bytes in the queue.
|
||||
* @retval 0 if the queue is full.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chIQGetEmptyI(iqp) (chQSizeI(iqp) - chQSpaceI(iqp))
|
||||
|
||||
/**
|
||||
* @brief Evaluates to @p true if the specified input queue is empty.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p InputQueue structure.
|
||||
* @return The queue status.
|
||||
* @retval false if the queue is not empty.
|
||||
* @retval true if the queue is empty.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chIQIsEmptyI(iqp) ((bool_t)(chQSpaceI(iqp) <= 0))
|
||||
|
||||
/**
|
||||
* @brief Evaluates to @p true if the specified input queue is full.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p InputQueue structure.
|
||||
* @return The queue status.
|
||||
* @retval false if the queue is not full.
|
||||
* @retval true if the queue is full.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chIQIsFullI(iqp) ((bool_t)(((iqp)->q_wrptr == (iqp)->q_rdptr) && \
|
||||
((iqp)->q_counter != 0)))
|
||||
|
||||
/**
|
||||
* @brief Input queue read.
|
||||
* @details This function reads a byte value from an input queue. If the queue
|
||||
* is empty then the calling thread is suspended until a byte arrives
|
||||
* in the queue.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p InputQueue structure
|
||||
* @return A byte value from the queue.
|
||||
* @retval Q_RESET if the queue has been reset.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define chIQGet(iqp) chIQGetTimeout(iqp, TIME_INFINITE)
|
||||
/** @} */
|
||||
/*===========================================================================*/
|
||||
/* Module macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Data part of a static input queue initializer.
|
||||
|
@ -222,88 +151,7 @@ typedef GenericQueue InputQueue;
|
|||
* @param[in] link application defined pointer
|
||||
*/
|
||||
#define INPUTQUEUE_DECL(name, buffer, size, inotify, link) \
|
||||
InputQueue name = _INPUTQUEUE_DATA(name, buffer, size, inotify, link)
|
||||
|
||||
/**
|
||||
* @extends GenericQueue
|
||||
*
|
||||
* @brief Type of an output queue structure.
|
||||
* @details This structure represents a generic asymmetrical output queue.
|
||||
* Reading from the queue is non-blocking and can be performed from
|
||||
* interrupt handlers or from within a kernel lock zone (see
|
||||
* <b>I-Locked</b> and <b>S-Locked</b> states in @ref system_states).
|
||||
* Writing the queue can be a blocking operation and is supposed to
|
||||
* be performed by a system thread.
|
||||
*/
|
||||
typedef GenericQueue OutputQueue;
|
||||
|
||||
/**
|
||||
* @name Macro Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Returns the filled space into an output queue.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p OutputQueue structure
|
||||
* @return The number of full bytes in the queue.
|
||||
* @retval 0 if the queue is empty.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chOQGetFullI(oqp) (chQSizeI(oqp) - chQSpaceI(oqp))
|
||||
|
||||
/**
|
||||
* @brief Returns the empty space into an output queue.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p OutputQueue structure
|
||||
* @return The number of empty bytes in the queue.
|
||||
* @retval 0 if the queue is full.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chOQGetEmptyI(oqp) chQSpaceI(oqp)
|
||||
|
||||
/**
|
||||
* @brief Evaluates to @p true if the specified output queue is empty.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p OutputQueue structure.
|
||||
* @return The queue status.
|
||||
* @retval false if the queue is not empty.
|
||||
* @retval true if the queue is empty.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chOQIsEmptyI(oqp) ((bool_t)(((oqp)->q_wrptr == (oqp)->q_rdptr) && \
|
||||
((oqp)->q_counter != 0)))
|
||||
|
||||
/**
|
||||
* @brief Evaluates to @p true if the specified output queue is full.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p OutputQueue structure.
|
||||
* @return The queue status.
|
||||
* @retval false if the queue is not full.
|
||||
* @retval true if the queue is full.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chOQIsFullI(oqp) ((bool_t)(chQSpaceI(oqp) <= 0))
|
||||
|
||||
/**
|
||||
* @brief Output queue write.
|
||||
* @details This function writes a byte value to an output queue. If the queue
|
||||
* is full then the calling thread is suspended until there is space
|
||||
* in the queue.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p OutputQueue structure
|
||||
* @param[in] b the byte value to be written in the queue
|
||||
* @return The operation status.
|
||||
* @retval Q_OK if the operation succeeded.
|
||||
* @retval Q_RESET if the queue has been reset.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define chOQPut(oqp, b) chOQPutTimeout(oqp, b, TIME_INFINITE)
|
||||
/** @} */
|
||||
input_queue_t name = _INPUTQUEUE_DATA(name, buffer, size, inotify, link)
|
||||
|
||||
/**
|
||||
* @brief Data part of a static output queue initializer.
|
||||
|
@ -339,30 +187,243 @@ typedef GenericQueue OutputQueue;
|
|||
* @param[in] link application defined pointer
|
||||
*/
|
||||
#define OUTPUTQUEUE_DECL(name, buffer, size, onotify, link) \
|
||||
OutputQueue name = _OUTPUTQUEUE_DATA(name, buffer, size, onotify, link)
|
||||
output_queue_t name = _OUTPUTQUEUE_DATA(name, buffer, size, onotify, link)
|
||||
|
||||
/**
|
||||
* @name Macro Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Returns the queue's buffer size.
|
||||
*
|
||||
* @param[in] qp pointer to a @p io_queue_t structure.
|
||||
* @return The buffer size.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chQSizeI(qp) ((size_t)((qp)->q_top - (qp)->q_buffer))
|
||||
|
||||
/**
|
||||
* @brief Queue space.
|
||||
* @details Returns the used space if used on an input queue or the empty
|
||||
* space if used on an output queue.
|
||||
*
|
||||
* @param[in] qp pointer to a @p io_queue_t structure.
|
||||
* @return The buffer space.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
#define chQSpaceI(qp) ((qp)->q_counter)
|
||||
|
||||
/**
|
||||
* @brief Returns the queue application-defined link.
|
||||
*
|
||||
* @param[in] qp pointer to a @p io_queue_t structure.
|
||||
* @return The application-defined link.
|
||||
*
|
||||
* @xclass
|
||||
*/
|
||||
#define chQGetLinkX(qp) ((qp)->q_link)
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void chIQInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy,
|
||||
void *link);
|
||||
void chIQResetI(InputQueue *iqp);
|
||||
msg_t chIQPutI(InputQueue *iqp, uint8_t b);
|
||||
msg_t chIQGetTimeout(InputQueue *iqp, systime_t time);
|
||||
size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp,
|
||||
void chIQObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size,
|
||||
qnotify_t infy, void *link);
|
||||
void chIQResetI(input_queue_t *iqp);
|
||||
msg_t chIQPutI(input_queue_t *iqp, uint8_t b);
|
||||
msg_t chIQGetTimeout(input_queue_t *iqp, systime_t time);
|
||||
size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp,
|
||||
size_t n, systime_t time);
|
||||
|
||||
void chOQInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy,
|
||||
void *link);
|
||||
void chOQResetI(OutputQueue *oqp);
|
||||
msg_t chOQPutTimeout(OutputQueue *oqp, uint8_t b, systime_t time);
|
||||
msg_t chOQGetI(OutputQueue *oqp);
|
||||
size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp,
|
||||
void chOQObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size,
|
||||
qnotify_t onfy, void *link);
|
||||
void chOQResetI(output_queue_t *oqp);
|
||||
msg_t chOQPutTimeout(output_queue_t *oqp, uint8_t b, systime_t time);
|
||||
msg_t chOQGetI(output_queue_t *oqp);
|
||||
size_t chOQWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
|
||||
size_t n, systime_t time);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module inline functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Returns the filled space into an input queue.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p input_queue_t structure
|
||||
* @return The number of full bytes in the queue.
|
||||
* @retval 0 if the queue is empty.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
static inline size_t chIQGetFullI(input_queue_t *iqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
return (size_t)chQSpaceI(iqp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the empty space into an input queue.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p input_queue_t structure
|
||||
* @return The number of empty bytes in the queue.
|
||||
* @retval 0 if the queue is full.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
static inline size_t chIQGetEmptyI(input_queue_t *iqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
return (size_t)(chQSizeI(iqp) - chQSpaceI(iqp));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Evaluates to @p true if the specified input queue is empty.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p input_queue_t structure.
|
||||
* @return The queue status.
|
||||
* @retval false if the queue is not empty.
|
||||
* @retval true if the queue is empty.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
static inline bool chIQIsEmptyI(input_queue_t *iqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
return (bool)(chQSpaceI(iqp) <= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Evaluates to @p true if the specified input queue is full.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p input_queue_t structure.
|
||||
* @return The queue status.
|
||||
* @retval false if the queue is not full.
|
||||
* @retval true if the queue is full.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
static inline bool chIQIsFullI(input_queue_t *iqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
return (bool)((iqp->q_wrptr == iqp->q_rdptr) && (iqp->q_counter != 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Input queue read.
|
||||
* @details This function reads a byte value from an input queue. If the queue
|
||||
* is empty then the calling thread is suspended until a byte arrives
|
||||
* in the queue.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p input_queue_t structure
|
||||
* @return A byte value from the queue.
|
||||
* @retval Q_RESET if the queue has been reset.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static inline msg_t chIQGet(input_queue_t *iqp) {
|
||||
|
||||
return chIQGetTimeout(iqp, TIME_INFINITE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the filled space into an output queue.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p output_queue_t structure
|
||||
* @return The number of full bytes in the queue.
|
||||
* @retval 0 if the queue is empty.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
static inline size_t chOQGetFullI(output_queue_t *oqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
return (size_t)(chQSizeI(oqp) - chQSpaceI(oqp));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the empty space into an output queue.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p output_queue_t structure
|
||||
* @return The number of empty bytes in the queue.
|
||||
* @retval 0 if the queue is full.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
static inline size_t chOQGetEmptyI(output_queue_t *oqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
return (size_t)chQSpaceI(oqp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Evaluates to @p true if the specified output queue is empty.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p output_queue_t structure.
|
||||
* @return The queue status.
|
||||
* @retval false if the queue is not empty.
|
||||
* @retval true if the queue is empty.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
static inline bool chOQIsEmptyI(output_queue_t *oqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
return (bool)((oqp->q_wrptr == oqp->q_rdptr) && (oqp->q_counter != 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Evaluates to @p true if the specified output queue is full.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p output_queue_t structure.
|
||||
* @return The queue status.
|
||||
* @retval false if the queue is not full.
|
||||
* @retval true if the queue is full.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
static inline bool chOQIsFullI(output_queue_t *oqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
return (bool)(chQSpaceI(oqp) <= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Output queue write.
|
||||
* @details This function writes a byte value to an output queue. If the queue
|
||||
* is full then the calling thread is suspended until there is space
|
||||
* in the queue.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p output_queue_t structure
|
||||
* @param[in] b the byte value to be written in the queue
|
||||
* @return The operation status.
|
||||
* @retval Q_OK if the operation succeeded.
|
||||
* @retval Q_RESET if the queue has been reset.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
static inline msg_t chOQPut(output_queue_t *oqp, uint8_t b) {
|
||||
|
||||
return chOQPutTimeout(oqp, b, TIME_INFINITE);
|
||||
}
|
||||
|
||||
#endif /* CH_CFG_USE_QUEUES */
|
||||
|
||||
#endif /* _CHQUEUES_H_ */
|
||||
|
|
|
@ -45,10 +45,30 @@
|
|||
|
||||
#if CH_CFG_USE_QUEUES || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module local definitions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module exported variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module local types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module local variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Puts the invoking thread into the queue's threads queue.
|
||||
*
|
||||
* @param[out] qp pointer to an @p GenericQueue structure
|
||||
* @param[out] qp pointer to an @p io_queue_t structure
|
||||
* @param[in] time the number of ticks before the operation timeouts,
|
||||
* the following special values are allowed:
|
||||
* - @a TIME_IMMEDIATE immediate timeout.
|
||||
|
@ -60,7 +80,7 @@
|
|||
* @retval Q_RESET if the queue has been reset.
|
||||
* @retval Q_TIMEOUT if the queue operation timed out.
|
||||
*/
|
||||
static msg_t qwait(GenericQueue *qp, systime_t time) {
|
||||
static msg_t qwait(io_queue_t *qp, systime_t time) {
|
||||
|
||||
if (TIME_IMMEDIATE == time)
|
||||
return Q_TIMEOUT;
|
||||
|
@ -69,6 +89,10 @@ static msg_t qwait(GenericQueue *qp, systime_t time) {
|
|||
return chSchGoSleepTimeoutS(CH_STATE_WTQUEUE, time);
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module exported functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Initializes an input queue.
|
||||
* @details A Semaphore is internally initialized and works as a counter of
|
||||
|
@ -76,7 +100,7 @@ static msg_t qwait(GenericQueue *qp, systime_t time) {
|
|||
* @note The callback is invoked from within the S-Locked system state,
|
||||
* see @ref system_states.
|
||||
*
|
||||
* @param[out] iqp pointer to an @p InputQueue structure
|
||||
* @param[out] iqp pointer to an @p input_queue_t structure
|
||||
* @param[in] bp pointer to a memory area allocated as queue buffer
|
||||
* @param[in] size size of the queue buffer
|
||||
* @param[in] infy pointer to a callback function that is invoked when
|
||||
|
@ -85,8 +109,8 @@ static msg_t qwait(GenericQueue *qp, systime_t time) {
|
|||
*
|
||||
* @init
|
||||
*/
|
||||
void chIQInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy,
|
||||
void *link) {
|
||||
void chIQObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size,
|
||||
qnotify_t infy, void *link) {
|
||||
|
||||
queue_init(&iqp->q_waiting);
|
||||
iqp->q_counter = 0;
|
||||
|
@ -103,11 +127,11 @@ void chIQInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy,
|
|||
* @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] iqp pointer to an @p InputQueue structure
|
||||
* @param[in] iqp pointer to an @p input_queue_t structure
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
void chIQResetI(InputQueue *iqp) {
|
||||
void chIQResetI(input_queue_t *iqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
|
@ -121,7 +145,7 @@ void chIQResetI(InputQueue *iqp) {
|
|||
* @brief Input queue write.
|
||||
* @details A byte value is written into the low end of an input queue.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p InputQueue structure
|
||||
* @param[in] iqp pointer to an @p input_queue_t structure
|
||||
* @param[in] b the byte value to be written in the queue
|
||||
* @return The operation status.
|
||||
* @retval Q_OK if the operation has been completed with success.
|
||||
|
@ -130,7 +154,7 @@ void chIQResetI(InputQueue *iqp) {
|
|||
*
|
||||
* @iclass
|
||||
*/
|
||||
msg_t chIQPutI(InputQueue *iqp, uint8_t b) {
|
||||
msg_t chIQPutI(input_queue_t *iqp, uint8_t b) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
|
@ -156,7 +180,7 @@ msg_t chIQPutI(InputQueue *iqp, uint8_t b) {
|
|||
* @note The callback is invoked before reading the character from the
|
||||
* buffer or before entering the state @p CH_STATE_WTQUEUE.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p InputQueue structure
|
||||
* @param[in] iqp pointer to an @p input_queue_t structure
|
||||
* @param[in] time the number of ticks before the operation timeouts,
|
||||
* the following special values are allowed:
|
||||
* - @a TIME_IMMEDIATE immediate timeout.
|
||||
|
@ -168,7 +192,7 @@ msg_t chIQPutI(InputQueue *iqp, uint8_t b) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) {
|
||||
msg_t chIQGetTimeout(input_queue_t *iqp, systime_t time) {
|
||||
uint8_t b;
|
||||
|
||||
chSysLock();
|
||||
|
@ -177,7 +201,7 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) {
|
|||
|
||||
while (chIQIsEmptyI(iqp)) {
|
||||
msg_t msg;
|
||||
if ((msg = qwait((GenericQueue *)iqp, time)) < Q_OK) {
|
||||
if ((msg = qwait((io_queue_t *)iqp, time)) < Q_OK) {
|
||||
chSysUnlock();
|
||||
return msg;
|
||||
}
|
||||
|
@ -203,7 +227,7 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) {
|
|||
* @note The callback is invoked before reading each character from the
|
||||
* buffer or before entering the state @p CH_STATE_WTQUEUE.
|
||||
*
|
||||
* @param[in] iqp pointer to an @p InputQueue structure
|
||||
* @param[in] iqp pointer to an @p input_queue_t structure
|
||||
* @param[out] bp pointer to the data buffer
|
||||
* @param[in] n the maximum amount of data to be transferred, the
|
||||
* value 0 is reserved
|
||||
|
@ -216,7 +240,7 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp,
|
||||
size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp,
|
||||
size_t n, systime_t time) {
|
||||
qnotify_t nfy = iqp->q_notify;
|
||||
size_t r = 0;
|
||||
|
@ -229,7 +253,7 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp,
|
|||
nfy(iqp);
|
||||
|
||||
while (chIQIsEmptyI(iqp)) {
|
||||
if (qwait((GenericQueue *)iqp, time) != Q_OK) {
|
||||
if (qwait((io_queue_t *)iqp, time) != Q_OK) {
|
||||
chSysUnlock();
|
||||
return r;
|
||||
}
|
||||
|
@ -256,7 +280,7 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp,
|
|||
* @note The callback is invoked from within the S-Locked system state,
|
||||
* see @ref system_states.
|
||||
*
|
||||
* @param[out] oqp pointer to an @p OutputQueue structure
|
||||
* @param[out] oqp pointer to an @p output_queue_t structure
|
||||
* @param[in] bp pointer to a memory area allocated as queue buffer
|
||||
* @param[in] size size of the queue buffer
|
||||
* @param[in] onfy pointer to a callback function that is invoked when
|
||||
|
@ -265,8 +289,8 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp,
|
|||
*
|
||||
* @init
|
||||
*/
|
||||
void chOQInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy,
|
||||
void *link) {
|
||||
void chOQObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size,
|
||||
qnotify_t onfy, void *link) {
|
||||
|
||||
queue_init(&oqp->q_waiting);
|
||||
oqp->q_counter = size;
|
||||
|
@ -283,11 +307,11 @@ void chOQInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy,
|
|||
* @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] oqp pointer to an @p OutputQueue structure
|
||||
* @param[in] oqp pointer to an @p output_queue_t structure
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
void chOQResetI(OutputQueue *oqp) {
|
||||
void chOQResetI(output_queue_t *oqp) {
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
||||
|
@ -305,7 +329,7 @@ void chOQResetI(OutputQueue *oqp) {
|
|||
* @note The callback is invoked after writing the character into the
|
||||
* buffer.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p OutputQueue structure
|
||||
* @param[in] oqp pointer to an @p output_queue_t structure
|
||||
* @param[in] b the byte value to be written in the queue
|
||||
* @param[in] time the number of ticks before the operation timeouts,
|
||||
* the following special values are allowed:
|
||||
|
@ -319,13 +343,13 @@ void chOQResetI(OutputQueue *oqp) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
msg_t chOQPutTimeout(OutputQueue *oqp, uint8_t b, systime_t time) {
|
||||
msg_t chOQPutTimeout(output_queue_t *oqp, uint8_t b, systime_t time) {
|
||||
|
||||
chSysLock();
|
||||
while (chOQIsFullI(oqp)) {
|
||||
msg_t msg;
|
||||
|
||||
if ((msg = qwait((GenericQueue *)oqp, time)) < Q_OK) {
|
||||
if ((msg = qwait((io_queue_t *)oqp, time)) < Q_OK) {
|
||||
chSysUnlock();
|
||||
return msg;
|
||||
}
|
||||
|
@ -347,13 +371,13 @@ msg_t chOQPutTimeout(OutputQueue *oqp, uint8_t b, systime_t time) {
|
|||
* @brief Output queue read.
|
||||
* @details A byte value is read from the low end of an output queue.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p OutputQueue structure
|
||||
* @param[in] oqp pointer to an @p output_queue_t structure
|
||||
* @return The byte value from the queue.
|
||||
* @retval Q_EMPTY if the queue is empty.
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
msg_t chOQGetI(OutputQueue *oqp) {
|
||||
msg_t chOQGetI(output_queue_t *oqp) {
|
||||
uint8_t b;
|
||||
|
||||
chDbgCheckClassI();
|
||||
|
@ -383,7 +407,7 @@ msg_t chOQGetI(OutputQueue *oqp) {
|
|||
* @note The callback is invoked after writing each character into the
|
||||
* buffer.
|
||||
*
|
||||
* @param[in] oqp pointer to an @p OutputQueue structure
|
||||
* @param[in] oqp pointer to an @p output_queue_t structure
|
||||
* @param[out] bp pointer to the data buffer
|
||||
* @param[in] n the maximum amount of data to be transferred, the
|
||||
* value 0 is reserved
|
||||
|
@ -396,7 +420,7 @@ msg_t chOQGetI(OutputQueue *oqp) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp,
|
||||
size_t chOQWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
|
||||
size_t n, systime_t time) {
|
||||
qnotify_t nfy = oqp->q_notify;
|
||||
size_t w = 0;
|
||||
|
@ -406,7 +430,7 @@ size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp,
|
|||
chSysLock();
|
||||
while (true) {
|
||||
while (chOQIsFullI(oqp)) {
|
||||
if (qwait((GenericQueue *)oqp, time) != Q_OK) {
|
||||
if (qwait((io_queue_t *)oqp, time) != Q_OK) {
|
||||
chSysUnlock();
|
||||
return w;
|
||||
}
|
||||
|
|
|
@ -671,7 +671,7 @@ static void bmk13_execute(void) {
|
|||
#endif
|
||||
#if CH_CFG_USE_QUEUES || defined(__DOXYGEN__)
|
||||
test_print("--- Queue : ");
|
||||
test_printn(sizeof(GenericQueue));
|
||||
test_printn(sizeof(io_queue_t));
|
||||
test_println(" bytes");
|
||||
#endif
|
||||
#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__)
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
|
||||
#define TEST_QUEUES_SIZE 4
|
||||
|
||||
static void notify(GenericQueue *qp) {
|
||||
static void notify(io_queue_t *qp) {
|
||||
(void)qp;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ static OUTPUTQUEUE_DECL(oq, test.wa.T1, TEST_QUEUES_SIZE, notify, NULL);
|
|||
|
||||
static void queues1_setup(void) {
|
||||
|
||||
chIQInit(&iq, wa[0], TEST_QUEUES_SIZE, notify, NULL);
|
||||
chIQObjectInit(&iq, wa[0], TEST_QUEUES_SIZE, notify, NULL);
|
||||
}
|
||||
|
||||
static msg_t thread1(void *p) {
|
||||
|
@ -164,7 +164,7 @@ ROMCONST struct testcase testqueues1 = {
|
|||
|
||||
static void queues2_setup(void) {
|
||||
|
||||
chOQInit(&oq, wa[0], TEST_QUEUES_SIZE, notify, NULL);
|
||||
chOQObjectInit(&oq, wa[0], TEST_QUEUES_SIZE, notify, NULL);
|
||||
}
|
||||
|
||||
static msg_t thread2(void *p) {
|
||||
|
|
Loading…
Reference in New Issue