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
};
Add to application initialization:
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:
- 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:
uint8_t status;
bool fifo_empty;
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.