⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flashtest.c

📁 CHP 2 - Real-Time Digital Signal Processing: Implementations and Applications, Second Edition by Sen
💻 C
字号:
// 
//  Project: Experiment 2.10.5 Flash Programming - Chapter 2 
//  File name: flashTest.c   
//  Function(s): main()    
//               dispID()    
//
//  Description: Experiment 2.10.5 initializes the C55x DSK EMIF registers
//               and reads the manufacture ID and device ID;
//               it also writes and reads data to and from flash memory
//
//  For the book "Real Time Digital Signal Processing: 
//                Implementation and Application, 2nd Ed"
//                By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
//                Publisher: John Wiley and Sons, Ltd
//
//  Tools used: CCS v.2.12.07
//              TMS320VC5510 DSK Rev-C
//

#include <stdio.h>
#include "emif.h"
#include "flash.h"

// Local data
#define   DATASIZE  12320
short data[DATASIZE]={
#include "dtmf18005551234.dat"
};

// Local functions
static void dispID(unsigned short id, unsigned short devID);
static short dataCheck(unsigned short *data1, unsigned short 
                       *data2, unsigned long length);

#pragma CODE_SECTION(main, ".text:example:main");
#pragma CODE_SECTION(dispID, ".text:example:dispID");
#pragma CODE_SECTION(dataCheck, ".text:example:dataCheck");

void main()
{      
  unsigned short manufactureID,deviceID;
  unsigned long err;
    
  // Initialize the EMIF     
  initEMIF();
    
  // Reset FLASH
  flashReset();

  // Read FLASH ID
  flashID(&manufactureID, &deviceID);    
    
  // Display manufacture and device IDs
  dispID(manufactureID, deviceID);   
                   
  // Flash chip erase
  printf("Flash erase begin - this may take a while\n"); 
  if ( flashErase() )
  {
    printf("Flash erase failed\n");        
  }
  else
  {
    printf("Flash erase completed\n");            
  }
  
  // Write data to Flash
  if ( flashWrite((unsigned short *)data, (unsigned short *)FLASH_MEM_BASE, DATASIZE))
  {
    printf("Flash write error\n");     
  }       
  else
  {
    printf("Flash write complted\n");            
  }
  
  // Check Flash write data error
  err = dataCheck((unsigned short *)data, (unsigned short *)FLASH_MEM_BASE, DATASIZE);    
  if ( err != 0)
  {
    printf("%ld data errors are found\n",err); 
  }          
  else
  {
    printf("No data error has been found\n");  
  }            
}

static void dispID(unsigned short mID, unsigned short devID)
{
  switch(mID)
  {
     case AMD:
       printf("This is an AMD Flash\n"); 
       if ((devID == AMDTOP_BOOT_BLOCK)||
           (devID == AMDBOTTOM_BOOT_BLOCK))
       {
         printf("The device is AM29LV400B\n");
       }    
       else
       {
         printf("The device is unknown\n");		     
       }
       break;
     case FUJITSU:
       printf("This is a Fujitsu Flash\n");
       break;
     case ATMEL:
       printf("This is an Atmel Flash\n");
       break;
     case ST:
       printf("This is an ST Flash\n");
       break;
     case INTEL:
       printf("This is an Intel Flash\n");
       break;
     case TOSHIBA:
       printf("This is a Toshiba Flash\n");
       break;
     case HYNIX:
       printf("This is a Hynix Flash\n");
       break;  
     case SHARP:
       printf("This is a Sharp Flash\n");
       break;  
     case MXIC:
       printf("This is a MXIC Flash\n");
       break;  
     default:
       printf("Flash manufacture is unknown\n");
       break;        
  }
}

static short dataCheck(unsigned short *data1, unsigned short *data2, unsigned long len)
{   
  unsigned long i,err;
                     
  err = 0;
  for (i=0; i<len; i++)
  {
    if (*data1++ != *data2++)
    {
      err++;
    }
  }
  return (err);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -