#include "system.h"
#include "sys/alt_flash.h"
#include "sys/alt_flash_dev.h"
void test_flash_block()
{
alt_flash_fd *my_flash; //define handle
flash_region* regions;
int number_of_regions;
int ret_code ;
char *buf = NULL;
my_flash = alt_flash_open_dev(CFI_FLASH_NAME);//open flash, get handle
if(my_flash == NULL)
{
printf("Open flash fail /n");
return;
}
ret_code = alt_get_flash_info (my_flash, ®ions, &number_of_regions);
if(my_flash != NULL)
{
int j = 0;
for(j=0;j<number_of_regions;j++)
{
printf("/n******************regions %d*************************/n",j);
printf("regions[%d].offset = %d /n", j, regions[j].offset);
printf("regions[%d].region_size = %d /n", j, regions[j].region_size);
printf("regions[%d].number_of_blocks = %d/n", j, regions[j].number_of_blocks);
printf("regions[%d].block_size = %d /n/n", j, regions[j].block_size);
buf = (char*)malloc(regions[j].block_size);
memset(buf, 'a', regions[j].block_size);
ret_code = alt_write_flash(my_flash,regions[j].offset,buf,regions[j].block_size);
if(ret_code != 0)
{
printf("write flash fail /n");
return;
}
memset(buf,0, regions[j].block_size);
ret_code = alt_read_flash(my_flash, regions[j].offset, buf, regions[j].block_size);
if(ret_code != 0)
{
printf("read flash fail /n");
return;
}
int i=0;
for(i=0;i< 20 ;i++)
{
printf("%c",buf[i]);
}
free(buf);
}
}
else
{
printf("get flash info fail /n");
}
alt_flash_close_dev(my_flash);
}