This is auxiliary implementation of queue. More...
Data Structures | |
struct | Queue |
Generic queue structure. More... | |
struct | BasicQueue |
Queue with 256 bytes of storage preallocated. More... | |
Macros | |
#define | QUEUE_LENGTH 256 |
#define | STATIC_QUEUE_T(name, size) |
Create queue type with custom storage allocation size. | |
Functions | |
bool | queue_init (struct Queue *queue, uint8_t depth, uint8_t item_size) |
Initialize queue structure. | |
bool | queue_send (struct Queue *queue, const void *data) |
Send data via the queue. | |
bool | queue_send_silent (struct Queue *queue, const void *data) |
Fills queue without notifying receivers. | |
bool | queue_receive_timeout (struct Queue *queue, void *data, uint32_t timeout_us) |
Receive data from queue with timeout. | |
static bool | queue_receive (struct Queue *queue, void *data) |
Receive data from queue. | |
bool | queue_empty (struct Queue *queue) |
Returns queue status. | |
bool | queue_full (struct Queue *queue) |
Tell if queue is already full. | |
This is auxiliary implementation of queue.
CMRX does not offer queues as an inherent service provided by the kernel as this does not fit the microkernel nature of CMRX RTOS.
CMRX natively supports lower communication and synchronization primitives than queues.
This implementation offers single producer-single consumer safe implementation of queue that is usable even from interrupt context.
This library will find uses if you need to implement queue between threads of single process and/or you need to push data into queue from ISR handler.
If you need a queue that works across processes then see aux_queue_server which wraps this library into RPC interface and thus is usable globally.
#define QUEUE_LENGTH 256 |
#define STATIC_QUEUE_T | ( | name, | |
size | |||
) |
Create queue type with custom storage allocation size.
This is a helper macro that defines type for queue with developer-specified size of the queue data storage. Suitable for cases where fixed allocation size of 256 bytes of BasicQueue is either too much or too little.
name | resulting name of queue variable |
size | size of the buffer in bytes |
bool queue_empty | ( | struct Queue * | queue | ) |
Returns queue status.
[in] | queue | pointer to queue queried |
bool queue_full | ( | struct Queue * | queue | ) |
Tell if queue is already full.
[in] | queue | pointer to queue queried |
bool queue_init | ( | struct Queue * | queue, |
uint8_t | depth, | ||
uint8_t | item_size | ||
) |
Initialize queue structure.
This call will initialize queue structure. It does not examine previous state of the structure, thus any previous existing state is erased.
[in] | queue | pointer to queue being initialized |
[in] | depth | amount of entries queue should be able to store |
[in] | item_size | size of each item in bytes |
|
inlinestatic |
Receive data from queue.
This will copy the oldest data out of the queue. If queue is empty then this call will block until queue is filled with at least one entry of data.
[in] | queue | pointer to queue data is retrieved from |
[out] | data | pointer to place where data will be written |
bool queue_receive_timeout | ( | struct Queue * | queue, |
void * | data, | ||
uint32_t | timeout_us | ||
) |
Receive data from queue with timeout.
This will copy the oldest data out of the queue. If queue is empty then this call will block until queue is filled with data or until specified amount of time passed with no new data in the queue.
[in] | queue | pointer to queue data is retrieved from |
[out] | data | pointer to place where data will be written |
[in] | timeout_us | amount of time to wait for the data. If 0 is passed as timeout, then the function will wait indefinitely. |
bool queue_send | ( | struct Queue * | queue, |
const void * | data | ||
) |
Send data via the queue.
This will copy data into queue. Queue must be initialized before this call is made. The size of data is determined based on value of item_size
used during queue initialization.
[in] | queue | pointer to queue data is being sent into |
[in] | data | pointer to data |
bool queue_send_silent | ( | struct Queue * | queue, |
const void * | data | ||
) |
Fills queue without notifying receivers.
This method performs the same action as queue_send() without actually performing notification of clients waiting for queue data to be available. This function may be useful e.g. in the interrupt context where calling notify_object() is not possible.
queue | pointer to queue data is being sent into | |
[in] | data | pointer to data |