Deterministic, generic FIFO queue for embedded / safety-critical systems.
More...
#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
Deterministic, generic FIFO queue for embedded / safety-critical systems.
- Author
- niwciu (niwci.nosp@m.u@gm.nosp@m.ail.c.nosp@m.om)
- Version
- 1.0.2
- Date
- 2025-10-26
Queue interface designed to be MISRA-C:2012 aware and suitable for safety-critical applications (ISO 26262). Implementation uses a user-supplied raw data buffer (void *) to support multiple element types.
MISRA Deviation: DV-QUEUE-001 (Rule 11.4) Justified cast from void* to uint8_t* for byte-level memory operations.
- Note
- Caller is responsible for ensuring the provided buffer size is at least: (element_size * capacity) bytes, properly aligned for the element type.
-
Internal helper function
copy_bytes(uint8_t*, const uint8_t*, uint16_t) is exercised indirectly via unit tests in group DV_QUEUE_001 to cover all branches, including NULL pointer cases and edge conditions.
◆ queue_status_t
Queue operation status codes.
| Enumerator |
|---|
| QUEUE_OK | Operation completed successfully.
|
| QUEUE_FULL | Queue is full; push operation failed.
|
| QUEUE_EMPTY | Queue is empty; pop operation failed.
|
| QUEUE_ERROR | General error (invalid parameters, etc.).
|
◆ queue_init()
Initialize a queue.
- Parameters
-
| [in,out] | q | Pointer to queue control structure. |
| [in] | buffer | Pointer to storage buffer. |
| [in] | element_size | Element size in bytes (>0). |
| [in] | capacity | Number of elements (>0). |
- Return values
-
| QUEUE_OK | Successful initialization. |
| QUEUE_ERROR | Invalid parameters. |
◆ queue_is_empty()
| bool queue_is_empty |
( |
const queue_t * |
q | ) |
|
Check whether queue is empty.
- Parameters
-
| [in] | q | Pointer to queue instance. |
- Returns
- true if empty, false otherwise.
◆ queue_is_full()
| bool queue_is_full |
( |
const queue_t * |
q | ) |
|
Check whether queue is full.
- Parameters
-
| [in] | q | Pointer to queue instance. |
- Returns
- true if full, false otherwise.
◆ queue_pop()
Pop an element from the queue.
- Parameters
-
| [in,out] | q | Pointer to queue instance. |
| [out] | item | Pointer to destination buffer. |
- Return values
-
| QUEUE_OK | Success. |
| QUEUE_EMPTY | Queue empty. |
| QUEUE_ERROR | Invalid parameters. |
◆ queue_push()
Push an element into the queue.
- Parameters
-
| [in,out] | q | Pointer to queue instance. |
| [in] | item | Pointer to data to add (element_size bytes). |
- Return values
-
| QUEUE_OK | Success. |
| QUEUE_FULL | Queue full. |
| QUEUE_ERROR | Invalid parameters. |