亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? m25p64.c

?? Blackfin驅(qū)動(dòng), 對SPI flash編程
?? C
?? 第 1 頁 / 共 2 頁
字號:
///////////////////////////////////////////////////////////////
//
// VisualDSP++ 4.0 "Flash Programmer" flash driver for use to
// programm the STMicro. M25P64 SPI flash device.
// M25P64 -- 64Mbit ( 8M x 8 )
// 128 (sectors) x 256 (pages) x 256 (bytes)
// 
///////////////////////////////////////////////////////////////

// error enum
#include "Errors.h"
#include <cdefBF533.h>
#include <stdio.h>

// #defines
#define TRUE			0x1
#define FALSE			0x0
// #define NULL			0x0
#define BUFFER_SIZE		0x600
#define	NUM_SECTORS 	128		// number of sectors in the M25P20 flash device

//Application definitions
#define COMMON_SPI_SETTINGS (SPE|MSTR|CPHA|CPOL) //Settings to the SPI_CTL
#define TIMOD01 (0x01)		//stes the SPI to work with core instructions
#define BAUD_RATE_DIVISOR 200

//Flash commands
#define SPI_WREN            (0x06)  //Set Write Enable Latch
#define SPI_WRDI            (0x04)  //Reset Write Enable Latch
#define SPI_RDSR            (0x05)  //Read Status Register
#define SPI_WRSR            (0x01)  //Write Status Register
#define SPI_READ            (0x03)  //Read data from memory
#define SPI_PP              (0x02)  //Program Data into memory
#define SPI_SE              (0xD8)  //Erase one sector in memory
#define SPI_BE              (0xC7)  //Erase all memory
#define WIP					(0x1)	//Check the write in progress bit of the SPI status register
#define WEL					(0x2)	//Check the write enable bit of the SPI status register

#define TIMEOUT        35000*64

// structure for flash sector information
// for the purpose of erase single sectors of the SPI flash the right sector must be chosen
typedef struct _SECTORLOCATION
{
	long lStartOff;
	long lEndOff;
	
}SECTORLOCATION;


// Flash Programmer commands
// The VisualDSP++ flash progammer plug-in "Flash Programmer Tool" will send commands
// to this driver. These commands will be taken to execute the corresponding C function
// The commands are used at the switch case below.
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
}enProgCmds;




// function prototypes
ERROR_CODE SetupForFlash();
ERROR_CODE GetCodes();
ERROR_CODE Wait_For_Status(char Statusbit);
ERROR_CODE Wait_For_WEL();
ERROR_CODE ResetFlash();
ERROR_CODE EraseFlash();
ERROR_CODE EraseBlock( int nBlock );
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 WriteData( unsigned long ulStart, long lCount, long lStride, int *pnData );
ERROR_CODE GetSectorNumber( unsigned long ulOffset, int *pnSector );
ERROR_CODE WriteFlash ( unsigned long StartAddr, long Count, long Stride, int *pnData, long *pnWriteCount );

char ReadStatusRegister(void);
void Wait_For_SPIF(void);
void SetupSPI( const int spi_setting );
void SPI_OFF(void);
void SendSingleCommand( const int iCommand );


// global data for use with the VisualDSP++ plug-in
// The plug-in will modify some AFP variables to control this driver
char 			*AFP_Title = "ADSP-BF533 STAMP";	// This title will be displayed in the plug-in
char 			*AFP_Description = "STMicro. M25P64";	// The description will also be displayed in the plug-in
enProgCmds 		AFP_Command = NO_COMMAND;				// AFP_Command is dedicated to control programm flow
int 			AFP_ManCode = 0x20;						// Some devices have Manufacturer codes to autodetect the device
int 			AFP_DevCode = 0x20;						// Some devices have device codes to autodetect the device
unsigned long 	AFP_Offset = 0;							// AFP_Offset holds the start address to the SPI device
int 			*AFP_Buffer;							// The plug-in copies the content of the *.ldr file to the buffer in small portions
long 			AFP_Size = BUFFER_SIZE;					// The AFP_Buffer size can be modified to change the size
long 			AFP_Count = -1;							// The plug-in copies the number of transfers to be executed to the AFP_Count 
long 			AFP_Stride = -1;						// For the plug-in Fill function a stride can optionally be inserted
int 			AFP_NumSectors = NUM_SECTORS;			// The number of SPI sectors are given for sector erase function
long 			AFP_SectorSize1 = 0x10000;				// The multiplier factor from sector to sector must be given
int 			AFP_Sector = -1;						// In case of sector erase the right sector must be chosen and hold in here
int 			AFP_Error 			= 0;				// contains last error encountered
bool 			AFP_Verify 			= FALSE;			// verify writes or not
long 			AFP_StartOff 		= 0x0;				// sector start offset
long 			AFP_EndOff 			= 0x0;				// sector end offset
int				AFP_FlashWidth		= 0x8;				// width of the flash device taken
int 			*AFP_SectorInfo;
SECTORLOCATION SectorInfo[NUM_SECTORS];


