Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ( ESP32-FIFO.TXT )
- \ INTEGER FIFO BUFFER / QUEQE
- 3 VALUE BUFFER-SIZE \ <*********** Small test size!
- CREATE FIFOBUFFER BUFFER-SIZE CELLS ALLOT
- 0 VALUE NEXT-IN
- 0 VALUE NEXT-OUT
- 0 VALUE BUFFER-COUNT
- : CLEAR-FIFOBUFFER \ clear buffer
- 0 is NEXT-IN
- 0 is NEXT-OUT
- 0 is BUFFER-COUNT
- ;
- : >FIFOBUFFER ( n -- )
- BUFFER-COUNT BUFFER-SIZE =
- IF CR ." BUFFER is Full! IGNORED!" CR
- DROP \ !!!
- ELSE FIFOBUFFER NEXT-IN CELLS + !
- BUFFER-COUNT 1+ IS BUFFER-COUNT
- NEXT-IN 1+ is NEXT-IN
- NEXT-IN BUFFER-SIZE =
- IF 0 is NEXT-IN
- THEN
- THEN ;
- : >Q >FIFOBUFFER ;
- : FIFOBUFFER> ( -- n )
- BUFFER-COUNT 0 =
- IF CR ." BUFFER is Empty! IGNORED!" CR
- ELSE FIFOBUFFER NEXT-OUT CELLS + @
- BUFFER-COUNT 1- IS BUFFER-COUNT
- NEXT-OUT 1+ is NEXT-OUT
- NEXT-OUT BUFFER-SIZE =
- IF 0 is NEXT-OUT THEN
- THEN ;
- : Q> FIFOBUFFER> ;
- : BUFFER-PEEK ( -- n )
- BUFFER-COUNT 0 =
- IF CR ." BUFFER is Empty! IGNORED!" CR
- ELSE FIFOBUFFER NEXT-OUT CELLS + @
- THEN ;
- : PQ BUFFER-PEEK ; \ Peek Queue
- : BUFFER-FULL? ( -- flag ) BUFFER-COUNT BUFFER-SIZE = ;
- : BUFFER-EMPTY? ( -- flag ) BUFFER-COUNT 0= ;
- : BUFFER-DISPLAY ( -- )
- BUFFER-COUNT 0=
- IF CR ." Buffer is empty!" CR
- ELSE BUFFER-COUNT 0
- DO NEXT-OUT I + BUFFER-SIZE MOD CELLS
- FIFOBUFFER + @
- CR .
- LOOP
- THEN ;
- : ZQ BUFFER-DISPLAY ; \ "See Queue"
- \ EOF
- FIFO (First-In-First-Out) buffers are commonly used in computer programs,
- especially in data processing applications where data needs to be stored
- and retrieved in the order it was received.
- FIFO buffers are particularly useful in scenarios such as:
- Sensor data processing: FIFO buffers are used in sensor data processing applications
- where data from multiple sensors needs to be processed in real-time.
- The FIFO buffer helps to synchronize and organize the incoming sensor data.
- Data transmission: In communication systems, FIFO buffers are often employed
- to temporarily store incoming data before it is processed or transmitted further.
- This ensures that data is processed in the same order it was received,
- preventing data loss or misalignment.
- Task scheduling: FIFO buffers can be used in task scheduling algorithms where tasks are
- executed in the order they were received.
- This ensures fairness and maintains the order of task execution.
- Overall, FIFO buffers are a fundamental data structure in computer programming and are widely used in
- various applications to manage and process data in a sequential manner.
Advertisement
Add Comment
Please, Sign In to add comment