flashwrite.c

来自「CHP 2 - Real-Time Digital Signal Process」· C语言 代码 · 共 60 行

C
60
字号
// 
//  Project: Experiment 2.10.5 Flash Programming - Chapter 2 
//  File name: flashWrite.c   
//  Function: flashWrite()        
//
//  Description: This function writes data to the C5510 DSK flash memory
//               Note: this funciton is for AMD: AM29LV400B
//
//  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 "flash.h"

#pragma CODE_SECTION(flashWrite, ".text:example:flashWrite");
 
short flashWrite(unsigned short *src, unsigned short *dest, unsigned long len)
{        
  unsigned long i;
  volatile short j;  
         
  for (i=0; i<len; i++)
  {             
    // Issue flash chip write sequence: AA-55-A0 then Addr Data
    *((volatile unsigned short *)FLASH_MEM_ADDR555) = 0xaa;
    *((volatile unsigned short *)FLASH_MEM_ADDR2AA) = 0x55;
    *((volatile unsigned short *)FLASH_MEM_ADDR555) = 0xa0;  

    // Write data
    *dest = *src;         

    // Wait until stable before check
    for (j=0; j<500; j++);

    // Check and wait until the flash write complete  
    while(1)                 
    {
      if ((*dest & FLASH_MEM_DQ7) == (*src & FLASH_MEM_DQ7))   
      {
        break;         // Write success
      }         
      if ((*dest & FLASH_MEM_DQ5) == FLASH_MEM_DQ5)   
      {         
        flashReset();  // Reset flash
        return (1);    // Write failed and timed out 
      }  
    }
    dest++;
    src++;  	         
  }
  // Reset flash
  flashReset();
  return (0); 
}

⌨️ 快捷键说明

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