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

📄 sys_init.cpp

📁 TMS320VC5502 DSP BootLoad源码 包括CPLD源码
💻 CPP
字号:
#include "system5501.h"
#include "sys_init.h"
void delay(int delay);

int fnSysInit(DSP5501_PLL *pPLL, DSP5501_EMIF *pEMIF)
{
	fnSetClk(pPLL);
	fnSetEmif(pEMIF);
	return 0;
}



/*---------------------------------------------------
|                  SETUP CLOCK                      |
|--------------------------------------------------*/
int fnSetClk(DSP5501_PLL *pPLL)
{
//Set Pll
	*(pPLL->PLLCSR)&=0xfffe;
		//1.pllen=0,pll and divider1 in bypass mode
	*(pPLL->PLLCSR)|=0x8;
		//2.reset pll
	*(pPLL->PLLM)=0xf;
	//3.set pllm and plldiv0
	for(int i=300;i>0;)//4.wait for 1us
	{
		i+=1;
		i-=2;
	}
	*(pPLL->PLLCSR)&=0xfff7;
		//5.release pll from reset mode
	while( (*(pPLL->PLLCSR)&0x60)!=0x60 )//6.wait for pll lock
	{	}
	*(pPLL->PLLCSR)|=0x1;//7.pllen to 1
	*(pPLL->CLKOUTSR)|=0x1;//disable clkout
	return 0;
}
/*---------------------------------------------------
|                  SETUP EMIF                       |
|--------------------------------------------------*/
int fnSetEmif(DSP5501_EMIF *pEMIF)
{
//SET SDRAM
	pEMIF->fnSetCe0Sdram();
  
	*(pEMIF->SDCR2)|=0x100;
	for(int temp=5;temp>0;)
	{
		temp=*(pEMIF->SDCR2);
		temp&=0x0100;
		if(temp==0)  
			temp=-5;
		else 
			temp=5;
	}
//Set  CE1-3
	*(pEMIF->CE1SCR1)=0x8713;
	*(pEMIF->CE1SCR2)=0x31e3;
	*(pEMIF->CE2SCR1)=0x8713;
	*(pEMIF->CE2SCR2)=0x31e3;
	*(pEMIF->CE3SCR1)=0x8713;
	*(pEMIF->CE3SCR2)=0x31e3;

   	return 0;
}
/*---------------------------------------------------
|                  Erase Flash                       |
|--------------------------------------------------*/
int FlashErase (void)
{
	int iCount;
	GPIO_DIR&=0xbf;//GPIO6 is Input pin
	//操作CE3上的32位Flash
	/*unsigned long *p=(unsigned long *)0x600000;
	*(p+0x555)=0xaa00aa;
	*(p+0x2aa)=0x550055;
	*(p+0x555)=0x800080;
	*(p+0x555)=0xaa00aa;
	*(p+0x2aa)=0x550055;
	*(p+0x555)=0x100010;*/
//___________________________________________________________
	//操作CE3上的16位Flash
	unsigned int *p=(unsigned int *)FLASHBASEADD;
	*(p+0x555)=0xaa;
	*(p+0x2aa)=0x55;
	*(p+0x555)=0x80;
	*(p+0x555)=0xaa;
	*(p+0x2aa)=0x55;
	*(p+0x555)=0x10;
	delay(1000);
	for(iCount=0;iCount==0;)
	{
		if( (GPIO_DATA & 0x40)!=0 )
			iCount=1;
	}
	return 0;
}

/*---------------------------------------------------
|                  Write Flash                       |
|--------------------------------------------------*/
int FlashWrite(unsigned int * const pPointToSource,
				unsigned int * const pPointToFlash,
				unsigned int iSize)
{
	unsigned int iCount=0;
	unsigned int iSizeCount=0;
	unsigned int *pPointToFalshBase=(unsigned int *)FLASHBASEADD;
	GPIO_DIR&=0xbf;//GPIO6 is Input pin

	for(iSizeCount=0;iSizeCount<iSize;iSizeCount++)
	{
		*(pPointToFalshBase+0x555)=0xaa;
		*(pPointToFalshBase+0x2aa)=0x55;
		*(pPointToFalshBase+0x555)=0xa0;
		*(pPointToFlash+iSizeCount)=*(pPointToSource+iSizeCount);
		delay(1000);
		for(iCount=0;iCount==0;)
		{
			if( (GPIO_DATA & 0x40)!=0 )
				iCount=1;
		}
	}
	return 0;
}
/*---------------------------------------------------
|                      DELAY                        |
|--------------------------------------------------*/
void delay(int delay)
{
	for (;delay>=0;delay--)
	{
		delay-=1;
	}
}

⌨️ 快捷键说明

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