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_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 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:
- 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 two new 16-bit element into the FIFO:
-
- Note
- The status variable will contain FIFO_OK if no error occurred.
- Flush the FIFO:
- Check that the FIFO is empty after flushing:
-
- Note
- The fifo_empty variable will be true if the FIFO is empty.