This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于dm6437写flash的一段代码没看懂,求解释




/* ---------------------------------------------------------------- *
* Write *
* ---------------------------------------------------------------- */
printf( " Writing Flash [%d-%d] pages\n", 0, npages );

/* Iterate through all pages */
for ( page = 0 ; page < npages ; page++ )
{
       pageaddr = ( page * NAND_PAGESIZE );

       /* Create write pattern */
       p32 = ( Uint32* )tx;
       for ( i = 0 ; i < segment_len ; i += 4 )
            *p32++ = ( pageaddr + i );

       /* Write to Flash */
       errors = EVMDM6437_NANDFLASH_writePage( ( Uint32 )tx, pageaddr, 1 );

       if ( errors )
       {
             printf( " Found bad page: %d\n", page );
             if ( ( ++bad_pages ) > allowed_bad_pages )
             {
                    printf( " >> Error: Too many bad pages %d\n", bad_pages );
                    return bad_pages;
             }
        }

        /* Skip some pages */
        if ( page >= NAND_PAGES_PER_BLOCK )
        page += ( NAND_PAGES_PER_BLOCK - 1 );
}

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 * NAND_PAGESIZE );

      /* Read from Flash */
     errors = EVMDM6437_NANDFLASH_readPage( pageaddr, ( Uint32 )rx, 1 );

      /* Check pattern */
      p32 = ( Uint32* )rx;
      for ( i = 0; i < segment_len; i += 4 )
      if ( *p32++ != ( pageaddr + i ) )
      errors = 1;

      if ( errors )
      {
            printf( " Found bad page: %d\n", page );
            if ( ( ++bad_pages ) > allowed_bad_pages )
            {
                  printf( " >> Error: Too many bad pages %d\n", bad_pages );
                  return bad_pages;
            }
       }

       /* Skip some pages */
      if ( page >= NAND_PAGES_PER_BLOCK )
      page += ( NAND_PAGES_PER_BLOCK - 1 );
}

bad_pages = 0;

-----------------------------------------------------------------------------------------------------------------------------

上面是一段dm6437读写flash的一段代码,截取自DM6437EVM例程。

其中tx,rx是前面定义的数组,

static Uint8 tx[NAND_PAGESIZE + NAND_SPARESIZE];

static Uint8 rx[NAND_PAGESIZE + NAND_SPARESIZE];

那位大神能给我讲一下,这段代码怎么理解,总感觉这个代码和调试过程中显示的数据对不上。