|
ChibiOS/RT
2.5.1 |
|
ChibiOS/RT queues are mostly used in serial-like device drivers. The device drivers are usually designed to have a lower side (lower driver, it is usually an interrupt service routine) and an upper side (upper driver, accessed by the application threads).
There are several kind of queues:
CH_USE_QUEUES option must be enabled in chconf.h. Data Structures | |
| struct | GenericQueue |
| Generic I/O queue structure. More... | |
Functions | |
| void | chIQInit (InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy, void *link) |
| Initializes an input queue. | |
| void | chIQResetI (InputQueue *iqp) |
| Resets an input queue. | |
| msg_t | chIQPutI (InputQueue *iqp, uint8_t b) |
| Input queue write. | |
| msg_t | chIQGetTimeout (InputQueue *iqp, systime_t time) |
| Input queue read with timeout. | |
| size_t | chIQReadTimeout (InputQueue *iqp, uint8_t *bp, size_t n, systime_t time) |
| Input queue read with timeout. | |
| void | chOQInit (OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy, void *link) |
| Initializes an output queue. | |
| void | chOQResetI (OutputQueue *oqp) |
| Resets an output queue. | |
| msg_t | chOQPutTimeout (OutputQueue *oqp, uint8_t b, systime_t time) |
| Output queue write with timeout. | |
| msg_t | chOQGetI (OutputQueue *oqp) |
| Output queue read. | |
| size_t | chOQWriteTimeout (OutputQueue *oqp, const uint8_t *bp, size_t n, systime_t time) |
| Output queue write with timeout. | |
Queue functions returned status value | |
| #define | Q_OK RDY_OK |
| Operation successful. | |
| #define | Q_TIMEOUT RDY_TIMEOUT |
| Timeout condition. | |
| #define | Q_RESET RDY_RESET |
| Queue has been reset. | |
| #define | Q_EMPTY -3 |
| Queue empty. | |
| #define | Q_FULL -4 |
| Queue full,. | |
Macro Functions | |
| #define | chQSizeI(qp) ((size_t)((qp)->q_top - (qp)->q_buffer)) |
| Returns the queue's buffer size. | |
| #define | chQSpaceI(qp) ((qp)->q_counter) |
| Queue space. | |
| #define | chQGetLink(qp) ((qp)->q_link) |
| Returns the queue application-defined link. | |
| #define | chIQGetFullI(iqp) chQSpaceI(iqp) |
| Returns the filled space into an input queue. | |
| #define | chIQGetEmptyI(iqp) (chQSizeI(iqp) - chQSpaceI(iqp)) |
| Returns the empty space into an input queue. | |
| #define | chIQIsEmptyI(iqp) ((bool_t)(chQSpaceI(iqp) <= 0)) |
Evaluates to TRUE if the specified input queue is empty. | |
| #define | chIQIsFullI(iqp) |
Evaluates to TRUE if the specified input queue is full. | |
| #define | chIQGet(iqp) chIQGetTimeout(iqp, TIME_INFINITE) |
| Input queue read. | |
| #define | chOQGetFullI(oqp) (chQSizeI(oqp) - chQSpaceI(oqp)) |
| Returns the filled space into an output queue. | |
| #define | chOQGetEmptyI(oqp) chQSpaceI(oqp) |
| Returns the empty space into an output queue. | |
| #define | chOQIsEmptyI(oqp) |
Evaluates to TRUE if the specified output queue is empty. | |
| #define | chOQIsFullI(oqp) ((bool_t)(chQSpaceI(oqp) <= 0)) |
Evaluates to TRUE if the specified output queue is full. | |
| #define | chOQPut(oqp, b) chOQPutTimeout(oqp, b, TIME_INFINITE) |
| Output queue write. | |
Defines | |
| #define | _INPUTQUEUE_DATA(name, buffer, size, inotify, link) |
| Data part of a static input queue initializer. | |
| #define | INPUTQUEUE_DECL(name, buffer, size, inotify, link) InputQueue name = _INPUTQUEUE_DATA(name, buffer, size, inotify, link) |
| Static input queue initializer. | |
| #define | _OUTPUTQUEUE_DATA(name, buffer, size, onotify, link) |
| Data part of a static output queue initializer. | |
| #define | OUTPUTQUEUE_DECL(name, buffer, size, onotify, link) OutputQueue name = _OUTPUTQUEUE_DATA(name, buffer, size, onotify, link) |
| Static output queue initializer. | |
Typedefs | |
| typedef struct GenericQueue | GenericQueue |
| Type of a generic I/O queue structure. | |
| typedef void(* | qnotify_t )(GenericQueue *qp) |
| Queue notification callback type. | |
| typedef GenericQueue | InputQueue |
| Type of an input queue structure. | |
| typedef GenericQueue | OutputQueue |
| Type of an output queue structure. | |
| void chIQInit | ( | InputQueue * | iqp, |
| uint8_t * | bp, | ||
| size_t | size, | ||
| qnotify_t | infy, | ||
| void * | link | ||
| ) |
Initializes an input queue.
A Semaphore is internally initialized and works as a counter of the bytes contained in the queue.
| [out] | iqp | pointer to an InputQueue structure |
| [in] | bp | pointer to a memory area allocated as queue buffer |
| [in] | size | size of the queue buffer |
| [in] | infy | pointer to a callback function that is invoked when data is read from the queue. The value can be NULL. |
| [in] | link | application defined pointer |
Definition at line 88 of file chqueues.c.
References GenericQueue::q_buffer, GenericQueue::q_counter, GenericQueue::q_link, GenericQueue::q_notify, GenericQueue::q_rdptr, GenericQueue::q_top, GenericQueue::q_waiting, GenericQueue::q_wrptr, and queue_init.
| void chIQResetI | ( | InputQueue * | iqp | ) |
Resets an input queue.
All the data in the input queue is erased and lost, any waiting thread is resumed with status Q_RESET.
| [in] | iqp | pointer to an InputQueue structure |
Definition at line 110 of file chqueues.c.
References chDbgCheckClassI(), chSchReadyI(), fifo_remove(), notempty, GenericQueue::q_buffer, GenericQueue::q_counter, GenericQueue::q_rdptr, Q_RESET, GenericQueue::q_waiting, GenericQueue::q_wrptr, and Thread::rdymsg.

