KM3NeT CLB
2.0
KM3NeT CLB v2 Embedded Software
|
A variable length queue implementation. More...
#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | VarQueue |
Variable length queue structure. More... | |
Macros | |
#define | VQ_INIT(NAME, SIZE) |
Initializes the variable length queue. More... | |
Functions | |
bool | vqQueue (VarQueue *const vq, uint16_t length, uint8_t *buffer) |
Queues an element on the queue. More... | |
bool | vqDeQueue (VarQueue *const vq, uint16_t *length, uint8_t *buffer) |
DeQueues an element from the queue. More... | |
bool | vqPeek (VarQueue *const vq, uint16_t *length, uint8_t *buffer) |
Peeks an element from the queue. More... | |
bool | vqRemove (VarQueue *const vq) |
Removes the first element from the queue (not the last). More... | |
uint16_t | vqDeQueueLength (VarQueue *const vq) |
Returns the lenght of the next element to dequeue. More... | |
uint16_t | vqFree (VarQueue *const vq) |
Returns the number of bytes free for the next element. More... | |
static void | vqReset (VarQueue *const vq) |
Resets the queue, such that is is empty. More... | |
A variable length queue implementation.
Queue is currently limited to 16 bits, e.g. it can not be larger than 64K.
To create a queue you will first need to initialize the a byte array, and configure the VarQueue structure, like this:
Note that the actual capacity of the queue is less, since each element requires a 2 byte header. So, you can store one 1022 sized element in the queue above, or two 510 sized elements, etc...
The code above is also written down my the VQ_INIT function, which you may also use.
Definition in file varqueue.h.
#define VQ_INIT | ( | NAME, | |
SIZE | |||
) |
Initializes the variable length queue.
NAME | Variable name of the queue structure. A byte array named NAME_mem will be created as heap. |
SIZE | The size of the queue in bytes. |
Definition at line 66 of file varqueue.h.
bool vqDeQueue | ( | VarQueue *const | vq, |
uint16_t * | length, | ||
uint8_t * | buffer | ||
) |
DeQueues an element from the queue.
vq | Pointer to the queue structure. |
length | Pointer containing the length of the buffer. On return this will be filled with the actual length of the element. |
buffer | The buffer to copy into. |
true | Element was dequeued and is now in the buffer false Element was not dequeued, either the length of the buffer is not sufficient or there is no element in the queue. |
Definition at line 50 of file varqueue.c.
uint16_t vqDeQueueLength | ( | VarQueue *const | vq | ) |
Returns the lenght of the next element to dequeue.
vq | The pointer to the queue structure. |
Definition at line 108 of file varqueue.c.
uint16_t vqFree | ( | VarQueue *const | vq | ) |
Returns the number of bytes free for the next element.
The header is already substracted from this number, so this is really the number of bytes you can still put into the queue.
vq | The pointer to the queue structure. |
Definition at line 114 of file varqueue.c.
bool vqPeek | ( | VarQueue *const | vq, |
uint16_t * | length, | ||
uint8_t * | buffer | ||
) |
Peeks an element from the queue.
The actual element is not removed from the queue.
vq | Pointer to the queue structure. |
length | Pointer containing the length of the buffer. On return this will be filled with the actual length of the element. |
buffer | The buffer to copy into. |
true | Element was dequeued and is now in the buffer false Element was not dequeued, either the length of the buffer is not sufficient |
bool vqQueue | ( | VarQueue *const | vq, |
uint16_t | length, | ||
uint8_t * | buffer | ||
) |
Queues an element on the queue.
vq | Pointer to the variable queue structure |
length | length of the element in the buffer |
buffer | The buffer to copy the element from |
true | Element was queued. false The element was not queued (out of space?). |
Definition at line 24 of file varqueue.c.
bool vqRemove | ( | VarQueue *const | vq | ) |
Removes the first element from the queue (not the last).
vq | The pointer to the queue structure. |
true | Element was removed. false Element was not removed because the queue was already empty. |
Definition at line 98 of file varqueue.c.
|
inlinestatic |
Resets the queue, such that is is empty.
vq | Pointer the the variable queue element. |
Definition at line 150 of file varqueue.h.