1 /*
2 * Copyright 2005 by Spectrum Digital Incorporated.
3 * All rights reserved. Property of Spectrum Digital Incorporated.
4 *
5 * Not for distribution.
6 */
7
8 /*
9 * NAND Flash Test
10 *
11 */
12
13 #include "stdio.h"
14 #include "davincievm.h"
15
16 /* ------------------------------------------------------------------------ *
17 * *
18 * Testing Function *
19 * *
20 * ------------------------------------------------------------------------ */
21 void TEST_execute( Int16 ( *funchandle )( ), char *testname, Int16 ledmask )
22 {
23 Int16 status;
24
25 /* Display test ID */
26 printf( "%02d Testing %s...\n", ledmask, testname );
27
28 /* Call test function */
29 status = funchandle( );
30
31 /* Check for test fail */
32 if ( status != 0 )
33 {
34 /* Print error message */
35 printf( " FAIL... error code %d... quitting\n", status, testname );
36
37 /* Software Breakpoint to Code Composer */
38 exit(0);
39 }
40 else
41 {
42 /* Print error message */
43 printf( " PASS\n", testname );
44 }
45 }
46
47 extern Int16 nandflash_test( );
48
49 /* ------------------------------------------------------------------------ *
50 * *
51 * main( ) *
52 * *
53 * ------------------------------------------------------------------------ */
54 void main( void )
55 {
56 /* Initialize BSL */
57 DAVINCIEVM_init( );
58
59 TEST_execute( nandflash_test, "NAND Flash", 1 );
60
61 printf( "\n***ALL Tests Passed***\n" );
62 }
-
-
-
-
-
-
-
-
-
-
-
- #define NANDF1ECC *( volatile Uint32* )0x01E00070
- #define NANDFCR *( volatile Uint32* )0x01E00060
-
- #include "davincievm_nandflash.h"
- typedef union {
- Uint8 *cp;
- Uint16 *wp;
- Uint32 *lp;
- } FLASHPtr;
-
- Uint8 *flash_make_addr (Uint32 baseAddr, Uint32 offset)
- {
- return ((Uint8 *) ( baseAddr + offset ));
- }
-
- void flash_swap_data(Uint32* data)
- {
- Uint32 i,temp = *data;
- volatile FLASHPtr dataAddr, tempAddr;
-
- dataAddr.cp = flash_make_addr((Uint32) data, 3);
- tempAddr.cp = flash_make_addr((Uint32) &temp,0);
-
- for(i=0; i<4; i++)
- *dataAddr.cp-- = *tempAddr.cp++;
- }
-
- Uint32 NAND_ECCReadAndRestart (void)
- {
- Uint32 retval;
-
- retval = NANDF1ECC & (0x0FFF0FFF);
-
- NANDFCR|=(1<<8);
- return retval;
- }
-
-
-
-
-
-
-
- Int16 NANDFLASH_waitWhileBusy( Uint32 timeout )
- {
- Uint32 timecount = 0;
-
-
-
-
- DAVINCIEVM_wait( 1000 );
-
-
-
-
- while( ( ( ! NANDFLASH_READ_RB ) && ( ++timecount timeout ) ) );
-
- if ( timecount == timeout )
- return NANDFLASH_TIMEOUT;
- else
- return 0;
- }
-
-
-
-
-
-
-
-
-
-
-
- Int16 DAVINCIEVM_NANDFLASH_init( )
- {
-
-
-
-
-
-
-
- Uint32 acfg2 = 0
- | ( 0 < 31 )
- | ( 0 < 30 )
- | ( 1 < 26 )
- | ( 4 < 20 )
- | ( 1 < 17 )
- | ( 1 < 13 )
- | ( 6 < 7 )
- | ( 1 < 4 )
- | ( 3 < 2 )
- | ( 0 < 0 )
- ;
-
- DAVINCIEVM_EMIF_config( acfg2,
- AEMIF_MAX_TIMEOUT_16BIT,
- AEMIF_MAX_TIMEOUT_16BIT,
- AEMIF_MAX_TIMEOUT_16BIT );
-
- AEMIF_NANDFCR = 0x00000001;
-
-
-
-
-
-
-
-
-
-
-
- NANDFLASH_ASSERT_CE( );
-
- NANDFLASH_CLE( NANDFLASH_RESET );
-
- if ( NANDFLASH_waitWhileBusy( ( Uint32 )-1 ) )
- return NANDFLASH_TIMEOUT;
-
- NANDFLASH_DEASSERT_CE( );
-
- return 0;
- }
-
-
-
-
-
-
-
-
- Uint32 DAVINCIEVM_NANDFLASH_getTotalPages( )
- {
- Uint8 mfg_id;
- Uint8 dev_id;
- Uint32 total_pages = 0;
-
- NANDFLASH_ASSERT_CE( );
-
- NANDFLASH_CLE( NANDFLASH_READID );
- NANDFLASH_ALE_1( 0 );
-
- mfg_id = NANDFLASH_BASE_PTR;
- dev_id = NANDFLASH_BASE_PTR;
-
-
-
-
- if ( mfg_id == MFG_SAMSUNG )
- {
- if ( dev_id == DEV_K9F5608U0B )
- total_pages = DEV_K9F5608U0B_PAGE_COUNT;
-
- else if ( dev_id == DEV_K9F5608Q0B )
- total_pages = DEV_K9F5608Q0B_PAGE_COUNT;
-
- else if ( dev_id == DEV_K9F2808U0C )
- total_pages = DEV_K9F2808U0C_PAGE_COUNT;
-
- else if ( dev_id == DEV_K9K1208Q0C )
- total_pages = DEV_K9K1208Q0C_PAGE_COUNT;
-
- else if ( dev_id == DEV_SMCARD_128 )
- total_pages = DEV_SMCARD_128_PAGE_COUNT;
- }
- else if( mfg_id==MFG_STMicroelectronics)
- {
- if ( dev_id == DEV_NAND512W3A )
- total_pages = DEV_NAND512W3A_PAGE_COUNT;
- }
- NANDFLASH_DEASSERT_CE( );
-
- return total_pages;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Int16 DAVINCIEVM_NANDFLASH_erase( Uint32 start, Uint32 block_count )
- {
- Uint32 i;
- Int16 bad_blocks = 0;
-
- for ( i = 0 ; i block_count ; i++ )
- {
- NANDFLASH_ASSERT_CE( );
-
- NANDFLASH_CLE( NANDFLASH_ERASE );
- NANDFLASH_ALE_3( start );
- NANDFLASH_CLE( NANDFLASH_ERASE_CONFIRM );
-
- if ( NANDFLASH_waitWhileBusy( ( Uint32 )-1 ) )
- {
- NANDFLASH_DEASSERT_CE( );
- return NANDFLASH_TIMEOUT;
- }
-
- NANDFLASH_CLE( NANDFLASH_STATUS );
- if ( NANDFLASH_BASE_PTR & NANDFLASH_STATUS_ERROR )
- bad_blocks++;
-
- NANDFLASH_DEASSERT_CE( );
-
- start += NANDFLASH_BLOCKSIZE;
- }
- return bad_blocks;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Int16 DAVINCIEVM_NANDFLASH_readPage( Uint32 src, Uint32 dst, Uint32 page_count )
- {
- Uint32 i, j;
- volatile Uint8* dst8 = ( volatile Uint8* )dst;
- Uint8 spare[NANDFLASH_SPARESIZE];
-
- for ( i = 0 ; i page_count ; i++ )
- {
- NANDFLASH_ASSERT_CE( );
-
- NANDFLASH_CLE( NANDFLASH_READ );
- NANDFLASH_ALE_4( src );
-
- if ( NANDFLASH_waitWhileBusy( ( Uint32 )-1 ) )
- {
- NANDFLASH_DEASSERT_CE( );
- return NANDFLASH_TIMEOUT;
- }
-
- for ( j = 0 ; j NANDFLASH_PAGESIZE ; j++ )
- *dst8++ = NANDFLASH_BASE_PTR;
-
-
- for ( j = 0 ; j NANDFLASH_SPARESIZE ; j++ )
- spare[j] = NANDFLASH_BASE_PTR;
-
- NANDFLASH_DEASSERT_CE( );
-
- src += NANDFLASH_PAGESIZE;
- }
-
- return 0;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Int16 DAVINCIEVM_NANDFLASH_writePage( Uint32 src, Uint32 dst, Uint32 page_count )
- {
- Uint32 i, j = 0;
- volatile Uint8* src8 = ( volatile Uint8* )src;
- Uint32 eccValue;
- Uint8 tempSpareValue[1];
- Int16 bad_pages = 0;
-
- for ( i = 0 ; i page_count ; i++ )
- {
- NANDFLASH_ASSERT_CE( );
-
- NANDFLASH_CLE( NANDFLASH_PROGRAM );
- NANDFLASH_ALE_4( dst );
- NAND_ECCReadAndRestart();
- for ( j = 0 ; j NANDFLASH_PAGESIZE ; j++ )
- NANDFLASH_BASE_PTR = *src8++;
- eccValue=NAND_ECCReadAndRestart();
- flash_swap_data(&(eccValue));
- tempSpareValue[0] = eccValue&0x000000FF;
- tempSpareValue[1] = (eccValue&0x0000FF00)>>8;
- tempSpareValue[2] = (eccValue&0x00FF0000)>>16;
- tempSpareValue[3] = (eccValue&0xFF000000)>>24;
- for(j=4;j<16;j++)
- {
- tempSpareValue[j]=0xff;
- }
- for ( j = 0 ; j 16 ; j++ )
- NANDFLASH_BASE_PTR=tempSpareValue[j];
-
- NANDFLASH_CLE( NANDFLASH_PROGRAM_CONFIRM );
-
- if ( NANDFLASH_waitWhileBusy( ( Uint32 )-1 ) )
- {
- NANDFLASH_DEASSERT_CE( );
- return NANDFLASH_TIMEOUT;
- }
-
- NANDFLASH_CLE( NANDFLASH_STATUS );
- if ( NANDFLASH_BASE_PTR & NANDFLASH_STATUS_ERROR )
- bad_pages++;
-
- NANDFLASH_DEASSERT_CE( );
-
- dst += NANDFLASH_PAGESIZE;
- }
-
- return bad_pages;
- }
-