Forum Discussion
Altera_Forum
Honored Contributor
17 years agoThe "when" is important. For your system to work, the load_data() on the second processor would need to be called just after the load_data() function on the first processor filled the matrix, but before it would read the result. This would be impossible to guarantee without any synchronisation between the two CPUs.
The NIOS processor can have a data cache, and it will cause some problems when you share memory. If the memory is updated by one CPU, the second CPU may not notice it, and when reading will return the old value from its cache instead of the new value in memory. One way to go around that is to call the alt_dcache_flush_all() function as you did, after writing and before reading. This will clear all the data cache and force the CPU to read from memory. This is not very efficient though, because all the cache is flushed, including other regions of memory that could still be in cache. Another way is to use the remap function. Given a pointer, it will return a new pointer value, that when used will force the CPU to access the main memory and never go through the cache. Finally for code readability and robustness to SOPC regenerations you should use a system.h define for the address rather than a hard coded value. Something like that:unsigned int *memory = alt_remap_uncached(SHARED_MEMORY_BASE);
h1 = memory;
h2 = memory;
g1 = memory;
g2 = memory;
memory = (h1*g1)+(h2*g2);
You should of course replace SHARED_MEMORY_BASE by the actual constant defined in system.h for your shared memory area. And by the way I think the NIOS forum would be more appropriate for this discussion ;)