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

📄 dec6713_flash.c

📁 6713flash测试烧写程序
💻 C
字号:


#include <stdio.h>
#include <csl.h>
#include <csl_irq.h>
#include <csl_chip.h>
#include <csl_emif.h>
#include <csl_irq.h>
#include "DEC6713_FLASH.h"
#include <math.h>

/********************************************************************************/

Uint32 i;
Uint32 TempData;
Uint32 Src_StartAdd;
Uint32 Dst_StartAdd;
extern far void vectors();
/********************************************************************************/
/********************************************************************************/
void main()
{
	Src_StartAdd = 0x90000000;
	/* Initialize CSL, must when using. */
	CSL_init();
	
	/* Initialize DEC6713 board. */
	DEC6713_init();
	
	/* Configure interrupt. */
	IRQ_setVecs(vectors);
    IRQ_nmiEnable();
    IRQ_globalEnable();
    
    /* Erase flash memory. */
    Flash_Erase(0x90000000,0x10);
	printf("\nErase flash ok.");
	
    /* Write flash memory. */
    for(i=0;i<0x40000;i++)
    {
    	Flash_Writes(Src_StartAdd+2*i,fmod(i,0x10000));
    }
    printf("\nWrite flash ok.");
    	
    /* Read flash memory. */
    for(i=0;i<0x40000;i++)
    {
    	TempData = Flash_Reads(Src_StartAdd+2*i);
    	if(TempData != fmod(i,0x10000))
    	{
    		printf("\n Testing is Failure!");
    		printf("\nAddress 0x%x is error!",i);
    		exit(0);
    	}
    }
	
	printf("\nOpereation is success.");
}
/********************************************************************************\
\*	Flash function difine. *\
\********************************************************************************/
/********************************************************************************\
\* Flash erase function. *\
\********************************************************************************/
Uint32 Flash_Erase(Uint32 addr,Uint16 type)
{
	Uint32 i,j;
	*FLASH_5555 = FLASH_UL1;	//first
	*FLASH_2AAA = FLASH_UL2;	//second
	*FLASH_5555 = FLASH_UL3;	//third
	*FLASH_5555 = FLASH_UL4;
	*FLASH_2AAA = FLASH_UL5;
	switch(type)
	{
		case 0x50:		//block erase
			*(Uint16 *)addr = type;
			while((*(Uint16 *)addr & 0x80) != 0x80);
			for(i = 0; i < BLOCK_SIZE; i++)
			{
				if(*(Uint16 *)(addr + i) != 0xffff)
				{
					j = 0;
					break;
				}
			}
			j = 1;
			break;
		
		case 0x30:		//sector erase
			*(Uint16 *)addr = type;
			while((*(Uint16 *)addr & 0x80) != 0x80);
			for(i = 0; i < SECTOR_SIZE; i++)
			{
				if(*(Uint16 *)(addr + i) != 0xffff)
				{
					j = 0;
					break;
				}
			}
			j = 1;
			break;
			
		case 0x10:		//chip erase
	//	for(;;)
	//	{
			*FLASH_5555 = type;
	//	}
			while((*FLASH_5555 & 0x80) != 0x80);
			for(i = 0; i < CHIP_SIZE; i++)
			{
				if(*(Uint16 *)(addr + i) != 0xffff)
				{
					j = 0;
					break;
				}
			}
			j = 1;
			break;
		
		default:
			break;
	}
	return (j);
}

/********************************************************************************\
\*  Write a single data. *\
\********************************************************************************/
void Flash_Writes(Uint32 addr,Uint16 data)
{
	//Uint16 TempData=0;
	*FLASH_5555 = FLASH_UL1;
	*FLASH_2AAA = FLASH_UL2;
	*FLASH_5555 = FLASH_PROGRAM;
    //for(;;)
    //{
	*(Uint16 *)addr = data;
	//TempData = *(Uint16 *)(addr);
	//}
	//TempData = *(Uint16 *)(addr);
	while(*(Uint16 *)addr != data);
}

/********************************************************************************\
\* Write the certain length data. *\
\********************************************************************************/
void Flash_Writem(Uint32 addr,Uint16 *ptr,Uint32 length)
{
	Uint32 i;
	for(i  = 0; i < length; i++)
	{
	//	for(;;)
	//	{
		Flash_Writes(addr+2*i,*(ptr+i));
	//	}
	}
}

/********************************************************************************\
\* Read a single data. *\
\********************************************************************************/
Uint32 Flash_Reads(Uint32 addr)
{
	return (*(Uint16 *)addr);
}

/********************************************************************************\
\* Read the certain length data. *\
\********************************************************************************/
void Flash_Readm(Uint32 addr,Uint16 *ptr,Uint32 length)
{
	Uint32 i;
	for(i = 0; i < length; i++)
	{
		*(ptr + i) = Flash_Reads(addr+2*i);
	}
}

/********************************************************************************\
\* End of DEC6713_FLASH.C *\
\********************************************************************************/


⌨️ 快捷键说明

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