Specifications
Creating Embedded Drivers for HAL Device Classes
The HAL supports a number of generic device model classes. By writing a device driver as described in
this section, you describe to the HAL an instance of a specific device that falls into one of its known device
classes. This section defines a consistent interface for driver functions so that the HAL can access the
driver functions uniformly.
The following sections define the API for the following classes of devices:
• Character-mode devices
• File subsystems
• DMA devices
• Timer devices used as system clock
• Timer devices used as timestamp clock
• Flash memory devices
• Ethernet devices
The following sections describe how to implement device drivers for each class of device, and how to
register them for use in HAL-based systems.
Related Information
Overview of the Hardware Abstraction Layer on page 5-1
Character-Mode Device Drivers
Create a Device Instance
For a device to be made available as a character mode device, it must provide an instance of the alt_dev
structure. The alt_dev structure, defined in <Nios II EDS install path>/components/altera_hal/HAL/inc/sys/
alt_dev.h, is essentially a collection of function pointers. These functions are called in response to applica‐
tion accesses to the HAL file system. For example, if you call the function open() with a file name that
corresponds to this device, the result is a call to the open() function provided in this structure.
Example 7–1. alt_dev Structure
typedef struct {
alt_llist llist; /* for internal use */
const char* name;
int (*open) (alt_fd* fd, const char* name, int flags, int mode);
int (*close) (alt_fd* fd);
int (*read) (alt_fd* fd, char* ptr, int len);
int (*write) (alt_fd* fd, const char* ptr, int len);
int (*lseek) (alt_fd* fd, int ptr, int dir);
int (*fstat) (alt_fd* fd, struct stat* buf);
int (*ioctl) (alt_fd* fd, int req, void* arg);
} alt_dev;
NII5V2
2015.05.14
Creating Embedded Drivers for HAL Device Classes
7-5
Developing Device Drivers for the Hardware Abstraction Layer
Altera Corporation
Send Feedback