Forum Discussion
Altera_Forum
Honored Contributor
14 years agoNios II - Data cache problem
Hi all,
I'm using a Cyclone III DSP Kit (DK-DSP-3C120N) and uClinux. Some days ago I realized a working design which includes a Nios II processor characterized by only an instruction cache. Within the system there's an IP that communicates with the CPU using a PIO peripheral. I wrote a Linux driver for this IP. All seems to work, but if I add also a data cache, Nios II and the IP stop to communicate, it seems that data do not leave the PIO. Can anyone tell me why? Thanks in advance Marco21 Replies
- Altera_Forum
Honored Contributor
You'll need to do something to either flush the data from the cache, or to do uncached accesses.
uClinux ought to have functions to map the memeory uncached. You also need to ensure that you NEVER access any physical address in the same cache line via cachable accesses. The cache line read/write will have unwanted effects. For a hardware device this is unlikely, but can be a problem is you want a block of memory (eg for dma). - Altera_Forum
Honored Contributor
Yep, do the cache flushing.
- Altera_Forum
Honored Contributor
Hi again,
after some weeks I got back on the issue and as you suggested I used fflush(fd) to force data flush, but nothing changed. I have to use data cache so I'd like to resolve this issue. Is it enough to add fflush(fd) after every write or do I need to do something else? Thanks in advance Marco - Altera_Forum
Honored Contributor
Wrong function. I don't remember how it is called, but I am sure this isn't the right one.
Edit: here it is: alt_dcache_flush_all(); - Altera_Forum
Honored Contributor
Thanks Socrates, but can I use it with uClinux? I remember that I read something similar in the past but it was for HAL. Am I wrong?
- Altera_Forum
Honored Contributor
--- Quote Start --- Wrong function. I don't remember how it is called, but I am sure this isn't the right one. Edit: here it is: alt_dcache_flush_all(); --- Quote End --- That's for HAL, that function is not available in Linux. fflush if for a *file* not for memory. Are you doing this in the kernel (like a device driver) or in user space? - Altera_Forum
Honored Contributor
Oh I've forgot You're using ucLinux... I'd offer You to write a message to mailing list of Nios. Check alterawiki.com for that.
- Altera_Forum
Honored Contributor
Thanks for your answer ykozlov. I'm doing it in user space. You're right, I noticed that fflush is for file. Is sync() correct? I tried it but software crashes...
@Socrates Thanks for the advice, I'll try. - Altera_Forum
Honored Contributor
sync() would be a unix system call to write all the disk buffer cache to disk.
If you are running in user mode, how are you mapping the required physical addresses into (process) virtual ones? That is usually only allowed in a device driver. That mapping operation should have an option to enable/disable the cache - put you may not have the desired control over it (even in the kernel). To flush the data cache you need to execute the flushd or flushda instruction, you might need initda (initd is supervisor/kernel only). Not sure what is in which .h file for these... - Altera_Forum
Honored Contributor
Hi dsl,
I wrote a char driver to manage communications with my peripheral. I've followed your previous advice, but with no success, I can't find flushda instruction. I found in linux/include/asm-nios2/cacheflush.h some functions and I tried to use flush_cache_all() within my driver at the end of the write function but it blocks when my user program calls write() for the first time.