QUEUE_LIB Embedded C library v1.0.0
Macros | Functions
queue.c File Reference

Generic FIFO queue implementation for embedded safety-critical use. More...

#include "queue.h"
Include dependency graph for queue.c:

Macros

#define PRIVATE   static
 

Functions

PRIVATE void copy_bytes (uint8_t *dst, const uint8_t *src, uint16_t size)
 Deterministic byte-wise copy of memory. More...
 
queue_status_t queue_init (queue_t *q, void *buffer, uint16_t element_size, uint16_t capacity)
 Initialize a queue. More...
 
queue_status_t queue_push (queue_t *q, const void *item)
 Push an element into the queue. More...
 
queue_status_t queue_pop (queue_t *q, void *item)
 Pop an element from the queue. More...
 
bool queue_is_empty (const queue_t *q)
 Check whether queue is empty. More...
 
bool queue_is_full (const queue_t *q)
 Check whether queue is full. More...
 

Detailed Description

Generic FIFO queue implementation for embedded safety-critical use.

Version
1.0.2
Date
2025-10-26

Provides deterministic enqueue/dequeue operations on a caller-supplied memory buffer. Implementation uses explicit byte-wise copying and avoids standard library dependencies to ensure deterministic behavior.

MISRA Deviation: DV-QUEUE-001 (Rule 11.4) Controlled cast from void* to uint8_t* for raw byte access. Safe because data is not type-reinterpreted.

Note
Internal helper function copy_bytes(uint8_t*, const uint8_t*, uint16_t) is tested indirectly via DV_QUEUE_001 unit tests, including:
  • pushing/popping int, struct, char array elements,
  • wrap-around behavior,
  • zero-byte edge case,
  • NULL pointer handling.

Macro Definition Documentation

◆ PRIVATE

#define PRIVATE   static

Function Documentation

◆ copy_bytes()

PRIVATE void copy_bytes ( uint8_t *  dst,
const uint8_t *  src,
uint16_t  size 
)

Deterministic byte-wise copy of memory.

Parameters
[out]dstDestination buffer.
[in]srcSource buffer.
[in]sizeNumber of bytes to copy.

Used internally by queue_push/queue_pop to implement type-agnostic element storage. The PRIVATE macro controls visibility:

  • static in production builds
  • non-static in UNIT_TESTS build for test coverage
Note
MISRA Deviation DV-QUEUE-001: controlled cast for raw memory access.
Branch with NULL pointers is exercised indirectly in unit tests DV_QUEUE_001.
Here is the caller graph for this function:

◆ queue_init()

queue_status_t queue_init ( queue_t q,
void *  buffer,
uint16_t  element_size,
uint16_t  capacity 
)

Initialize a queue.

Parameters
[in,out]qPointer to queue control structure.
[in]bufferPointer to storage buffer.
[in]element_sizeElement size in bytes (>0).
[in]capacityNumber of elements (>0).
Return values
QUEUE_OKSuccessful initialization.
QUEUE_ERRORInvalid parameters.

◆ queue_is_empty()

bool queue_is_empty ( const queue_t q)

Check whether queue is empty.

Parameters
[in]qPointer 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]qPointer to queue instance.
Returns
true if full, false otherwise.

◆ queue_pop()

queue_status_t queue_pop ( queue_t q,
void *  item 
)

Pop an element from the queue.

Parameters
[in,out]qPointer to queue instance.
[out]itemPointer to destination buffer.
Return values
QUEUE_OKSuccess.
QUEUE_EMPTYQueue empty.
QUEUE_ERRORInvalid parameters.
Here is the call graph for this function:

◆ queue_push()

queue_status_t queue_push ( queue_t q,
const void *  item 
)

Push an element into the queue.

Parameters
[in,out]qPointer to queue instance.
[in]itemPointer to data to add (element_size bytes).
Return values
QUEUE_OKSuccess.
QUEUE_FULLQueue full.
QUEUE_ERRORInvalid parameters.
Here is the call graph for this function: