The FIFO buffer is a first-in-first-out buffer area realized as a ring buffer. Data is stored in the order in which it is written to the buffer, and then read out in the order stored, starting from the first data item stored. It is convenient for buffering objects in sequential order.
The area to be used is defined as the FIFO buffer using FP_FIFO_DEFINE. (This should be done only once, before reading or writing is done.)
Data should be written to the buffer using FP_FIFO_WRITE, and read out of the buffer using FP_FIFO_READ.
When data is written, the data items are stored in sequential order, starting from the first data storage area. The writing pointer indicates the next area to which data is to be written. The number of words stored increases by 1.
If the data storage area becomes full, i.e. the number of words stored is equal to n-1, further data writing is inhibited.
When data is read, data is transferred starting from the first data item stored. The reading pointer indicates the next area from which data is to be read. The number of words stored decreases by 1.
An error occurs if an attempt is made to read data when the data storage area is empty, the number of words stored is equal to the memory size of the FIFO buffer or is equal to zero.
If data is written while the FIFO buffer is in the status shown below, the data will be stored in the area indicated by 3. The writing pointer moves to 4, i.e. the next data item will be written to 4. If data is read, it will be read from the area indicated by 0. The reading pointer then moves to 1, i.e. the next data item will be read from 1.