// exit flag
bool bExit = FALSE;


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
	
	// The AFP_Buffer gets filled by the programmer plug-in. The data the plug-in fetches
	// from the *.ldr file will be stored in the AFP_Buffer byte wise to avoid gaps in the buffer.
	// The verify command uses the buffer to store the data read from the SPI flash for comparison.
	// The fill command uses the first address of the buffer to hold the value to be filled.
	
	// -In case of loading the code to the SPI flash the plug-in will fill the buffer automatically 
	//  so that this driver just has to fetch the data from the buffer and tranfer it to the SPI flash.
	// -In case of reading the data from the SPI flash (plug-in command "VERIFY") this driver just has 
	//  to fetch the data from the SPI flash and store it in the buffer.
	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;
	}



	AFP_SectorInfo = (int*)&SectorInfo[0];
	
	
	for(i=0;i<NUM_SECTORS;i++){

	// This is the sector table of the STMicro. M25P64 SPI flash device.
			SectorInfo[i].lStartOff = 0x0000 + i* 0x10000;
			SectorInfo[i].lEndOff 	= 0xFFFF + i* 0x10000;
	}

	// The while loop below is inserted to give the programmer plug-in control over this driver

	// the plug-in will set a breakpoint at "AFP_BreakReady" forcing the processor to stop.
	// After the plug-in starts the processor again the function which is selected by AFP_Command will be executed.
	// After execution the function the processor stops again at the breadpoint at "AFP_BreakReady".
	// Now the plug-in can place the next command in AFP_Command and start the processor again. 

	while ( !bExit )
	{
		asm("AFP_BreakReady:");
				
		if ( FALSE )
			asm("jump AFP_BreakReady;");

		// switch on the command
		switch ( AFP_Command )
		{
			// As the plug-in displays manufacturer and device ID this function will fetch it from the SPI flash
			// The STMicro. M25P64 SPI flash device does not have those IDs so the function is empty.
			case GET_CODES:
				AFP_Error = GetCodes();
				break;

			// The plug-in offers to reset the flash. This function will send a "write disable command to the SPI flash.
			//  Additionally, it checks the status register for the write enable bit "WEL" to be cleared.
			case RESET:
				AFP_Error = ResetFlash();
				break;

			// By taking the parameters below the function "WriteData" will program the flash.
			// AFP_Offset points to the SPI destination address, AFP_Count holds the number of transfers
			// AFP_Stride holds the address increment and finally AFP_Buffer points to the source buffer.
			case WRITE:
				AFP_Error = WriteData( AFP_Offset, AFP_Count, AFP_Stride, AFP_Buffer );
				break;

			// As the programmer plug-in allows to simply fill the SPI flash with any value the 
			// "FILL" function includes the code. The AFP_Offset points to the destination while the AFP_Count 
			// holds the number of locations where the value will be placed. AFP_Stride holds the increment
			// while AFP_Buffer points to the memory source.
			case FILL:
				AFP_Error = FillData( AFP_Offset, AFP_Count, AFP_Stride, AFP_Buffer );
				break;

			// Pushing the "Erase" button on the programmer plug-in the driver executes an erase all command.
			case ERASE_ALL:
				AFP_Error = EraseFlash();
				break;

			// Pushing the "Erase Sectors" button on the programmer plug-in makes the driver to take the value from
			// AFP_Sector and sends the erase sector command followed by the start address of the dedicated sector.
			// The AFP_Sector gets filled by running the function GET_SECTNUM driven by the plug-in
			case ERASE_SECT:
				AFP_Error = EraseBlock( AFP_Sector );
				break;

			// In order to verify the data that has been programmed to the flash the data must been read.
			// This function will be entered when pushing the Verify button.
			case READ:
				AFP_Error = ReadData( AFP_Offset, AFP_Count, AFP_Stride, AFP_Buffer );
				break;

			// Based on the address where to start programming this sector must be erased before. 
			// The function GET_SECTNUM will return the sector number where the start address points to.
			// The sector number will than be taken to run the EraseBlock function.
			case GET_SECTNUM:
				AFP_Error = GetSectorNumber( AFP_Offset, &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 WriteData()
//
// Write the contents of AFP_Buffer to SPI flash.
//
// Inputs:	unsigned long ulStart - SPI start address 
//			long lCount - number of elements write to the SPI
//			long lStride - address increment to the SPI
//			int *pnData - pointer to data buffer
//
// This function takes the input parameters and calls the function 
// WriteFlash which writes the data of AFP_Buffer to the SPI.
//
// The function WriteFlash will usually be executed multiple times because 
// the SPI needs a break after a transfer of max. 256 bytes for programming
// each following transfer will need recalculated addresses and counts
//////////////////////////////////////////////////////////////

ERROR_CODE WriteData( unsigned long ulStart, long lCount, long lStride, int *pnData )
{

	unsigned long ulWStart = ulStart; 
	long lWCount = lCount, lWriteCount;
	long *pnWriteCount = &lWriteCount;
	int i;
	
	
	ERROR_CODE ErrorCode = NO_ERR;

	while (lWCount != 0)
	{
		ErrorCode = WriteFlash(ulWStart, lWCount, lStride, pnData, pnWriteCount);
		
		// After each function call of WriteFlash the counter must be adjusted
		lWCount -= *pnWriteCount;
		
		// Also, both address pointers must be recalculated.
		ulWStart += *pnWriteCount;
		pnData += *pnWriteCount/4;
	}

	for(i=0; i<1000; i++)
	{
		asm("nop;");
	}

	
	// return the appropriate error code
	return ErrorCode;
	
}


//////////////////////////////////////////////////////////////
// ERROR_CODE FillData()
//
// Fill flash with a value.
//
// Inputs:	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
//
//////////////////////////////////////////////////////////////

ERROR_CODE FillData( unsigned long ulStart, long lCount, long lStride, int *pnData )
{

	
	unsigned long ulWAddr = ulStart; 
	long lWCount = 1, lWriteCount;
	long *pnWriteCount = &lWriteCount;

	int i;
	ERROR_CODE ErrorCode = NO_ERR;	// tells us if there was an error erasing flash

	
    for (i = 0; i < lCount; i++, ulWAddr += lStride)
	{
		ErrorCode = WriteFlash(ulWAddr, lWCount, lStride, pnData, pnWriteCount);
	}
	
	
	for(i=0; i<1000; i++)
	{
		asm("nop;");
	}
	
	// return the appropriate error code
	return ErrorCode;
	
}



//////////////////////////////////////////////////////////////
// ERROR_CODE WriteFlash()
//
// Write the maximum of 256 bytes to flash.
//
// Inputs:	unsigned long StartAddr - address to write to
//			int iDataSource - pointer to the AFP_Buffer
//			long lTransferCount - number of elements to send
//////////////////////////////////////////////////////////////

ERROR_CODE WriteFlash ( unsigned long ulStartAddr, long lTransferCount, long lModify, int *iDataSource, long *lWriteCount )
{

	unsigned long ulWAddr;
	long lWTransferCount = 0;
	int i;
	char iData;
	char *temp = (char *)iDataSource;
	int dummyread;
	ERROR_CODE ErrorCode = NO_ERR;	// tells us if there was an error erasing flash

	// First, a Write Enable Command must be sent to the SPI.
	SendSingleCommand(SPI_WREN);
	
	// Second, the SPI Status Register will be tested whether the 
	//         Write Enable Bit has been set. 
	ErrorCode = Wait_For_WEL();

	if( POLL_TIMEOUT == ErrorCode )
		return ErrorCode;
	else

	// Third, the 24 bit address will be shifted out the SPI MOSI bytewise.
	SetupSPI( (COMMON_SPI_SETTINGS|TIMOD01) ); // Turns the SPI on

	*pSPI_TDBR = SPI_PP;
	Wait_For_SPIF();		//wait until the instruction has been sent
	ulWAddr = (ulStartAddr >> 16);
	*pSPI_TDBR = ulWAddr;
	Wait_For_SPIF();		//wait until the instruction has been sent
	ulWAddr = (ulStartAddr >> 8);
	*pSPI_TDBR = ulWAddr;
	Wait_For_SPIF();		//wait until the instruction has been sent
	ulWAddr = ulStartAddr;
	*pSPI_TDBR = ulWAddr;
	Wait_For_SPIF();		//wait until the instruction has been sent
	dummyread = *pSPI_RDBR;	//read dummy to empty the receive register

	
	// Fourth, maximum number of 256 bytes will be taken from the Buffer
	// and sent to the SPI device.
	for (i=0; (i < lTransferCount) && (i < 256); i++, lWTransferCount++)
	{
		iData = *temp;
		*pSPI_TDBR = iData;
		Wait_For_SPIF();		//wait until the instruction has been sent

		((unsigned char *) temp) ++;
	}
		
	SPI_OFF(); // Turns the SPI off

	// Sixth, the SPI Write in Progress Bit must be toggled to ensure the 
	// programming is done before start of next transfer.
	ErrorCode = Wait_For_Status(WIP);
	
	if( POLL_TIMEOUT == ErrorCode )
		return ErrorCode;
	else


	
	*lWriteCount = lWTransferCount;
	
	return ErrorCode;
}

//////////////////////////////////////////////////////////////
// ERROR_CODE ReadData()
//
// Read a value from flash for verify purpose
//
// Inputs:	unsigned long ulStart - holds the SPI start address
//			int pnData - pointer to store value read from flash
//			long lCount - number of elements to read

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99精品久久99久久久久| 久久精品一区四区| 国产精品午夜免费| 国产一区二区三区在线看麻豆| 91在线视频网址| 97精品久久久午夜一区二区三区| 国产视频在线观看一区二区三区| 国产麻豆视频一区二区| 日本一区二区视频在线| 久草热8精品视频在线观看| 欧美日免费三级在线| 综合激情网...| 欧美三区免费完整视频在线观看| 中文一区二区完整视频在线观看 | 日韩av一级片| 中文字幕五月欧美| 国产日韩精品视频一区| 欧美电影免费观看高清完整版 | 亚洲精品欧美激情| 国产日产欧美一区二区视频| 精品久久久久久久久久久院品网| 欧美这里有精品| 欧美唯美清纯偷拍| 欧美一区二区三区系列电影| 911国产精品| 欧美图区在线视频| 3d动漫精品啪啪一区二区竹菊 | 美国av一区二区| 免费人成在线不卡| 成人综合婷婷国产精品久久| 91精彩视频在线| 精品国产一区二区三区四区四| 欧美国产欧美亚州国产日韩mv天天看完整 | 色综合久久99| 久久综合狠狠综合久久激情| 亚洲日本一区二区三区| 日韩专区在线视频| 成人小视频免费在线观看| 欧美性极品少妇| 亚洲欧美国产三级| 精品国产区一区| 日韩美女一区二区三区| 精品成人一区二区| 精品成a人在线观看| 国产网红主播福利一区二区| 国产亚洲欧美一区在线观看| 久久综合色播五月| 久久精品亚洲麻豆av一区二区 | 99久久免费精品高清特色大片| 不卡的av电影在线观看| 亚洲国产精品精华液ab| 国产在线一区观看| 亚洲国产精品精华液2区45| 国产白丝精品91爽爽久久 | 91小视频免费观看| 国产精品免费视频一区| thepron国产精品| 欧美在线看片a免费观看| 欧美高清激情brazzers| 中文字幕在线一区| 亚洲bdsm女犯bdsm网站| 成人sese在线| 日韩欧美一级精品久久| 一区二区日韩av| 国产永久精品大片wwwapp | 欧美日韩黄色一区二区| 中文字幕不卡在线播放| 亚洲高清视频中文字幕| 丰满放荡岳乱妇91ww| 日韩视频中午一区| 亚洲国产三级在线| caoporen国产精品视频| 精品日本一线二线三线不卡| 亚洲午夜视频在线| 在线观看免费一区| 亚洲综合另类小说| 91网站在线播放| 亚洲欧美偷拍三级| 一本大道久久a久久精品综合| 久久久久国产精品人| 国产精品资源在线看| 久久中文娱乐网| 成人开心网精品视频| 亚洲私人影院在线观看| 欧美在线观看禁18| 六月丁香综合在线视频| 久久精品日产第一区二区三区高清版| 粉嫩高潮美女一区二区三区| 亚洲精品免费一二三区| 久久久久久电影| 7777精品久久久大香线蕉| 成人综合激情网| 日本欧美久久久久免费播放网| 成人欧美一区二区三区白人| 欧美日韩国产精品自在自线| 国产成人午夜精品5599| 美腿丝袜在线亚洲一区| 亚洲最大成人综合| 国产女人水真多18毛片18精品视频| 欧美日韩一级二级| 欧美性猛交xxxxxx富婆| 91网上在线视频| 在线区一区二视频| 欧美三级视频在线| 色婷婷综合在线| 93久久精品日日躁夜夜躁欧美| 激情欧美一区二区| 麻豆国产精品官网| 免费黄网站欧美| 免费美女久久99| 国产一本一道久久香蕉| 精品综合免费视频观看| 国产一区二区毛片| 国产传媒一区在线| 色综合天天综合狠狠| 在线观看三级视频欧美| 51精品国自产在线| 26uuu色噜噜精品一区| 欧美经典三级视频一区二区三区| 久久一夜天堂av一区二区三区| 国产农村妇女精品| 洋洋av久久久久久久一区| 偷拍亚洲欧洲综合| 国产成人精品免费| 欧美妇女性影城| 国产精品成人一区二区三区夜夜夜| 成人欧美一区二区三区黑人麻豆| 午夜精品久久久久影视| 国产一区三区三区| 蜜桃一区二区三区在线| 欧美国产欧美综合| 日韩成人dvd| 欧美视频中文字幕| 一区二区三区四区高清精品免费观看| 激情丁香综合五月| 久久精品欧美一区二区三区麻豆| 日本在线播放一区二区三区| 欧美在线视频你懂得| 亚洲福利国产精品| 欧美日韩一区二区三区在线看 | 一区二区三区蜜桃| 91久久一区二区| 亚洲国产va精品久久久不卡综合| 在线观看日韩精品| 亚洲电影第三页| 日韩欧美在线一区二区三区| 免费看欧美美女黄的网站| 色综合天天天天做夜夜夜夜做| 国产aⅴ精品一区二区三区色成熟| 中文字幕二三区不卡| 欧美日韩成人在线一区| 国产精品每日更新| 色噜噜狠狠成人中文综合| 亚洲三级久久久| 欧美日本国产视频| 激情六月婷婷久久| 亚洲欧洲国产日本综合| 一本色道久久综合精品竹菊| 亚洲综合成人在线| 欧美一区三区二区| 国产91在线观看丝袜| 亚洲精品一二三| 精品国产免费人成在线观看| 国产河南妇女毛片精品久久久| 久久精品亚洲麻豆av一区二区| 99免费精品视频| 久久精品国产在热久久| 国产精品久久久久久久久图文区 | 国产伦理精品不卡| 亚洲人成网站精品片在线观看| 欧美三级视频在线播放| 国产精品99久久久久久似苏梦涵 | 国产精品国产a| 91精品婷婷国产综合久久 | 欧美精品第1页| 91精品办公室少妇高潮对白| 国产麻豆精品95视频| 日韩精品乱码免费| 亚洲精品久久嫩草网站秘色| 国产欧美一区二区精品秋霞影院| 欧美精品视频www在线观看| 一本一道久久a久久精品综合蜜臀| 国产乱人伦精品一区二区在线观看| 亚洲高清免费视频| 婷婷综合另类小说色区| 亚洲国产成人av网| 日本aⅴ亚洲精品中文乱码| 亚洲成人免费av| 天天色天天操综合| 免费高清视频精品| 精品一区二区三区久久久| 精品中文字幕一区二区| 国产成人精品影视| 91论坛在线播放| 91国偷自产一区二区开放时间 | 欧美成人aa大片| 国产精品视频一二三区 | 黄色小说综合网站| 天堂一区二区在线免费观看| 卡一卡二国产精品|