Specifications
Developing Device Drivers for the Hardware
Abstraction Layer
7
2015.05.14
NII5V2
Subscribe
Send Feedback
Embedded systems typically have application-specific hardware features that require custom device
drivers. This chapter describes how to develop device drivers and integrate them with the hardware
abstraction layer (HAL).
This chapter also describes how to develop software packages for use with HAL board support packages
(BSPs). The process of integrating a software package with the HAL is nearly identical with the process for
integrating a device driver.
Confine direct interaction with the hardware to device driver code. In general, the best practice is to keep
most of your program code free of low-level access to the hardware. Wherever possible, use the high-level
HAL application program interface (API) functions to access hardware. This makes your code more
consistent and more portable to other Nios
®
II systems that might have different hardware configurations.
When you create a new driver, you can integrate the driver with the HAL framework at one of the
following two levels:
• Integration in the HAL API
• Peripheral-specific API
Note:
As an alternative to creating a driver, you can compile the device-specific code as a user library,
and link it with the application. This approach is workable if the device-specific code is
independent of the BSP, and does not require any of the extra services offered by the BSP, such as
the ability to add definitions to the system.h file.
Driver Integration in the HAL API
Integration in the HAL API is the preferred option for a peripheral that belongs to one of the HAL generic
device model classes, such as character-mode or direct memory access (DMA) devices.
For integration in the HAL API, you write device access functions as specified in this chapter, and the
device becomes accessible to software through the standard HAL API. For example, if you have a new
LCD screen device that displays ASCII characters, you write a character-mode device driver. With this
driver in place, programs can call the familiar printf() function to stream characters to the LCD screen.
Related Information
Overview of the Hardware Abstraction Layer on page 5-1
For more information about the descriptions of the HAL generic device model classes.
©
2015 Altera Corporation. All rights reserved. ALTERA, ARRIA, CYCLONE, ENPIRION, MAX, MEGACORE, NIOS, QUARTUS and STRATIX words and logos are
trademarks of Altera Corporation and registered in the U.S. Patent and Trademark Office and in other countries. All other words and logos identified as
trademarks or service marks are the property of their respective holders as described at www.altera.com/common/legal.html. Altera warrants performance
of its semiconductor products to current specifications in accordance with Altera's standard warranty, but reserves the right to make changes to any
products and services at any time without notice. Altera assumes no responsibility or liability arising out of the application or use of any information,
product, or service described herein except as expressly agreed to in writing by Altera. Altera customers are advised to obtain the latest version of device
specifications before relying on any published information and before placing orders for products or services.
ISO
9001:2008
Registered
www.altera.com
101 Innovation Drive, San Jose, CA 95134