📄 nandflash_test.c
字号:
/*
* Copyright 2005 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*
* Not for distribution.
*/
/*
* NAND Flash Test
*
*/
#include "stdio.h"
#include "davincievm_msp430.h"
#include "davincievm_nandflash.h"
/* ------------------------------------------------------------------------ *
* *
* nandflash_init( ) *
* Configure pinmux and wait states *
* *
* ------------------------------------------------------------------------ */
Int16 nandflash_init( )
{
DAVINCIEVM_MSP430_setOutput( 0, 1 ); // DeSelect SM card
return 0;
}
static Uint8 rx[NANDFLASH_PAGESIZE + NANDFLASH_SPARESIZE];
static Uint8 tx[NANDFLASH_PAGESIZE + NANDFLASH_SPARESIZE];
/* ------------------------------------------------------------------------ *
* *
* nandflash_test( ) *
* *
* ------------------------------------------------------------------------ */
Int16 nandflash_test( )
{
Int32 i;
Int16 retcode = 0;
Uint32 nblocks;
Uint32 npages;
Uint32 nbytes;
Uint32 segment_len = NANDFLASH_PAGESIZE;
Uint32* p32;
Uint32 page;
Uint32 pageaddr;
Int32 bad_pages = 0;
/* ---------------------------------------------------------------- *
* Initialize NAND Flash *
* ---------------------------------------------------------------- */
DAVINCIEVM_NANDFLASH_init( );
/* Determine the total number of pages */
if ( ( npages = DAVINCIEVM_NANDFLASH_getTotalPages( ) ) == 0 )
{
printf( " Error: NO pages found\n" );
return 1;
}
else
{
nblocks = npages >> NANDFLASH_PAGES_PER_BLOCK_POW2;
nbytes = npages * NANDFLASH_PAGESIZE;
printf( " %d Blocks\n", nblocks );
printf( " %d Pages\n", npages );
printf( " %d Mbytes\n", nbytes >> 20 );
}
/* ---------------------------------------------------------------- *
* Erase *
* ---------------------------------------------------------------- */
printf( " Erasing Flash [%d-%d] blocks\n", 0, nblocks );
/* Erase all block of NAND Flash */
if ( ( retcode = DAVINCIEVM_NANDFLASH_erase( 0, nblocks ) ) > 3 )
{
printf( " Error: Erasing code %d\n", retcode );
return retcode | 0x8000;
}
else if ( ( retcode > 0 ) && ( retcode <= 3 ) )
{
printf( " Found: %d # bad blocks\n", retcode );
}
/* ---------------------------------------------------------------- *
* Write *
* ---------------------------------------------------------------- */
printf( " Writing Flash [%d-%d] pages\n", 0, npages );
/* Iterate through all pages */
for ( page = 0 ; page < npages ; page++ )
{
pageaddr = ( page * NANDFLASH_PAGESIZE );
/* Create write pattern */
p32 = ( Uint32* )tx;
for ( i = 0 ; i < segment_len ; i += 4 )
*p32++ = ( pageaddr + i );
/* Write to Flash */
retcode |= DAVINCIEVM_NANDFLASH_writePage( ( Uint32 )tx, pageaddr, 1 );
if ( retcode != 0 )
{
printf( " Bad page found: %d\n", page );
bad_pages++;
if ( bad_pages > 3 )
return bad_pages;
retcode = 0;
}
/* Skip some pages */
if ( page >= NANDFLASH_PAGES_PER_BLOCK )
page += ( NANDFLASH_PAGES_PER_BLOCK - 1 );
}
/* Check errors */
if ( retcode != 0 )
{
printf( " Error: Writing code %d\n", retcode );
return retcode | 0x8000;
}
bad_pages = 0;
/* ---------------------------------------------------------------- *
* Read *
* ---------------------------------------------------------------- */
printf( " Reading Flash [%d-%d] pages\n", 0, npages );
/* Iterate through all pages */
for ( page = 0 ; page < npages ; page++ )
{
pageaddr = ( page * NANDFLASH_PAGESIZE );
/* Read from Flash */
retcode |= DAVINCIEVM_NANDFLASH_readPage( pageaddr, ( Uint32 )rx, 1 );
/* Check pattern */
p32 = ( Uint32* )rx;
for ( i = 0; i < segment_len; i += 4 )
if ( *p32++ != ( pageaddr + i ) )
retcode = 1;
if ( retcode != 0 )
{
printf( " Bad page found: %d\n", page );
bad_pages++;
if ( bad_pages > 3 )
return bad_pages;
retcode = 0;
}
/* Skip some pages */
if ( page >= NANDFLASH_PAGES_PER_BLOCK )
page += ( NANDFLASH_PAGES_PER_BLOCK - 1 );
}
/* Check errors */
if ( retcode != 0 )
{
printf( " Error: Reading code %d\n", retcode );
return retcode | 0x8000;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -