Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

6.10.3.1. alt_get_flash_info()

alt_get_flash_info() gets the number of erase regions, the number of erase blocks in each region, and the size of each erase block. The function prototype is as follows:

int alt_get_flash_info ( 
 alt_flash_fd* fd,
 flash_region** info,
 int* number_of_regions )

If the call is successful, on return the address pointed to by number_of_regions contains the number of erase regions in the flash memory, and *info points to an array of flash_region structures. This array is part of the file descriptor.

Table 32.  Example of Writing Flash and Causing Unexpected Data Corruption
Address Block Time t(0) Time t(1) Time t(2) Time t(3) Time t(4)
Before First Write First Write Second Write
After Erasing Block(s) After Writing Data 1 After Erasing Block(s) After Writing Data 2
0x0000 1 Unknown FF AA AA AA
0x0400 1 Unknown FF AA AA AA
0x0800 1 Unknown FF AA AA AA
0x0C00 1 Unknown FF AA AA AA
0x1000 2 Unknown FF AA FF FF6
0x1400 2 Unknown FF FF FF BB
0x1800 2 Unknown FF FF FF BB
0x1C00 2 Unknown FF FF FF FF
The flash_region structure is defined in sys/alt_flash_types.h. The data structure is defined as follows:
typedef struct flash_region
{
int offset; /* Offset of this region from start of the flash */
int region_size; /* Size of this erase region */
int number_of_blocks; /* Number of blocks in this region */
int block_size; /* Size of each block in this erase region */
}flash_region;

With the information obtained by calling alt_get_flash_info(), you are in a position to erase or program individual blocks of the flash device.

6 Unintentionally cleared to FF during erasure for second write.