Microchip® Advanced Software Framework

Push and flush

In this use case, two elements will be pushed to the FIFO, and the FIFO will be flushed.

Setup steps

Example code

The following must be added to the project:

#define FIFO_BUFFER_LENGTH 4
#define PUSH_VALUE 0x12345678
union buffer_element {
uint8_t byte;
uint16_t halfword;
uint32_t word;
};

Add to application initialization:

union buffer_element fifo_buffer[FIFO_BUFFER_LENGTH];
fifo_desc_t fifo_desc;
fifo_init(&fifo_desc, fifo_buffer, FIFO_BUFFER_LENGTH);

Workflow

  1. Create a FIFO buffer of FIFO_BUFFER_LENGTH elements, capable of holding a byte, halfword or word:
    • union buffer_element fifo_buffer[FIFO_BUFFER_LENGTH];
  2. Create a FIFO buffer descriptor that containing information about the location of the FIFO buffer, its size and where to read from or write to upon the next buffer pull or push:
  3. Initialize the FIFO:
    • fifo_init(&fifo_desc, fifo_buffer, FIFO_BUFFER_LENGTH);

Usage steps

Example code

Add to application C-file:

uint8_t status;
bool fifo_empty;
status = fifo_push_uint16(&fifo_desc, PUSH_VALUE & 0xffff);
status = fifo_push_uint16(&fifo_desc, PUSH_VALUE & 0xffff);
fifo_flush(&fifo_desc);
fifo_empty = fifo_is_empty(&fifo_desc);

Workflow

  1. Create a variable to hold the return status from the FIFO:
  2. Create a variable to hold the pulled value from the FIFO:
    • uint16_t pull_value;
  3. Put two new 16-bit element into the FIFO:
  4. Flush the FIFO:
  5. Check that the FIFO is empty after flushing:
    • fifo_empty = fifo_is_empty(&fifo_desc);
      Note
      The fifo_empty variable will be true if the FIFO is empty.