Nios® V Processor Software Developer Handbook

ID 743810
Date 2/14/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

6.8.1. Simple Flash Access

This interface consists of the functions alt_flash_open_dev(), alt_write_flash(), alt_read_flash(), and alt_flash_close_dev().

You open a flash device by calling alt_flash_open_dev(), which returns a file handle to a flash device. This function takes a single argument that is the name of the flash device, as defined in system.h.

After you obtain a handle, you can use the alt_write_flash() function to write data to the flash device. The prototype is:

int alt_write_flash( alt_flash_fd* fd,
int offset,
const void* src_addr,
int length )

A call to this function writes to the flash device identified by the handle fd. The driver writes the data starting at offset bytes from the base of the flash device. The data written comes from the address pointed to by src_addr, and the amount of data written is length.

There is also an alt_read_flash() function to read data from the flash device. The prototype is:

int alt_read_flash( 
alt_flash_fd* fd,
int offset,
void* dest_addr,
int length
)

A call to alt_read_flash() reads from the flash device with the handle fd, offset bytes from the beginning of the flash device. The function writes the data to location pointed to by dest_addr, and the amount of data read is length. For most flash devices, you can access the contents as standard memory, making it unnecessary to use alt_read_flash().

The function alt_flash_close_dev() takes a file handle and closes the device. The prototype for this function is:

void alt_flash_close_dev(alt_flash_fd* fd )