Deterministic FIFO queue for safety-critical embedded systems.
More...
|
| file | queue.c |
| | Generic FIFO queue implementation for embedded safety-critical use.
|
| |
Deterministic FIFO queue for safety-critical embedded systems.
This module provides a generic, deterministic, and type-agnostic FIFO queue implementation suitable for use in MISRA-C and ISO 26262 compliant projects.
- See also
- MISRA Compliance
MISRA Compliance
Overview
This module is developed with awareness of MISRA-C:2012 guidelines and is suitable for use in ISO 26262 safety-related applications.
The implementation avoids dynamic memory allocation, recursion, and non-deterministic library calls. All memory accesses are bounded and validated before use.
Controlled Deviations
| ID | Rule | Description | Justification |
| DV-QUEUE-001 | MISRA-C:2012 Rule 11.4 | Cast between void* and uint8_t* for raw byte copying. | Controlled and justified cast, no aliasing or type reinterpretation. Enables a generic queue implementation. Tested indirectly via DV_QUEUE_001 unit tests, including NULL and edge cases. |
- See also
- docs/compliance/MISRA_Deviations.md
Verification
- Static analysis with MISRA checker: PASSED (no critical violations)
- Unit tests (DV_QUEUE_001): cover int, struct, char array, wrap-around, zero-byte elements, NULL pointer handling
- Code review: APPROVED by Software Safety Architect
◆ queue_status_t
Queue operation status codes.
| Enumerator |
|---|
| QUEUE_OK | Operation completed successfully.
|
| QUEUE_FULL | Queue full — push failed.
|
| QUEUE_EMPTY | Queue empty — pop failed.
|
| QUEUE_ERROR | General error — invalid parameters.
|
◆ queue_init()
| queue_status_t queue_init |
( |
queue_t * |
q, |
|
|
void * |
buffer, |
|
|
uint16_t |
buffer_element_size, |
|
|
uint16_t |
queue_capacity |
|
) |
| |
Initialize a queue instance.
- Parameters
-
| [in,out] | q | Pointer to queue control structure. |
| [in] | buffer | Pointer to caller-supplied storage buffer. |
| [in] | buffer_element_size | Element size in bytes (must > 0). |
| [in] | queue_capacity | Number of elements in queue (must > 0). |
- Return values
-
| QUEUE_OK | Initialization succeeded. |
| QUEUE_ERROR | Invalid arguments (NULL or 0). |
- Note
- Deterministic and reentrant.
◆ queue_is_empty()
| bool queue_is_empty |
( |
const queue_t * |
q | ) |
|
Check if queue is empty.
- Parameters
-
| [in] | q | Pointer to queue instance. |
- Returns
- true — queue empty or q is NULL.
-
false — otherwise.
◆ queue_is_full()
| bool queue_is_full |
( |
const queue_t * |
q | ) |
|
Check if queue is full.
- Parameters
-
| [in] | q | Pointer to queue instance. |
- Returns
- true — queue full.
-
false — otherwise (including q is NULL).
◆ queue_pop()
Pop (dequeue) one element from the queue.
- Parameters
-
| [in,out] | q | Pointer to queue instance. |
| [out] | item | Pointer to destination buffer to store element. |
- Return values
-
| QUEUE_OK | Success. |
| QUEUE_EMPTY | Queue empty — no element available (item unchanged). |
| QUEUE_ERROR | Invalid parameters. |
- Note
- Deterministic; no blocking.
◆ queue_push()
Push (enqueue) one element into the queue.
- Parameters
-
| [in,out] | q | Pointer to queue instance. |
| [in] | item | Pointer to element data to add. |
- Return values
-
| QUEUE_OK | Success. |
| QUEUE_FULL | Queue already full. |
| QUEUE_ERROR | Invalid parameters. |
- Note
- Deterministic; no blocking.