Forum Discussion
Memory Conflicts in onchip ram
Hi,
I had created a simple design that consists of clock, OCR, Nios II, jtag uart and data in/out component. The OCR address is range from 0x40000 (Base) to 0x657ff (End). The corresponding decimal for 0x40000 (Base) and 0x657ff (End) are 262144 and 415743 respectively.
I had created a code which loops to IOWR_32DIRECT and IORD_32DIRECT the data for each OCR address. The first data is 262144 which being incremented by 1 for each loop until 415743. In the terminal, I'm getting decimal 415743 for address 0x657ff means the data are matching with each address respectively. Attached the project file below for your reference.
Code:
# include <stdio.h>
# include "system.h"
# include "io.h"
#define BASE_ADDRESS ONCHIP_MEM_BASE
#define END_ADDRESS 0x657FF
int main() {
int i = 262144;
unsigned int addr;
for (addr = BASE_ADDRESS; addr <= END_ADDRESS; addr++) {
char addr_str[11]; // Assumes 32-bit address
snprintf(addr_str, sizeof(addr_str), "0x%05x", addr);
IOWR_32DIRECT(addr_str, 1, i);
printf("Address: 0x%x, Value: %d\n", addr, IORD_32DIRECT(addr_str, 1));
i++;
}
return 0;
}
Terminal screenshot:
Not sure your case is because of processor speed or not. What will happen if you add small delay to the loop?
Thanks,
Best Regards,
Sheng
p/s: If any answer from the community or Intel Support are helpful, please feel free to give best answer or rate 4/5 survey.
- ggxnd3 years ago
New Contributor
Hi,
Thank you for your reply. I will have a look into the solution that you provided. I have a doubt.
The following is how I try to perform write and read.for (addr = 0; addr <= END_ADDRESS; addr += 4) {
IOWR_32DIRECT(BASE_ADDRESS, addr, i);
}
for (addr = 0; addr <= END_ADDRESS; addr += 4) {
value = IORD_32DIRECT(BASE_ADDRESS, addr);
printf("Address: 0x%x, Value: %d\n", addr, value);}
What is the key difference between the your code and the above one. Why is it failing to provide same result here.? Can you provide any insight / idea on this?