Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

io.h vs normal data access

Hi there,

Maybe a silly question...

What is the purpose of the io.h headerfile?

A memory addressable device can be referenced as follows:

data = *(INT32U*) 0x200000;

or using io.h

data = IORD_32DIRECT(0x200000, 0);

I find that it some cases the first option does not work correctly - the device chip selects do not get set while doing the read.

I have now switched to using io.h for such reads but would like to know if anyone can explain this?

Thanks

R

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I'm guessing that you have a data cache in your system, which is why you're seeing strange results with your first example. The second example maps onto the ldxio assembly functions which bypass the cache. For more information you should read Writing Device Drivers (page 7-4) in the Nios II Software Developer's Handbook (n2sw_nii5v2.pdf)

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Rikusg.

    If you were working with Nios I then what you showed in your first example was correct. However from a software point of view, you can't pre-determine if you will get a cache hit or miss (cache hit in your case will cause the program to fail since your device will not be accessed).