SST39VF160_Flash_Program.rar

  • PUDN用户
    了解作者
  • Others
    开发工具
  • 43KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 87
    下载次数
  • 2006-12-19 09:30
    上传日期
SST39VF160 NOR Flash驱动 VDSP环境
SST39VF160_Flash_Program.rar
  • Flash Program
  • Debug
  • def.h
    1009B
  • BF533EzFlash.mak
    3.6KB
  • BF533EzFlash.c
    26.9KB
  • 39VF160.C
    3.2KB
  • BF533EzFlash.dpj
    3.9KB
  • linker_log.xml
    40.7KB
  • Errors.h
    324B
  • www.pudn.com.txt
    218B
内容介绍
/////////////////////////////////////////////////////////////// // // BF533EzFlash.c // // Analog Devices, Inc. - 2001 // // // Change Log // // 1.00.1 // - made changes so that the driver will work with // the revised GUI // // 1.00.0 // - initial release // // VisualDSP++ "Flash Programmer" flash driver for use with the // ADSP-BF533 EZ-KIT Lite containing the STMicroelectronics PSD4256G // flash device. // /////////////////////////////////////////////////////////////// // error enum #include <stdlib.h> #include "Errors.h" #include <cdefBF533.h> #include <ccblkfn.h> // #defines #define TRUE 0x1 #define FALSE 0x0 #define BUFFER_SIZE 0x600 //#define NUM_SECTORS 40 // number of sectors in the flash device #define NUM_SECTORS 32// SST39VF160 blocks #define SECTOR_SIZE 2048 /* Must be 2048 words for 39VF160 */ #define BLOCK_SIZE 32768 /* Must be 32K words for 39VF160 */ #define DELAY 0x5 char state = 0; // structure for flash sector information typedef struct _SECTORLOCATION{ long lStartOff; long lEndOff; }SECTORLOCATION; // Flash Programmer commands typedef enum { NO_COMMAND, // 0 GET_CODES, // 1 RESET, // 2 WRITE, // 3 FILL, // 4 ERASE_ALL, // 5 ERASE_SECT, // 6 READ, // 7 GET_SECTNUM, // 8 GET_SECSTARTEND // 9 }enProgCmds; // #defines for the assembler asm ("#define FLASH_START_L 0x0000"); asm ("#define FLASH_START_H 0x2000"); // function prototypes ERROR_CODE SetupForFlash(); ERROR_CODE GetCodes(); ERROR_CODE PollToggleBit(unsigned long ulOffset); ERROR_CODE ResetFlash(); ERROR_CODE EraseFlash(); ERROR_CODE EraseBlock( int nBlock ); ERROR_CODE UnlockFlash(unsigned long ulOffset); ERROR_CODE WriteData( unsigned long ulStart, long lCount, long lStride, int *pnData ); ERROR_CODE FillData( unsigned long ulStart, long lCount, long lStride, int *pnData ); ERROR_CODE ReadData( unsigned long ulStart, long lCount, long lStride, int *pnData ); ERROR_CODE ReadFlash( unsigned long ulOffset, int *pnValue ); ERROR_CODE WriteFlash( unsigned long ulOffset, int nValue ); ERROR_CODE GetSectorNumber( unsigned long ulOffset, int *pnSector ); ERROR_CODE GetSectorStartEnd( long *lStartOff, long *lEndOff, int nSector ); // global data for use with the VisualDSP++ plug-in char *AFP_Title = "ADSP-BF533 Board"; char *AFP_Description = "SS39TVF160"; enProgCmds AFP_Command = NO_COMMAND; int AFP_ManCode = -1; // 0x20 = STMicroelectronics int AFP_DevCode = -1; // 0xE9 = PSD4256G unsigned long AFP_Offset = 0x0; int *AFP_Buffer; long AFP_Size = BUFFER_SIZE; long AFP_Count = -1; long AFP_Stride = -1; int AFP_NumSectors = NUM_SECTORS; long AFP_SectorSize = 0x10000;//byte long AFP_SectorSize1 = 0x10000; int AFP_SectorSize2 = 0x2000; int AFP_Sector = -1; int AFP_Error = 0; // contains last error encountered //bool AFP_Verify = FALSE; // verify writes or not bool AFP_Verify = TRUE; long AFP_StartOff = 0x0; // sector start offset long AFP_EndOff = 0x0; // sector end offset int AFP_FlashWidth = 0x10; // width of the flash device int *AFP_SectorInfo; SECTORLOCATION SectorInfo[NUM_SECTORS]; // flag telling us that the flash had to be reset char reset = 0x0; // exit flag bool bExit = FALSE; #define DELAY_WRITE 9 ERROR_CODE Delay(int time) { int i =0; int j =0; for(j=0;j<300;j++) for(i=0;i<time;i++) { asm("nop;"); } return NO_ERR; } void main_test() { // unsigned long ulStart - offset in flash to start the writes at // long lCount - number of elements to write, in this case bytes // long lStride - number of locations to skip between writes // int *pnData - pointer to data buffer // int start = 0; int lcount = 0x100; int lstride= 0x1; int data[10]={0}; int data1[10]={0}; int i=0; char j; int m_j; for(i=0;i<10;i++) { data[i] = 8; data1[i] = i; } // SetupForFlash(); *pEBIU_AMBCTL0 = 0x78B078B0; *pEBIU_AMBCTL1 = 0x78B078B0; *pEBIU_AMGCTL |= 0xF; ssync(); GetCodes(); unsigned short test = 0; EraseFlash(); for(i=0;i<SECTOR_SIZE/4;i++) { WriteFlash( 0x5555*2, 0xaaaa ); WriteFlash( 0x2aaa*2, 0x5555 ); WriteFlash( 0x5555*2, 0xa0a0 ); WriteFlash( (0x0+i)*2, test ); PollToggleBit( (0x0+i)*2); test++; // Delay( DELAY_WRITE *1000); } // ReadFlash( 0x10000*2, test ); // Delay( DELAY_WRITE *10000); GetCodes(); start = 0; lcount = 0x100; ReadData(start,lcount,lstride,data1); } main() { int i = 0; // by making AFP_Buffer as big as possible the plug-in can send and // receive more data at a time making the data transfer quicker // // by allocating it on the heap the compiler does not create an // initialized array therefore making the driver image smaller // and faster to load // // we have modified the linker description file (LDF) so that the heap // is large enough to store BUFFER_SIZE elements at this point AFP_Buffer = (int *)malloc(BUFFER_SIZE); // AFP_Buffer will be NULL if we could not allocate storage for the // buffer if ( AFP_Buffer == NULL ) { // tell GUI that our buffer was not initialized AFP_Error = BUFFER_IS_NULL; } //initiate sector information structures for(i=0;i<AFP_NumSectors; i++) { GetSectorStartEnd(&SectorInfo[i].lStartOff, &SectorInfo[i].lEndOff, i); } AFP_SectorInfo = (int*)&SectorInfo[0]; // setup the flash so the DSP can access it SetupForFlash(); EraseFlash(); //setup code so that flash programmer can just read memory instead of call GetCodes(). GetCodes(); // int test[10]={0,1,2,3,4,5,6,7,8,9}; // WriteData( 2, 10, 1, test ); // EraseBlock(0); // command processing loop while ( !bExit ) { // the plug-in will set a breakpoint at "AFP_BreakReady" so it knows // when we are ready for a new command because the DSP will halt // // the jump is used so that the label will be part of the debug // information in the driver image otherwise it may be left out // since the label is not referenced anywhere asm("AFP_BreakReady:"); if ( FALSE ) asm("jump AFP_BreakReady;"); // switch on the command switch ( AFP_Command ) { // get manufacturer and device codes case GET_CODES: AFP_Error = GetCodes(); break; // reset case RESET: AFP_Error = ResetFlash(); break; // write case WRITE: AFP_Error = WriteData( AFP_Offset, AFP_Count, AFP_Stride, AFP_Buffer ); break; // fill case FILL: AFP_Error = FillData( AFP_Offset, AFP_Count, AFP_Stride, AFP_Buffer ); break; // erase all case ERASE_ALL: AFP_Error = EraseFlash(); break; // erase sector case ERASE_SECT: AFP_Error = EraseBlock( AFP_Sector ); break; // read case READ: AFP_Error = ReadData( AFP_Offset, AFP_Count, AFP_Stride, AFP_Buffer ); break; // get sector number based on address case GET_SECTNUM: AFP_Error = GetSectorNumber( AFP_Offset, &AFP_Sector ); break; // get sector number start and end offset case GET_SECSTARTEND: AFP_Error = GetSectorStartEnd( &AFP_StartOff, &AFP_EndOff, AFP_Sector ); break; // no command or unknown command do nothing case NO_COMMAND: default: // set our error AFP_Error = UNKNOWN_COMMAND; break; } // clear the command AFP_Command = NO_COMMAND; } // free the buffer if we were able to allocate one if ( AFP_Buffer ) free( AFP_Buffer ); // all done return 0; } ////////////////////////////////////////////////////////////// // ERROR_CODE SetupForFlash() // // Perform necessary setup for the processor to talk to the // flash such as external memory interface registers, etc. // /////////////////////////////////////////
评论
    相关推荐