| msg_t chIQPutI | ( | InputQueue * | iqp, |
| uint8_t | b | ||
| ) |
Input queue write.
A byte value is written into the low end of an input queue.
| [in] | iqp | pointer to an InputQueue structure |
| [in] | b | the byte value to be written in the queue |
| Q_OK | if the operation has been completed with success. |
| Q_FULL | if the queue is full and the operation cannot be completed. |
Definition at line 133 of file chqueues.c.
References chDbgCheckClassI(), chIQIsFullI, chSchReadyI(), fifo_remove(), notempty, GenericQueue::q_buffer, GenericQueue::q_counter, Q_FULL, Q_OK, GenericQueue::q_top, GenericQueue::q_waiting, GenericQueue::q_wrptr, and Thread::rdymsg.

| msg_t chIQGetTimeout | ( | InputQueue * | iqp, |
| systime_t | time | ||
| ) |
Input queue read with timeout.
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 or a timeout occurs.
THD_STATE_WTQUEUE.| [in] | iqp | pointer to an InputQueue structure |
| [in] | time | the number of ticks before the operation timeouts, the following special values are allowed:
|
| Q_TIMEOUT | if the specified time expired. |
| Q_RESET | if the queue has been reset. |
Definition at line 171 of file chqueues.c.
References chIQIsEmptyI, chSysLock, chSysUnlock, GenericQueue::q_buffer, GenericQueue::q_counter, GenericQueue::q_notify, Q_OK, GenericQueue::q_rdptr, and GenericQueue::q_top.
| size_t chIQReadTimeout | ( | InputQueue * | iqp, |
| uint8_t * | bp, | ||
| size_t | n, | ||
| systime_t | time | ||
| ) |
Input queue read with timeout.
The function reads data from an input queue into a buffer. The operation completes when the specified amount of data has been transferred or after the specified timeout or if the queue has been reset.
THD_STATE_WTQUEUE.| [in] | iqp | pointer to an InputQueue structure |
| [out] | bp | pointer to the data buffer |
| [in] | n | the maximum amount of data to be transferred, the value 0 is reserved |
| [in] | time | the number of ticks before the operation timeouts, the following special values are allowed:
|
Definition at line 219 of file chqueues.c.
References chDbgCheck, chIQIsEmptyI, chSysLock, chSysUnlock, GenericQueue::q_buffer, GenericQueue::q_counter, GenericQueue::q_notify, Q_OK, GenericQueue::q_rdptr, GenericQueue::q_top, and TRUE.
| void chOQInit | ( | OutputQueue * | oqp, |
| uint8_t * | bp, | ||
| size_t | size, | ||
| qnotify_t | onfy, | ||
| void * | link | ||
| ) |
Initializes an output queue.
A Semaphore is internally initialized and works as a counter of the free bytes in the queue.
| [out] | oqp | pointer to an OutputQueue structure |
| [in] | bp | pointer to a memory area allocated as queue buffer |
| [in] | size | size of the queue buffer |
| [in] | onfy | pointer to a callback function that is invoked when data is written to the queue. The value can be NULL. |
| [in] | link | application defined pointer |
Definition at line 268 of file chqueues.c.
References GenericQueue::q_buffer, GenericQueue::q_counter, GenericQueue::q_link, GenericQueue::q_notify, GenericQueue::q_rdptr, GenericQueue::q_top, GenericQueue::q_waiting, GenericQueue::q_wrptr, and queue_init.
| void chOQResetI | ( | OutputQueue * | oqp | ) |
Resets an output queue.
All the data in the output queue is erased and lost, any waiting thread is resumed with status Q_RESET.
| [in] | oqp | pointer to an OutputQueue structure |
Definition at line 290 of file chqueues.c.
References chDbgCheckClassI(), chQSizeI, chSchReadyI(), fifo_remove(), notempty, GenericQueue::q_buffer, GenericQueue::q_counter, GenericQueue::q_rdptr, Q_RESET, GenericQueue::q_waiting, GenericQueue::q_wrptr, and Thread::rdymsg.

