Atmel Software Framework

Quick start guide for First-In-First-Out Buffer (FIFO)

This is the quick start guide for the First-In-First-Out Buffer (FIFO), with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

FIFO use cases

Basic use case - Push and pull

In this use case, an element will be pushed to the FIFO, and the same element will be pulled from it.

Setup steps

Example code

The following must be added to the project:

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

Add to application initialization:

union buffer_element fifo_buffer[FIFO_BUFFER_LENGTH];
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:
  2. Create a FIFO buffer descriptor that contains 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;
uint8_t pull_value;
status = fifo_push_uint8(&fifo_desc, PUSH_VALUE & 0xff);
status = fifo_pull_uint8(&fifo_desc, &pull_value);

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:
    • uint8_t pull_value;
  3. Put a new 8-bit element into the FIFO:
    • status = fifo_push_uint8(&fifo_desc, PUSH_VALUE & 0xff);
      Note
      The status variable will contain FIFO_OK if no error occurred.
  4. Get the 8-bit element from the FIFO:
    • status = fifo_pull_uint8(&fifo_desc, &pull_value);
      Note
      The status variable will contain FIFO_OK if no error occurred.