![Interrupt Interrupt](/uploads/1/2/5/6/125649548/805069285.gif)
Implement two with head and tail pointers (indexes), large enough to accommodate throughput rates. Determine the minimum time the responder requires between requests and respect it.
Because the UART is the device used for serial communication, it is good to explain what it stands for. Probably the shortest definition would be that serial communication stands for the process of sending data one bit at a time, sequentially, through the bus or communication channel.
Each time you send a request add it to the first queue, the “request sent queue”. When a response arrives add it to the second queue in your interrupt routine and increment the head pointer. This is your “response received queue”. You can then process transactions asynchronously in your main loop. Compare the second queue head to its tail. Each time the second queue becomes imbalanced (head does not equal tail) you have received at least one response.
The first queue tells you the request it was a response to. Each time you complete processing a response advance the tail pointers of both queues. You probably want to reset the queues if you don’t get a response (if queues remain imbalanced for too long) and make sure the queues don't overwrite.