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

📄 hello.c

📁 6713falsh burn 烧写flash
💻 C
字号:
/*
 *  Copyright 2007 by WXK
 * 
 */
/**************************************************************************/
/*                                                                         */
/*     c6713test . C                                                       */
/*                                                                         */
/*     Basic C standard I/O from main.                                     */
/*                                                                         */
/*                                                                         */
/***************************************************************************/

#include "c6713regs.h"
#define SramBaseAddr 0x80000000
#define FlashBaseAddr 0x90000000
#define CodeLength 0x20000 
void sys_init();
void WriteIsOver(void);
void EraseChip(void);
void WriteWord(unsigned int,unsigned int);
unsigned int i,codestart,codeend;
unsigned PData,PAdrr;
unsigned count,temp;

/*
 *  ======== main ========
 */


void main()
{
  sys_init();
  count = 0;
  
  EraseChip();
  
//  Program  Chip
//------------------------------------------------------------
	for(i=0;i<CodeLength;i++)	{
		PAdrr = i;
		PData = PFUNC_wordRead(PAdrr);		
		
		WriteWord(i,PData);
		
		temp = *(volatile unsigned char*)(FlashBaseAddr + i<<1);
		if(temp!=PData) count++;
	}	
//	WriteWord(0x0000,0x00F0);		//read mode
	for(i=0;i<CodeLength;i++)	{
		
		temp = *(volatile unsigned char*)(FlashBaseAddr + PAdrr);
		
	}	
	while(1);
  
					
}

void sys_init()
{
/* config the CSR,disables all interrupts,except the reset and NMI */
	asm(" mvk 00000100h,a0 ");
	asm(" mvc a0,CSR ");

/* config the AMR(addressing mode register) */
	asm(" mvk 00000000h,a0 ");
	asm(" mvc a0,AMR ");	//all mode are linear modification

/* congig the interrupt Enable Register */
	asm(" mvk 00000001h,a0 ");
	asm(" mvc a0,IER ");	//disable all nonreset interrupts
	
	DEVCFG = 0x0000000F;	//2 I2C + 2 McASP + GPIO

/* config the EMIF registers */
	GBLCTL = 0x00003080;	//clkout1 and clkout2 are held high,hold is disabled
	CECTL1 = 0x22F1D113;	//asynchronous 16-bit-wide interface
	CECTL0 = 0xFFFFFF13;	//asynchronous 16-bit-wide interface
	
	EXTPOL = 0x00000000;	//a low-to-high transition on an interrupt source is recognized as an interrupt

/* config the PLL registers */
//	PLLCSR = 0x00000009;	//divider D0 and PLL are not bypassed
//	PLLM = 0x00000004;		//*4
//	PLLDIV0 = 0x00008001;	//divided by 2,dsp core is working at 40M
//  if the core work at 40M,the power supply is not enough	

/* config the cache registers */
	CCFG = 0x00000007;	//4-way cache 64k
	MAR0 = 0x00000001;  //Memory CE0 is cacheable.
/* config the GPIO registers */
	GPEN = 0x0000FFFF;	    
}

void EraseChip(void)
{
	/*由于设置CECTL1为16位异步,所以Am29Lv160的[19:0]对应C6713的EA[20:1]*/
	*(volatile unsigned int*)(FlashBaseAddr + 0x555<<1) = 0xaa;
	*(volatile unsigned int*)(FlashBaseAddr + 0x2aa<<1) = 0x55;
	*(volatile unsigned int*)(FlashBaseAddr + 0x555<<1) = 0x80;
	*(volatile unsigned int*)(FlashBaseAddr + 0x555<<1) = 0xaa;
	*(volatile unsigned int*)(FlashBaseAddr + 0x2aa<<1) = 0x55;
	*(volatile unsigned int*)(FlashBaseAddr + 0x555<<1) = 0x10;
//	WriteIsOver();
}

void WriteWord(unsigned int Addr, unsigned int Val)
{
	*(volatile unsigned int*)(FlashBaseAddr + 0x555<<1) = 0xaa;
	*(volatile unsigned int*)(FlashBaseAddr + 0x2aa<<1) = 0x55;
	*(volatile unsigned int*)(FlashBaseAddr + 0x555<<1) = 0xa0;
	*(volatile unsigned int*)(FlashBaseAddr + Addr<<1) = Val;
//	WriteIsOver();
}

void WriteIsOver(void)
{
	unsigned int i;
	unsigned int LastToggleBit,CurrentToggleBit;
	LastToggleBit = (*(volatile unsigned char*)FlashBaseAddr) & 0x40;
	CurrentToggleBit = (*(volatile unsigned char*)FlashBaseAddr) & 0x40;
	for(i = 0; ; i++)
	{
		LastToggleBit = CurrentToggleBit;
		CurrentToggleBit = (*(volatile unsigned char*)FlashBaseAddr) & 0460;
		if( LastToggleBit == CurrentToggleBit ) break;			
	}
}

	


⌨️ 快捷键说明

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