Specifications
Function Default Behavior
write Calls to write() for this device always fail.
lseek Calls to lseek() for this device always fail.
fstat The device identifies itself as a character mode device.
ioctl ioctl() requests that cannot be handled without reference to the
device fail.
In addition to the function pointers, the alt_dev structure contains two other fields: llist and name.
llist is for internal use, and must always be set to the value ALT_LLIST_ENTRY. name is the location of the
device in the HAL file system and is the name of the device as defined in system.h.
Register a Character Device
After you create an instance of the alt_dev structure, the device must be made available to the system by
registering it with the HAL and by calling the following function:
int alt_dev_reg (alt_dev* dev)
This function takes a single input argument, which is the device structure to register. The return value is
zero upon success. A negative return value indicates that the device cannot be registered.
After a device is registered with the HAL file system, you can access it through the HAL API and the ANSI
C standard library. The node name for the device is the name specified in the alt_dev structure.
For more information, refer to the "Developing Programs Using the Hardware Abstraction Layer" chapter
of the Nios II Software Developer’s Handbook.
Related Information
Developing Device Drivers for the Hardware Abstraction Layer
File Subsystem Drivers
A file subsystem device driver is responsible for handling file accesses beneath a specified mount point in
the global HAL file system.
Create a Device Instance
Creating and registering a file system is very similar to creating and registering a character-mode device.
To make a file system available, create an instance of the alt_dev structure.
For more information, refer to the “Character-Mode Device Drivers” chapter.
The only distinction is that the name field of the device represents the mount point for the file subsystem.
Of course, you must also provide any necessary functions to access the file subsystem, such as read() and
write(), similar to the case of the character-mode device.
Note:
If you do not provide an implementation of fstat(), the default behavior returns the value for a
character-mode device, which is incorrect behavior for a file subsystem.
Related Information
Character-Mode Device Drivers on page 7-5
Register a File Subsystem Device
You can register a file subsystem using the following function:
NII5V2
2015.05.14
Register a Character Device
7-7
Developing Device Drivers for the Hardware Abstraction Layer
Altera Corporation
Send Feedback