I have a typical two-wires RS485 network with multiple nodes. Only one node (the master) can start a communication: it sends a packet/request and receives a packet/answer. Usually the slaves can't communicate without the help of the master.
The slaves could be different, so running a different firmware on different CPUs. Of course, all the slaves understand a common protocol (syntax of packets). I'm trying to organize the firmware of a slave and I have problems to define the size of the receiving buffer.
Typically the bytes received are stored in a fifo buffer inside the ISR. During main loop, the FIFO is spooled for a new complete packet to decode and process. What is the size of the buffer to avoid missing packets? I can't answer.
Suppose this sequence: - master sends packet P1 to slave 1 - slave 1 answers after 10ms with packet P2 - master sends packet P3 to slave 2 after 10ms
I'm writing the firmware of slave 2. I could miss P1 and/or P2 packets, because they aren't for slave 2, but I need to process P3. Consider that I have a subroutine running on slave 2 that lasts 100ms. So, if I'm not lucky, I can enter this subroutine just before receiving the first byte of P1. During the subroutine, all the 3 packets appears on the network and should be buffered. So I need the space for 3 packets.
It seems the size of the rx fifo buffer of a slave depends on the maximum packet size that could appear on the network (even a request for
*another* slave or a slave answer), how fast are *other* slaves to answer and how fast is the master to start a new communication.If there is a very fast slave that manages very big packets (super-computer) and very slow slave that manages very small packets (small 8-bit microcontrollers) how to tune the rx fifo buffer? I could arrive to a very big buffer size that isn't compatible to the small CPU.
Should I limit the maximum packet size, even for the supercomputer (this could be acceptable)? Should I delay the new communication from the master to let the slow slaves to process the previous request/answer packets (this could be annoying, because the time of a poll of all the slaves on the network increases)?
Any suggestion?