| msg_t chOQPutTimeout | ( | OutputQueue * | oqp, |
| uint8_t | b, | ||
| systime_t | time | ||
| ) |
Output queue write with timeout.
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 or a timeout occurs.
| [in] | oqp | pointer to an OutputQueue structure |
| [in] | b | the byte value to be written in the queue |
| [in] | time | the number of ticks before the operation timeouts, the following special values are allowed:
|
| Q_OK | if the operation succeeded. |
| Q_TIMEOUT | if the specified time expired. |
| Q_RESET | if the queue has been reset. |
Definition at line 322 of file chqueues.c.
References chOQIsFullI, chSysLock, chSysUnlock, GenericQueue::q_buffer, GenericQueue::q_counter, GenericQueue::q_notify, Q_OK, GenericQueue::q_top, and GenericQueue::q_wrptr.
| msg_t chOQGetI | ( | OutputQueue * | oqp | ) |
Output queue read.
A byte value is read from the low end of an output queue.
| [in] | oqp | pointer to an OutputQueue structure |
| Q_EMPTY | if the queue is empty. |
Definition at line 356 of file chqueues.c.
References chDbgCheckClassI(), chOQIsEmptyI, chSchReadyI(), fifo_remove(), notempty, GenericQueue::q_buffer, GenericQueue::q_counter, Q_EMPTY, Q_OK, GenericQueue::q_rdptr, GenericQueue::q_top, GenericQueue::q_waiting, and Thread::rdymsg.

