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
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_init(&fifo_desc, fifo_buffer, FIFO_BUFFER_LENGTH);
Workflow
- 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];
- 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:
- Initialize the FIFO:
fifo_init(&fifo_desc, fifo_buffer, FIFO_BUFFER_LENGTH);
Usage steps
Example code
Add to application C-file:
Workflow
- Create a variable to hold the return status from the FIFO:
- Create a variable to hold the pulled value from the FIFO:
- Put a new 8-bit element into the FIFO:
-
- Note
- The status variable will contain FIFO_OK if no error occurred.
- Get the 8-bit element from the FIFO:
-
- Note
- The status variable will contain FIFO_OK if no error occurred.