Forum Discussion
Altera_Forum
Honored Contributor
16 years agoIf the addresses of the hardware component are register addresses and not memory addresses, then you really ought to use the IOWR macro.
An example. Suppose you've got some hardware component in your system named "my_custom_hw" and you want to write values to registers 0 and 1 within your component:
# include <io.h> // Contains IOWR and IORD macros
# include "system.h" // Includes everything you need to know about your system.
...
void some_function(){
...
IOWR(MY_CUSTOM_HW_BASE, 0, 0x12345678); // Write to register offset 0 of "my_custom_hw"
IOWR(MY_CUSTOM_HW_BASE, 1, 0x87654321); // Write to register offset 1 of "my_custom_hw"
}
The other macros (IOWR_8DIRECT, IOWR_16DIRECT, IOWR_32DIRECT) are really for writing to memory addressed components. If you want to see the macros, just look at: C:\altera\90\nios2eds\components\altera_nios2\HAL\inc\io.h The "MY_CUSTOM_HW_BASE" macro is generated in the "system.h" file. So you never need to know what the base addresses of your components are, you just use the macro. Jake