Specifications
The _regs.h header file defines the following access macros for the component:
• Register access macros that provide a read and/or write macro for each register in the component that
supports the operation. The macros are:
• IORD_<component name>_<register name> (<component base address>)
• IOWR_<component name>_<register name> (<component base address>, <data>)
For example, altera_avalon_jtag_uart_regs.h defines the following macros:
• IORD_ALTERA_AVALON_JTAG_UART_DATA()
• IOWR_ALTERA_AVALON_JTAG_UART_DATA()
• IORD_ALTERA_AVALON_JTAG_UART_CONTROL()
• IOWR_ALTERA_AVALON_JTAG_UART_CONTROL()
• Register address macros that return the physical address for each register in a component. The address
register returned is the component’s base address + the specified register offset value. These macros are
named IOADDR_<component name>_<register name> (<component base address>).
For example, altera_avalon_jtag_uart_regs.h defines the following macros:
• IOADDR_ALTERA_AVALON_JTAG_UART_DATA()
• IOADDR_ALTERA_AVALON_JTAG_UART_CONTROL()
Use these macros only as parameters to a function that requires the specific address of a data source
or destination. For example, a routine that reads a stream of data from a particular source register
in a component might require the physical address of the register as a parameter.
• Bit-field masks and offsets that provide access to individual bit-fields in a register. These macros have
the following names:
• <component name>_<register name>_<name of field>_MSK—A bit-mask of the field
• <component name>_<register name>_<name of field>_OFST—The bit offset of the start of the field
For example, ALTERA_AVALON_UART_STATUS_PE_MSK and ALTERA_AVALON_UART_STATUS_PE_OFST
access the pe field of the status register.
Access a device’s registers only with the macros defined in the _regs.h file. You must use the register access
functions to ensure that the processor bypasses the data cache when reading and or writing the device. Do
not use hard-coded constants, because they make your software susceptible to changes in the underlying
hardware.
If you are writing the driver for a completely new hardware device, you must prepare the _regs.h header
file.
For more information about a complete example of the _regs.h file, refer to the component directory for
any of the Altera-supplied components, such as <Altera installation>/ip/sopc_builder_ip/
altera_avalon_jtag_uart/inc.
Related Information
• AN 459: Guidelines for Developing a Nios II HAL Device Driver
For more information about developing device drivers for HAL BSPs.
• Cache and Tightly-Coupled Memory
For more information about the effects of cache management and device access.
7-4
Accessing Hardware
NII5V2
2015.05.14
Altera Corporation
Developing Device Drivers for the Hardware Abstraction Layer
Send Feedback