electroRF
Member
Hi,
I'm got a 10KB buffer in a small memory, and I divide it into 2 equal halves.
I write data to it on real time.
Every time I cross to from one half another, I trigger a DMA to transfer the previous half to a large memory.
Every time I write to the 10KB buffer, I reserve in advance (atomic operation) the length of the data to be written, and only then I write it.
That is in order to protect every data from being overridden in case it's interrupted by other data.
The problem is that:
It occurred to me a few times that when I came to write a message A to the 10KB buffer in the end of the top half (i.e. just before crossing to the bottom half) I was interrupted by another message B, and therefore didn't finish yet to write message A.
Message B already crossed to the bottom half, and triggered the DMA to transfer the top half.
Now, before the uC returned to complete Message A (which is in the end of the top half), the DMA already transferred the top half (it took the uC "too long" to get back and finish writing message A).
Therefore, what happens here is that the DMA lost message A, since message A was written completely only AFTER the DMA finished transferring the top half.
How can I avoid losing messages in such way?
I cannot afford writing each message in atomic operation, because it'd damage the real-time functionality of the system (What I could afford was to reserve the length of the message in advance, in atomic operation)
Thank you very much.
I'm got a 10KB buffer in a small memory, and I divide it into 2 equal halves.
I write data to it on real time.
Every time I cross to from one half another, I trigger a DMA to transfer the previous half to a large memory.
Every time I write to the 10KB buffer, I reserve in advance (atomic operation) the length of the data to be written, and only then I write it.
That is in order to protect every data from being overridden in case it's interrupted by other data.
The problem is that:
It occurred to me a few times that when I came to write a message A to the 10KB buffer in the end of the top half (i.e. just before crossing to the bottom half) I was interrupted by another message B, and therefore didn't finish yet to write message A.
Message B already crossed to the bottom half, and triggered the DMA to transfer the top half.
Now, before the uC returned to complete Message A (which is in the end of the top half), the DMA already transferred the top half (it took the uC "too long" to get back and finish writing message A).
Therefore, what happens here is that the DMA lost message A, since message A was written completely only AFTER the DMA finished transferring the top half.
How can I avoid losing messages in such way?
I cannot afford writing each message in atomic operation, because it'd damage the real-time functionality of the system (What I could afford was to reserve the length of the message in advance, in atomic operation)
Thank you very much.