FIFO Buffer (Circular/ring buffer) for packet storage
//pseudo algorithm First In First Out
    int FIFO[16]; // size of 2^N
    int WR_Ptr, RD_Ptr; // Write and read pointer
    int Input, Output;

    // On write event
    FIFO[WR_Ptr] = Input;
    WR_Ptr++; //increment WR pointer
    WR_Ptr &amp;= 15 // apply mask 2^N-1, turn over in circular manner
    if WR_Ptr==RD_Ptr //buffer overrun?
    {
       //handle error
    }

    //On read event
    if WR_Ptr&lt;&gt;RD_Ptr //check if FIFO is not empty
    {
      Output = FIFO[RD_Ptr];
      RD_Ptr++; //increment RD pointer
      RD_Ptr &amp;= 15 // apply mask 2^N-1, turn over in circular manner
    }

//clear FIFO
RD_Ptr = 0;
WR_Ptr = 0;