Nios® V Processor Software Developer Handbook

ID 743810
Date 4/01/2024
Public
Document Table of Contents

7.9.2. Device Driver Source Code

In addition to the header file, the component driver might need to provide source code to be incorporated in the BSP. This source code is specific to the hardware component, and resides in one or more C files (or assembly language files).

When writing a device driver, apply the HAL I/O macros in the source code. The HAL provides the C-language macros IORD and IOWR that expand to the load and store assembly instructions. These macros are provided to enable HAL device drivers to access device registers.
Note: These instructions cannot bypass the data cache. You are required to place device registers within a peripheral region.

Generally, your program passes values defined in system.h as the BASE and REGNUM parameters. These macros are defined in the file <Intel Quartus installation directory>/ip/altera/soft_processor/intel_niosv_common/HAL/inc/io.h.

Table 36.  HAL I/O Macro
Macro Use
IORD(BASE, REGNUM) Read the value of the register at offset REGNUM in a device with base address BASE. Registers are assumed to be offset by the address width of the bus.
IOWR(BASE, REGNUM, DATA) Write the value DATA to the register at offset REGNUM in a device with base address BASE. Registers are assumed to be offset by the address width of the bus.
IORD_32DIRECT(BASE, OFFSET) Make a 32-bit read access at the location with address BASE+OFFSET.
IORD_16DIRECT(BASE, OFFSET) Make a 16-bit read access at the location with address BASE+OFFSET.
IORD_8DIRECT(BASE, OFFSET) Make an 8-bit read access at the location with address BASE+OFFSET.
IOWR_32DIRECT(BASE, OFFSET, DATA) Make a 32-bit write access to write the value DATA at the location with address BASE+OFFSET.
IOWR_16DIRECT(BASE, OFFSET, DATA) Make a 16-bit write access to write the value DATA at the location with address BASE+OFFSET.
IOWR_8DIRECT(BASE, OFFSET, DATA) Make an 8-bit write access to write the value DATA at the location with address BASE+OFFSET.