diff options
Diffstat (limited to 'os/kernel/include/chqueues.h')
| -rw-r--r-- | os/kernel/include/chqueues.h | 105 | 
1 files changed, 72 insertions, 33 deletions
| diff --git a/os/kernel/include/chqueues.h b/os/kernel/include/chqueues.h index 1913e8bdd..a2df59dad 100644 --- a/os/kernel/include/chqueues.h +++ b/os/kernel/include/chqueues.h @@ -1,5 +1,6 @@  /*
 -    ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio.
 +    ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
 +                 2011 Giovanni Di Sirio.
      This file is part of ChibiOS/RT.
 @@ -30,18 +31,11 @@  #if CH_USE_QUEUES || defined(__DOXYGEN__)
 -/*
 - * Module dependencies check.
 - */
 -#if !CH_USE_SEMAPHORES
 -#error "CH_USE_QUEUES requires CH_USE_SEMAPHORES"
 -#endif
 -
  /** @brief Returned by the queue functions if the operation is successful.*/
  #define Q_OK            RDY_OK
  /** @brief Returned by the queue functions if a timeout occurs.*/
  #define Q_TIMEOUT       RDY_TIMEOUT
 -/** @brief Returned by the queue functions if the queue is reset.*/
 +/** @brief Returned by the queue functions if the queue has been reset.*/
  #define Q_RESET         RDY_RESET
  /** @brief Returned by the queue functions if the queue is empty.*/
  #define Q_EMPTY         -3
 @@ -66,12 +60,13 @@ typedef void (*qnotify_t)(GenericQueue *qp);   *          @ref system_states) and is non-blocking.
   */
  struct GenericQueue {
 +  ThreadsQueue          q_waiting;  /**< @brief Queue of waiting threads.   */
 +  size_t                q_counter;  /**< @brief Resources counter.          */
    uint8_t               *q_buffer;  /**< @brief Pointer to the queue buffer.*/
    uint8_t               *q_top;     /**< @brief Pointer to the first location
                                                  after the buffer.           */
    uint8_t               *q_wrptr;   /**< @brief Write pointer.              */
    uint8_t               *q_rdptr;   /**< @brief Read pointer.               */
 -  Semaphore             q_sem;      /**< @brief Counter @p Semaphore.       */
    qnotify_t             q_notify;   /**< @brief Data notification callback. */
  };
 @@ -83,21 +78,19 @@ struct GenericQueue {   *
   * @iclass
   */
 -#define chQSizeI(qp) ((qp)->q_top - (qp)->q_buffer)
 +#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.
 - * @note    The returned value can be less than zero when there are waiting
 - *          threads on the internal semaphore.
   *
   * @param[in] qp        pointer to a @p GenericQueue structure.
   * @return              The buffer space.
   *
   * @iclass
   */
 -#define chQSpaceI(qp) chSemGetCounterI(&(qp)->q_sem)
 +#define chQSpaceI(qp) ((size_t)((qp)->q_counter))
  /**
   * @extends GenericQueue
 @@ -113,6 +106,28 @@ struct GenericQueue {  typedef GenericQueue InputQueue;
  /**
 + * @brief   Returns the filled space into an input queue.
 + *
 + * @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
 + */
 +#define chIQGetFullI(iqp) chQSpaceI(iqp)
 +
 +/**
 + * @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.
 @@ -134,7 +149,8 @@ typedef GenericQueue InputQueue;   *
   * @iclass
   */
 -#define chIQIsFullI(iqp) ((bool_t)(chQSpaceI(iqp) >= chQSizeI(iqp)))
 +#define chIQIsFullI(iqp) ((bool_t)(((iqp)->q_wrptr == (iqp)->q_rdptr) &&   \
 +                                   ((iqp)->q_counter != 0)))
  /**
   * @brief   Input queue read.
 @@ -144,7 +160,7 @@ typedef GenericQueue InputQueue;   *
   * @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.
 + * @retval Q_RESET      if the queue has been reset.
   *
   * @api
   */
 @@ -160,13 +176,14 @@ typedef GenericQueue InputQueue;   * @param[in] size      size of the queue buffer area
   * @param[in] inotify   input notification callback pointer
   */
 -#define _INPUTQUEUE_DATA(name, buffer, size, inotify) {                 \
 -  (uint8_t *)(buffer),                                                  \
 -  (uint8_t *)(buffer) + size,                                           \
 -  (uint8_t *)(buffer),                                                  \
 -  (uint8_t *)(buffer),                                                  \
 -  _SEMAPHORE_DATA(name.q_sem, 0),                                       \
 -  inotify                                                               \
 +#define _INPUTQUEUE_DATA(name, buffer, size, inotify) {                     \
 +  _THREADSQUEUE_DATA(name),                                                 \
 +  0,                                                                        \
 +  (uint8_t *)(buffer),                                                      \
 +  (uint8_t *)(buffer) + (size),                                             \
 +  (uint8_t *)(buffer),                                                      \
 +  (uint8_t *)(buffer),                                                      \
 +  inotify                                                                   \
  }
  /**
 @@ -195,6 +212,28 @@ typedef GenericQueue InputQueue;   */
  typedef GenericQueue OutputQueue;
 + /**
 +  * @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] iqp       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(iqp) chQSpaceI(oqp)
 +
  /**
   * @brief   Evaluates to @p TRUE if the specified output queue is empty.
   *
 @@ -205,7 +244,8 @@ typedef GenericQueue OutputQueue;   *
   * @iclass
   */
 -#define chOQIsEmptyI(oqp) ((bool_t)(chQSpaceI(oqp) >= chQSizeI(oqp)))
 +#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.
 @@ -245,13 +285,14 @@ typedef GenericQueue OutputQueue;   * @param[in] size      size of the queue buffer area
   * @param[in] onotify   output notification callback pointer
   */
 -#define _OUTPUTQUEUE_DATA(name, buffer, size, onotify) {                \
 -  (uint8_t *)(buffer),                                                  \
 -  (uint8_t *)(buffer) + size,                                           \
 -  (uint8_t *)(buffer),                                                  \
 -  (uint8_t *)(buffer),                                                  \
 -  _SEMAPHORE_DATA(name.q_sem, size),                                    \
 -  onotify                                                               \
 +#define _OUTPUTQUEUE_DATA(name, buffer, size, onotify) {                    \
 +  _THREADSQUEUE_DATA(name),                                                 \
 +  (size),                                                                   \
 +  (uint8_t *)(buffer),                                                      \
 +  (uint8_t *)(buffer) + (size),                                             \
 +  (uint8_t *)(buffer),                                                      \
 +  (uint8_t *)(buffer),                                                      \
 +  onotify                                                                   \
  }
  /**
 @@ -271,7 +312,6 @@ typedef GenericQueue OutputQueue;  extern "C" {
  #endif
    void chIQInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy);
 -  size_t chIQGetFullI(InputQueue *iqp);
    void chIQResetI(InputQueue *iqp);
    msg_t chIQPutI(InputQueue *iqp, uint8_t b);
    msg_t chIQGetTimeout(InputQueue *iqp, systime_t time);
 @@ -279,7 +319,6 @@ extern "C" {                           size_t n, systime_t time);
    void chOQInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy);
 -  size_t chOQGetFullI(OutputQueue *oqp);
    void chOQResetI(OutputQueue *oqp);
    msg_t chOQPutTimeout(OutputQueue *oqp, uint8_t b, systime_t time);
    msg_t chOQGetI(OutputQueue *oqp);
 | 
