electroRF
Member
Hi,
I'd love to share the problem I have with a Shared Circular Buffer between two uCs that is used for sending Messages between them.
Each uC holds Tail and Head Indexes for the Shared Circular Buffer, which are initialized to zero.
When one uC wants to send a message to another uC, it puts the Message in the Buffer and Interrupts the other uC.
Now, the other uC knows to look for the message in its Tail Index (it'd know the length of the Message since it's located at the beginning of the message as a rule between the two uCs).
I hope the Mechanism is clear.
I'm debugging a problem I got with the Mechanism and I think that this is what happened.
One of the uC sent Message to the other uC.
the other uC was still occupied with a high-priority task, and therefore did not read the Message yet until it finished handling that task.
In the meantime, the uC sent another 2 Messages to the other uC.
Only now, having 3 pending Messages waiting for it in the buffer, the other uC turned to read the Messages from the Buffer.
What happened was the the other uC read garbage.
I'm afraid the these 3 Messages exceeded the length of the Buffer (which is Circular), and therefore the 3rd Message ran over the 1st Message;
For that reason, the 1st Message looked like garbage to the other uC when it turned to read it.
How could I overcome such situation?
Increasing the Shared Circular Buffer is not an ideal solution since it could still happen.
Thank you.
I'd love to share the problem I have with a Shared Circular Buffer between two uCs that is used for sending Messages between them.
Each uC holds Tail and Head Indexes for the Shared Circular Buffer, which are initialized to zero.
When one uC wants to send a message to another uC, it puts the Message in the Buffer and Interrupts the other uC.
Now, the other uC knows to look for the message in its Tail Index (it'd know the length of the Message since it's located at the beginning of the message as a rule between the two uCs).
I hope the Mechanism is clear.
I'm debugging a problem I got with the Mechanism and I think that this is what happened.
One of the uC sent Message to the other uC.
the other uC was still occupied with a high-priority task, and therefore did not read the Message yet until it finished handling that task.
In the meantime, the uC sent another 2 Messages to the other uC.
Only now, having 3 pending Messages waiting for it in the buffer, the other uC turned to read the Messages from the Buffer.
What happened was the the other uC read garbage.
I'm afraid the these 3 Messages exceeded the length of the Buffer (which is Circular), and therefore the 3rd Message ran over the 1st Message;
For that reason, the 1st Message looked like garbage to the other uC when it turned to read it.
How could I overcome such situation?
Increasing the Shared Circular Buffer is not an ideal solution since it could still happen.
Thank you.