OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
Loading...
Searching...
No Matches
can_buffer_fifo.h File Reference

Circular FIFO queue for can_msg_t pointers. More...

Go to the source code of this file.

Functions

void CanBufferFifo_initialize (void)
 Clears all FIFO slots and resets head and tail to zero.
 
bool CanBufferFifo_push (can_msg_t *new_msg)
 Pushes a can_msg_t pointer onto the tail of the FIFO.
 
can_msg_tCanBufferFifo_pop (void)
 Removes and returns the oldest can_msg_t from the FIFO.
 
uint8_t CanBufferFifo_is_empty (void)
 Returns non-zero if the FIFO is empty, zero if messages are present.
 
uint16_t CanBufferFifo_get_allocated_count (void)
 Returns the number of can_msg_t pointers currently in the FIFO.
 

Detailed Description

Circular FIFO queue for can_msg_t pointers.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Messages are allocated from CanBufferStore and pushed here for ordered processing. Uses one extra slot so head == tail always means empty.

Author
Jim Kueneman
Date
4 Mar 2026

Function Documentation

◆ CanBufferFifo_initialize()

void CanBufferFifo_initialize ( void )
extern

Clears all FIFO slots and resets head and tail to zero.

Warning
Must be called once at startup before any push or pop.
NOT thread-safe.
See also
CanBufferStore_initialize - must be called first

Algorithm:

  1. Set all LEN_CAN_FIFO_BUFFER pointer slots to NULL.
  2. Reset head and tail indices to zero.

◆ CanBufferFifo_push()

bool CanBufferFifo_push ( can_msg_t * new_msg)
extern

Pushes a can_msg_t pointer onto the tail of the FIFO.

Parameters
new_msgPointer to an allocated can_msg_t.
Returns
true on success, false if the FIFO is full.
Warning
Returns false when full - dropped messages are not recoverable.
NOT thread-safe - use shared resource locking.
See also
CanBufferFifo_pop

Algorithm:

  1. Compute next head position with wraparound.
  2. If next != tail (not full): store pointer, advance head, return true.
  3. Otherwise return false (FIFO full).
* @param new_msg Pointer to an allocated @ref can_msg_t.
* 
Returns
true on success, false if the FIFO is full.

◆ CanBufferFifo_pop()

can_msg_t * CanBufferFifo_pop ( void )
extern

Removes and returns the oldest can_msg_t from the FIFO.

Caller is responsible for freeing the returned buffer with CanBufferStore_free_buffer() when processing is complete.

Returns
Pointer to the oldest can_msg_t, or NULL if the FIFO is empty.
Warning
Returns NULL when empty - caller MUST check before use.
Caller MUST free the buffer after processing.
NOT thread-safe - use shared resource locking.
See also
CanBufferStore_free_buffer

Algorithm:

  1. If head != tail (not empty): save pointer at tail, clear slot, advance tail with wraparound, return saved pointer.
  2. Otherwise return NULL (FIFO empty).
Returns
Pointer to the oldest can_msg_t, or NULL if the FIFO is empty.

◆ CanBufferFifo_is_empty()

uint8_t CanBufferFifo_is_empty ( void )
extern

Returns non-zero if the FIFO is empty, zero if messages are present.

◆ CanBufferFifo_get_allocated_count()

uint16_t CanBufferFifo_get_allocated_count ( void )
extern

Returns the number of can_msg_t pointers currently in the FIFO.

Handles the wraparound case where tail > head.

Returns
Current FIFO occupancy count.

Copyright (c) 2026 Jim Kueneman all rights reserved. See the License