Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: CReese on April 16, 2014, 06:08:58 PM
-
Hello,
I'm streaming in message data into a bunch of arrays. For example, I have a 15-byte message that I have in arrays named after what each byte means:
ByteONE0-255
ByteTWO0-255
...
Each time I read a message, I MOVER the range, e.g. move 255 bytes from ByteONE0 to ByteONE1, and plop the new message into the the zeroth position.
So I've got a FIFO queue .. what's the best way to read it? I've created an auxiliary array, MsgProcStat0-255, that I can use to store status info, like 0="unprocessed", 1="read and processed", 2="read and error", etc.
So I need to start at the end of the array and move forward, processing messages as they need to be. How do I:
a) Do this quickly
b) Avoid race conditions where a message is inserted while the processor moves to the next message that needs to be processed?
Given the message receipt rate, I could probably get away with requiring processing before the next message is read, but this doesn't seem like the most elegant solution. I'm sure this is an age-old problem.
Thanks,
Colin
-
If it were me, I'd probably set up three arrays.
1) This is the main FIFO array
2) This is input buffer #1
3) This is input buffer #2
When I first receive a message I flag the transfer program that I need to start the transfer for #2 to #1. I then switch my receive buffer to #3.
After I get done processing #2, if I have messages in #3, then I set the flag to process #3 and go back to receiving on #2.
Flippity, floppity, back and forth keeping track of how many messages I need to process in each buffer as I move back and forth between them.
But like all programming solutions there are a few dozen other ways to skin this cat.
-
Every time you do a MOVER, you can:
MATH
V100
if(V100<MyMaxBufferLength,V100+1,MyMaxBufferLength)
Now you can start your message viewer at Message[V100].
Edge trigger this rung to view:
STRPRINT
SL_MyDisplay
"Message[v100]"
MATH
V100
if(v100>=1,V100-1,0)