Hi...i am tring to copy memory from sram to sdram using dma.For some reason some of the data dosent transfered... Are there any suggestions what to look for to solve this problem? Thanks. Asaf
I'm assuming you are trying to do something like this:1) Using Nios II to populate some buffer in memory (lets call this buffer A) 2) DMA data from buffer A to another buffer (lets call this buffer B ) 3) Using Nios II to read back buffer B Doing this the data written in# 1 should be the same as the data read back in# 3 but due to the cache this isn't happen. So for# 1 to be safe you need to ensure the data is not cached and reaches the memory. There are two ways you can do this, A) if you are using pointers remap the pointer to be a cache bypassing pointer, or B ) after you write to the buffer perform a cache flush (just flush the range of address where your buffer resides in memory). When this is done then you can start the DMA. For# 3 to be safe (just in case you have previously read from the buffer B locations previously) you can do something similar. Either flush those locations before the DMA transfer, or use a cache bypassing pointer to access the data after the DMA transfer. Depending on your memory latencies and buffer sizes one method will be better than the other. For example if the buffers were on-chip memory using cache bypassing pointers is probably the way to go. If it was SDRAM then flushing ranges of the data cache would probably be better due to the high latency.
Thanks..can you please give me an example to do that?And about rhe agdma..i couldnt find a memory to memory example. Can someone give me an example? Thanks
If you are getting memory with malloc() that is either uncached, or for which you are doing explicit cache operations, you do need to make sure that you only use a cache-aligned part of the buffer.The altera function to malloc() uncached data doesn't stop the cache line being shared!
If you want to always bypass the cache with the allocated pointers then I recommend using the uncached version of malloc. I forget what it's called but it's most likely "uncache_malloc". If you search through the software handbook you should be able to find it where all the other cache bypassing APIs are located. Using uncache_malloc will ensure that the data cache gets flushed before you attempt to use the pointer to avoid the issue dsl is talking about. The cache/uncache remapping APIs should do the same thing safely for you as well.*edit* Also do you need to allocate pointers? I usually try to avoid malloc since I don't like debugging stack and heap collisions :)
I'm not sure if I follow. If you mean that you think cache isn't a problem because you see the DMA addressing incrementing then that's not what we are talking about. We are talking about the data that you are accessing before and after the transfer. If you do not take care of cache coherency of the data then the DMA may not transfer the data you populated in the memory (because it may still be allocated in the cache).