Platform-neutral blocking RTOS queues.
#include "etcpal/queue.h"
Provides a platform-neutral API to RTOS queue functionality.
#include "etcpal/queue.h"
typedef struct Foo
{
int value;
} Foo;
void main_task(void* arg)
{
{
return;
}
while (true)
{
Foo foo;
{
printf("Got new Foo with value %d\n", foo.value);
}
else
{
printf("Error receiving from queue.\n");
}
}
}
void interrupt_handler(void)
{
Foo foo;
foo.value = REG_READ();
}
const char * etcpal_strerror(etcpal_error_t code)
Get a string representation of an error code.
Definition: error.c:69
etcpal_error_t
A set of error codes that can be returned by library functions.
Definition: error.h:49
@ kEtcPalErrOk
The call was successful, no error occurred.
Definition: error.h:51
bool etcpal_queue_send_from_isr(etcpal_queue_t *id, const void *data)
Add an item to a queue from an interrupt context.
Definition: queue.c:321
PLATFORM_DEFINED etcpal_queue_t
The queue identifier.
Definition: queue.dox:85
bool etcpal_queue_receive(etcpal_queue_t *id, void *data)
Retrieve the first item from a queue.
Definition: queue.c:297
void etcpal_queue_destroy(etcpal_queue_t *id)
Destroy a queue.
Definition: queue.c:241
bool etcpal_queue_create(etcpal_queue_t *id, size_t size, size_t item_size)
Create a new queue.
Definition: queue.c:194
There are also functions for sending and receiving with a timeout, and for checking to see if the queue is empty.
Queues are implemented using native constructs on RTOS platforms, and using other EtcPal constructs such as semaphores on full OS platforms. The current availability is as follows:
IMPORTANT NOTES FOR ZEPHYR USERS: Some EtcPal features are dependent on Zephyr configuration see: Targeting Zephyr
|
bool | etcpal_queue_create (etcpal_queue_t *id, size_t size, size_t item_size) |
| Create a new queue. More...
|
|
bool | etcpal_queue_create_static (etcpal_queue_t *id, size_t size, size_t item_size, uint8_t *buffer) |
| Create a new queue with a buffer provided by the user. More...
|
|
void | etcpal_queue_destroy (etcpal_queue_t *id) |
| Destroy a queue. More...
|
|
bool | etcpal_queue_send (etcpal_queue_t *id, const void *data) |
| Add an item to a queue. More...
|
|
bool | etcpal_queue_timed_send (etcpal_queue_t *id, const void *data, int timeout_ms) |
| Add an item to a queue, giving up after a timeout. More...
|
|
bool | etcpal_queue_send_from_isr (etcpal_queue_t *id, const void *data) |
| Add an item to a queue from an interrupt context. More...
|
|
bool | etcpal_queue_receive (etcpal_queue_t *id, void *data) |
| Retrieve the first item from a queue. More...
|
|
bool | etcpal_queue_timed_receive (etcpal_queue_t *id, void *data, int timeout_ms) |
| Retrieve the first item from a queue, giving up after a timeout. More...
|
|
bool | etcpal_queue_receive_from_isr (etcpal_queue_t *id, void *data) |
| Retrieve the first item from a queue from an interrupt context. More...
|
|
bool | etcpal_queue_reset (const etcpal_queue_t *id) |
| Resets queue to empty state. More...
|
|
bool | etcpal_queue_is_empty (const etcpal_queue_t *id) |
| Determine whether a queue is currently empty. More...
|
|
bool | etcpal_queue_is_empty_from_isr (const etcpal_queue_t *id) |
| Determine whether a queue is currently empty from an interrupt context. More...
|
|
bool | etcpal_queue_is_full (const etcpal_queue_t *id) |
| Determine whether a queue is currently full. More...
|
|
bool | etcpal_queue_is_full_from_isr (const etcpal_queue_t *id) |
| Determine whether a queue is currently full from an interrupt context. More...
|
|
size_t | etcpal_queue_slots_used (const etcpal_queue_t *id) |
| Get number of slots being stored in the queue. More...
|
|
size_t | etcpal_queue_slots_used_from_isr (const etcpal_queue_t *id) |
| Get number of slots being stored in the queue from an interrupt context. More...
|
|
size_t | etcpal_queue_slots_available (const etcpal_queue_t *id) |
| Get number of remaining slots in the queue. More...
|
|
◆ ETCPAL_QUEUE_HAS_ISR_FUNCTIONS
#define ETCPAL_QUEUE_HAS_ISR_FUNCTIONS /* platform-defined */ |
◆ ETCPAL_QUEUE_HAS_STATIC
#define ETCPAL_QUEUE_HAS_STATIC /* platform-defined */ |
◆ ETCPAL_QUEUE_HAS_TIMED_FUNCTIONS
#define ETCPAL_QUEUE_HAS_TIMED_FUNCTIONS /* platform-defined */ |
◆ etcpal_queue_t
The queue identifier.
Depending on the platform, this could be a scalar type or a struct.
◆ etcpal_queue_create()
bool etcpal_queue_create |
( |
etcpal_queue_t * |
id, |
|
|
size_t |
size, |
|
|
size_t |
item_size |
|
) |
| |
Create a new queue.
- Parameters
-
[out] | id | Queue identifier on which to create a queue. If this function returns true, id becomes valid for calls to other etcpal_queue API functions. |
[in] | size | The maximum number of items that can be held in the queue. |
[in] | item_size | The size in bytes of the item type to be held in the queue. |
- Returns
- true: The queue was created.
-
false: The queue was not created.
◆ etcpal_queue_create_static()
bool etcpal_queue_create_static |
( |
etcpal_queue_t * |
id, |
|
|
size_t |
size, |
|
|
size_t |
item_size, |
|
|
uint8_t * |
buffer |
|
) |
| |
Create a new queue with a buffer provided by the user.
- Parameters
-
[out] | id | Queue identifier on which to create a queue. If this function returns true, id becomes valid for calls to other etcpal_queue API functions. |
[in] | size | The maximum number of items that can be held in the queue. |
[in] | item_size | The size in bytes of the item type to be held in the queue. |
[in] | buffer | The buffer to use for the queue. |
- Returns
- true: The queue was created.
-
false: The queue was not created.
◆ etcpal_queue_destroy()
Destroy a queue.
Frees the queue's resources back to the operating system.
- Parameters
-
[in] | id | Identifier for the queue to destroy. |
◆ etcpal_queue_is_empty()
Determine whether a queue is currently empty.
- Parameters
-
[in] | id | Identifier for the queue to check the status of. |
- Returns
- true: The queue is empty.
-
false: The queue is not empty.
◆ etcpal_queue_is_empty_from_isr()
Determine whether a queue is currently empty from an interrupt context.
This function is meaningful on platforms which have a different method for interacting with queues from an interrupt context.
- Parameters
-
[in] | id | Identifier for the queue to check the status of. |
- Returns
- true: The queue is empty.
-
false: The queue is not empty.
◆ etcpal_queue_is_full()
Determine whether a queue is currently full.
- Parameters
-
[in] | id | Identifier for the queue to check the status of. |
- Returns
- true: The queue is full.
-
false: The queue is not full.
◆ etcpal_queue_is_full_from_isr()
Determine whether a queue is currently full from an interrupt context.
This function is meaningful on platforms which have a different method for interacting with queues from an interrupt context.
- Parameters
-
[in] | id | Identifier for the queue to check the status of. |
- Returns
- true: The queue is full.
-
false: The queue is not full.
◆ etcpal_queue_receive()
Retrieve the first item from a queue.
Blocks until there is an item available to retrieve from the queue.
- Parameters
-
[in] | id | Identifier for the queue from which to retrieve an item. |
[out] | data | Pointer to a location to write the object's data. Must not be NULL. |
- Returns
- true: Item retrieved successfully.
-
false: Error occurred while trying to retrieve an item from the queue.
◆ etcpal_queue_receive_from_isr()
bool etcpal_queue_receive_from_isr |
( |
etcpal_queue_t * |
id, |
|
|
void * |
data |
|
) |
| |
Retrieve the first item from a queue from an interrupt context.
This function is meaningful on platforms which have a different method for interacting with queues from an interrupt context. This function never blocks, i.e. the behavior is similar to calling etcpal_queue_timed_receive() with a value of 0 for the timeout_ms parameter.
- Parameters
-
[in] | id | Identifier for the queue from which to retrieve an item. |
[out] | data | Pointer to a location to write the object's data. Must not be NULL. |
- Returns
- true: Item retrieved successfully.
-
false: Error occurred while trying to retrieve an item from the queue.
◆ etcpal_queue_reset()
Resets queue to empty state.
- Parameters
-
[in] | id | Identifier for the queue to check the status of. |
- Returns
- true: On reset success.
-
false: On reset failure.
◆ etcpal_queue_send()
Add an item to a queue.
Blocks until there is room in the queue to add a new item.
- Parameters
-
[in] | id | Identifier for the queue to which to add an item. |
[in] | data | Pointer to item to add to the queue. Must not be NULL. |
- Returns
- true: Item added successfully.
-
false: An error occurred while trying to add an item to the queue.
◆ etcpal_queue_send_from_isr()
bool etcpal_queue_send_from_isr |
( |
etcpal_queue_t * |
id, |
|
|
const void * |
data |
|
) |
| |
Add an item to a queue from an interrupt context.
This function is meaningful on platforms which have a different method for interacting with queues from an interrupt context. This function never blocks, i.e. the behavior is similar to calling etcpal_queue_timed_send() with a value of 0 for the timeout_ms parameter.
- Parameters
-
[in] | id | Identifier for the queue to which to add an item. |
[in] | data | Pointer to item to add to the queue. Must not be NULL. |
- Returns
- true: Item added successfully.
-
false: Timeout or error occurred while trying to add an item to the queue.
◆ etcpal_queue_slots_available()
Get number of remaining slots in the queue.
- Parameters
-
[in] | id | Identifier for the queue to check the status of. |
- Returns
- Number of remaining slots in queue.
◆ etcpal_queue_slots_used()
Get number of slots being stored in the queue.
- Parameters
-
[in] | id | Identifier for the queue to check the status of. |
- Returns
- Number of slots in queue.
◆ etcpal_queue_slots_used_from_isr()
Get number of slots being stored in the queue from an interrupt context.
This function is meaningful on platforms which have a different method for interacting with queues from an interrupt context.
- Parameters
-
[in] | id | Identifier for the queue to check the status of. |
- Returns
- Number of slots in queue.
◆ etcpal_queue_timed_receive()
bool etcpal_queue_timed_receive |
( |
etcpal_queue_t * |
id, |
|
|
void * |
data, |
|
|
int |
timeout_ms |
|
) |
| |
Retrieve the first item from a queue, giving up after a timeout.
- Parameters
-
[in] | id | Identifier for the queue from which to retrieve an item. |
[out] | data | Pointer to a location to write the object's data. Must not be NULL. |
[in] | timeout_ms | Maximum amount of time to wait for an item to be available, in milliseconds. If ETCPAL_WAIT_FOREVER is given, the result is the same as if etcpal_queue_receive() was called. |
- Returns
- true: Item retrieved successfully.
-
false: Timeout or error occurred while trying to retrieve an item from the queue.
◆ etcpal_queue_timed_send()
bool etcpal_queue_timed_send |
( |
etcpal_queue_t * |
id, |
|
|
const void * |
data, |
|
|
int |
timeout_ms |
|
) |
| |
Add an item to a queue, giving up after a timeout.
- Parameters
-
[in] | id | Identifier for the queue to which to add an item. |
[in] | data | Pointer to item to add to the queue. Must not be NULL. |
[in] | timeout_ms | Maximum amount of time to wait for space to be available, in milliseconds. If ETCPAL_WAIT_FOREVER is given, the result is the same as if etcpal_queue_send() was called. |
- Returns
- true: Item added successfully.
-
false: Timeout or error occurred while trying to add an item to the queue.