| size_t chOQWriteTimeout | ( | OutputQueue * | oqp, |
| const uint8_t * | bp, | ||
| size_t | n, | ||
| systime_t | time | ||
| ) |
Output queue write with timeout.
The function writes data from a buffer to an output queue. The operation completes when the specified amount of data has been transferred or after the specified timeout or if the queue has been reset.
| [in] | oqp | pointer to an OutputQueue structure |
| [out] | bp | pointer to the data buffer |
| [in] | n | the maximum amount of data to be transferred, the value 0 is reserved |
| [in] | time | the number of ticks before the operation timeouts, the following special values are allowed:
|
Definition at line 399 of file chqueues.c.
References chDbgCheck, chOQIsFullI, chSysLock, chSysUnlock, GenericQueue::q_buffer, GenericQueue::q_counter, GenericQueue::q_notify, Q_OK, GenericQueue::q_top, GenericQueue::q_wrptr, and TRUE.
| #define Q_OK RDY_OK |
Operation successful.
Definition at line 38 of file chqueues.h.
Referenced by chIQGetTimeout(), chIQPutI(), chIQReadTimeout(), chOQGetI(), chOQPutTimeout(), and chOQWriteTimeout().
| #define Q_TIMEOUT RDY_TIMEOUT |
Timeout condition.
Definition at line 39 of file chqueues.h.
| #define Q_RESET RDY_RESET |
Queue has been reset.
Definition at line 40 of file chqueues.h.
Referenced by chIQResetI(), and chOQResetI().
| #define Q_EMPTY -3 |
| #define Q_FULL -4 |
| #define chQSizeI | ( | qp | ) | ((size_t)((qp)->q_top - (qp)->q_buffer)) |
Returns the queue's buffer size.
| [in] | qp | pointer to a GenericQueue structure. |
Definition at line 86 of file chqueues.h.
Referenced by chOQResetI().
| #define chQSpaceI | ( | qp | ) | ((qp)->q_counter) |
Queue space.
Returns the used space if used on an input queue or the empty space if used on an output queue.
| [in] | qp | pointer to a GenericQueue structure. |
Definition at line 98 of file chqueues.h.
| #define chQGetLink | ( | qp | ) | ((qp)->q_link) |
Returns the queue application-defined link.
| [in] | qp | pointer to a GenericQueue structure. |
Definition at line 109 of file chqueues.h.
| #define chIQGetFullI | ( | iqp | ) | chQSpaceI(iqp) |
Returns the filled space into an input queue.
| [in] | iqp | pointer to an InputQueue structure |
| 0 | if the queue is empty. |
Definition at line 138 of file chqueues.h.
| #define chIQGetEmptyI | ( | iqp | ) | (chQSizeI(iqp) - chQSpaceI(iqp)) |
Returns the empty space into an input queue.
| [in] | iqp | pointer to an InputQueue structure |
| 0 | if the queue is full. |
Definition at line 149 of file chqueues.h.
| #define chIQIsEmptyI | ( | iqp | ) | ((bool_t)(chQSpaceI(iqp) <= 0)) |
Evaluates to TRUE if the specified input queue is empty.
| [in] | iqp | pointer to an InputQueue structure. |
| FALSE | The queue is not empty. |
| TRUE | The queue is empty. |
Definition at line 161 of file chqueues.h.
Referenced by chIQGetTimeout(), and chIQReadTimeout().
| #define chIQIsFullI | ( | iqp | ) |
((bool_t)(((iqp)->q_wrptr == (iqp)->q_rdptr) && \ ((iqp)->q_counter != 0)))
Evaluates to TRUE if the specified input queue is full.
| [in] | iqp | pointer to an InputQueue structure. |
| FALSE | The queue is not full. |
| TRUE | The queue is full. |
Definition at line 173 of file chqueues.h.
Referenced by chIQPutI().
| #define chIQGet | ( | iqp | ) | chIQGetTimeout(iqp, TIME_INFINITE) |
Input queue read.
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.
| [in] | iqp | pointer to an InputQueue structure |
| Q_RESET | if the queue has been reset. |
Definition at line 188 of file chqueues.h.
| #define _INPUTQUEUE_DATA | ( | name, | |
| buffer, | |||
| size, | |||
| inotify, | |||
| link | |||
| ) |
{ \
_THREADSQUEUE_DATA(name), \
0, \
(uint8_t *)(buffer), \
(uint8_t *)(buffer) + (size), \
(uint8_t *)(buffer), \
(uint8_t *)(buffer), \
(inotify), \
(link) \
}
Data part of a static input queue initializer.
This macro should be used when statically initializing an input queue that is part of a bigger structure.
| [in] | name | the name of the input queue variable |
| [in] | buffer | pointer to the queue buffer area |
| [in] | size | size of the queue buffer area |
| [in] | inotify | input notification callback pointer |
| [in] | link | application defined pointer |
Definition at line 202 of file chqueues.h.
| #define INPUTQUEUE_DECL | ( | name, | |
| buffer, | |||
| size, | |||
| inotify, | |||
| link | |||
| ) | InputQueue name = _INPUTQUEUE_DATA(name, buffer, size, inotify, link) |
Static input queue initializer.
Statically initialized input queues require no explicit initialization using chIQInit().
| [in] | name | the name of the input queue variable |
| [in] | buffer | pointer to the queue buffer area |
| [in] | size | size of the queue buffer area |
| [in] | inotify | input notification callback pointer |
| [in] | link | application defined pointer |
Definition at line 224 of file chqueues.h.
| #define chOQGetFullI | ( | oqp | ) | (chQSizeI(oqp) - chQSpaceI(oqp)) |
Returns the filled space into an output queue.
| [in] | oqp | pointer to an OutputQueue structure |
| 0 | if the queue is empty. |
Definition at line 253 of file chqueues.h.
| #define chOQGetEmptyI | ( | oqp | ) | chQSpaceI(oqp) |
Returns the empty space into an output queue.
| [in] | oqp | pointer to an OutputQueue structure |
| 0 | if the queue is full. |
Definition at line 264 of file chqueues.h.
| #define chOQIsEmptyI | ( | oqp | ) |
((bool_t)(((oqp)->q_wrptr == (oqp)->q_rdptr) && \ ((oqp)->q_counter != 0)))
Evaluates to TRUE if the specified output queue is empty.
| [in] | oqp | pointer to an OutputQueue structure. |
| FALSE | The queue is not empty. |
| TRUE | The queue is empty. |
Definition at line 276 of file chqueues.h.
Referenced by chOQGetI().
| #define chOQIsFullI | ( | oqp | ) | ((bool_t)(chQSpaceI(oqp) <= 0)) |
Evaluates to TRUE if the specified output queue is full.
| [in] | oqp | pointer to an OutputQueue structure. |
| FALSE | The queue is not full. |
| TRUE | The queue is full. |
Definition at line 289 of file chqueues.h.
Referenced by chOQPutTimeout(), and chOQWriteTimeout().
| #define chOQPut | ( | oqp, | |
| b | |||
| ) | chOQPutTimeout(oqp, b, TIME_INFINITE) |
Output queue write.
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.
| [in] | oqp | pointer to an OutputQueue structure |
| [in] | b | the byte value to be written in the queue |
| Q_OK | if the operation succeeded. |
| Q_RESET | if the queue has been reset. |
Definition at line 305 of file chqueues.h.
| #define _OUTPUTQUEUE_DATA | ( | name, | |
| buffer, | |||
| size, | |||
| onotify, | |||
| link | |||
| ) |
{ \
_THREADSQUEUE_DATA(name), \
(size), \
(uint8_t *)(buffer), \
(uint8_t *)(buffer) + (size), \
(uint8_t *)(buffer), \
(uint8_t *)(buffer), \
(onotify), \
(link) \
}
Data part of a static output queue initializer.
This macro should be used when statically initializing an output queue that is part of a bigger structure.
| [in] | name | the name of the output queue variable |
| [in] | buffer | pointer to the queue buffer area |
| [in] | size | size of the queue buffer area |
| [in] | onotify | output notification callback pointer |
| [in] | link | application defined pointer |
Definition at line 319 of file chqueues.h.
| #define OUTPUTQUEUE_DECL | ( | name, | |
| buffer, | |||
| size, | |||
| onotify, | |||
| link | |||
| ) | OutputQueue name = _OUTPUTQUEUE_DATA(name, buffer, size, onotify, link) |
Static output queue initializer.
Statically initialized output queues require no explicit initialization using chOQInit().
| [in] | name | the name of the output queue variable |
| [in] | buffer | pointer to the queue buffer area |
| [in] | size | size of the queue buffer area |
| [in] | onotify | output notification callback pointer |
| [in] | link | application defined pointer |
Definition at line 341 of file chqueues.h.
| typedef struct GenericQueue GenericQueue |
Type of a generic I/O queue structure.
Definition at line 48 of file chqueues.h.
| typedef void(* qnotify_t)(GenericQueue *qp) |
Queue notification callback type.
Definition at line 51 of file chqueues.h.
| typedef GenericQueue InputQueue |
Type of an input queue structure.
This structure represents a generic asymmetrical input queue. Writing to the queue is non-blocking and can be performed from interrupt handlers or from within a kernel lock zone (see I-Locked and S-Locked states in System States). Reading the queue can be a blocking operation and is supposed to be performed by a system thread.
Definition at line 123 of file chqueues.h.
| typedef GenericQueue OutputQueue |
Type of an output queue structure.
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 I-Locked and S-Locked states in System States). Writing the queue can be a blocking operation and is supposed to be performed by a system thread.
Definition at line 238 of file chqueues.h.