| ??? 12/26/07 22:20 Read: times |
#148750 - single, double and ring buffer Responding to: ???'s previous message |
a ring buffer is just the recipe. As you always say, ring buffer is heavy. Then, depending on the protocol on the RS232, simpler buffering, like single buffer or double buffer, is applied. For example, The PC doesn't send next command packet until the device returns acknowledge over RS232. In this case, a single buffer of the max command packet size is enough to handle the UART RX. When the device receives the entire packet on the buffer, the ISR sets a flag to notify it to the main-loop task. The main-loop task handles the packet, clears the buffer index and the flag, and returns acknowledge to the PC. Another example, The PC sends data packets of fixed length to the device continuously. A double buffer of the packet length each will handle this data stream. While the main-loop task handles the last packet in one buffer, the ISR receives current packet into another buffer. When the entire packet is received, the ISR swaps the buffer and notify it to the main-loop task. Tsuneo |



