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

📄 set_fpga.c

📁 gzip解压缩算法在tic64x核上的移植。在dm642上测试过。工程中含测试源码
💻 C
字号:

#include <csl.h>
#include <csl_emifa.h>
#include <csl_irq.h>
#include <csl_chip.h>
#include <stdio.h>
#include "seeddm642.h"
void SlaveSerial();
void ShiftDataOut(char Data);
void Check_DONE_Bit();
extern char fout[];
void delay(int delaytime)
{
	int i;
	for(i=0; i<delaytime; i++)
	{
	}
}

void Start_SlaveSerial()
{

	int gpio_value=0;
	int i;


	SlaveSerial();
	for(i=0;i<0;i++)
	{
		gpio_value = 0x0008;//GPIO_RGET(GPVAL);
		GPIO_RSET(GPVAL, gpio_value);
		delay(100);
		gpio_value = 0x000a ;//GPIO_RGET(GPVAL);
		GPIO_RSET(GPVAL,  gpio_value);
		delay(100);
	}
	delay(1000000);
	Check_DONE_Bit();

	GPIO_RSET(GPVAL,0x210a);
}

void ShiftDataOut(char Data )
{
	char DataOut;
	short gpio_value=0;
	DataOut = (Data & 0x80) ? 1 : 0;
	gpio_value = (0x2000|DataOut<<3) & 0xfffd;//GPIO_RGET(GPVAL);
	GPIO_RSET(GPVAL, gpio_value  );
//	delay(5);
	gpio_value = 0x2000 | DataOut<<3 | 0x0002 ;
	GPIO_RSET(GPVAL, gpio_value);
//	delay(5);
	

	DataOut = (Data & 0x40) ? 1 : 0;
	gpio_value = (0x2000|DataOut<<3) & 0xfffd;//GPIO_RGET(GPVAL);
	GPIO_RSET(GPVAL, gpio_value  );
//	delay(5);
	gpio_value = 0x2000 | DataOut<<3 | 0x0002 ;
	GPIO_RSET(GPVAL, gpio_value);
//	delay(5);
	
	
	DataOut = (Data & 0x20) ? 1 : 0;
	gpio_value = (0x2000|DataOut<<3) & 0xfffd;//GPIO_RGET(GPVAL);
	GPIO_RSET(GPVAL, gpio_value  );
//	delay(5);
	gpio_value = 0x2000 | DataOut<<3 | 0x0002 ;
	GPIO_RSET(GPVAL, gpio_value);
//	delay(5);
	
	
	DataOut = (Data & 0x10) ? 1 : 0;
	gpio_value = (0x2000|DataOut<<3) & 0xfffd;//GPIO_RGET(GPVAL);
	GPIO_RSET(GPVAL, gpio_value  );
//	delay(5);
	gpio_value = 0x2000 | DataOut<<3 | 0x0002 ;
	GPIO_RSET(GPVAL, gpio_value);
//	delay(5);
	
	
	DataOut = (Data & 0x08) ? 1 : 0;
	gpio_value = (0x2000|DataOut<<3) & 0xfffd;//GPIO_RGET(GPVAL);
	GPIO_RSET(GPVAL, gpio_value  );
//	delay(5);
	gpio_value = 0x2000 | DataOut<<3 | 0x0002 ;
	GPIO_RSET(GPVAL, gpio_value);
//	delay(5);
	
	
	DataOut = (Data & 0x04) ? 1 : 0;
	gpio_value = (0x2000|DataOut<<3) & 0xfffd;//GPIO_RGET(GPVAL);
	GPIO_RSET(GPVAL, gpio_value  );
//	delay(5);

	gpio_value = 0x2000 | DataOut<<3 | 0x0002 ;
	GPIO_RSET(GPVAL, gpio_value);
//	delay(5);
	
	
	DataOut = (Data & 0x02) ? 1 : 0;
	gpio_value = (0x2000|DataOut<<3) & 0xfffd;//GPIO_RGET(GPVAL);
	GPIO_RSET(GPVAL, gpio_value  );
//	delay(5);
	gpio_value = 0x2000 | DataOut<<3 | 0x0002 ;
	GPIO_RSET(GPVAL, gpio_value);
//	delay(5);
	
	
	DataOut = (Data & 0x01) ? 1 : 0;
	gpio_value = (0x2000|DataOut<<3) & 0xfffd;//GPIO_RGET(GPVAL);
	GPIO_RSET(GPVAL, gpio_value  );
//	delay(5);
	//gpio_value = GPIO_RGET(GPVAL);
	gpio_value = 0x2000 | DataOut<<3 | 0x0002 ;
	GPIO_RSET(GPVAL, gpio_value);
//	delay(5);
	
}

void SlaveSerial()
{
	short gpio_value=0;
//	short Data16;
//	int totalnum=0,
	int i=0;
//	char* flash = (char*)0x90000000;
/*                                                        edit by lzj 12.28
	FILE * fr;
	int read_length=0;
	int read_one=0;
	fr = fopen("E:\\fpgatop.bin","rb");

	for(i=0;i<1024;i++)
	{
		read_one= fread(fd+read_length, 1, 512, fr);
		if(read_one<0) break;
		read_length += read_one;
	}
*/	
	gpio_value = GPIO_RGET(GPVAL);
	GPIO_RSET(GPVAL,gpio_value|0x2000);
	
//	Data16 = 1;  //Initialize Data16 variable before entering While Loop
	
/*
	while(1){
//		Data16 = IORead(CPLD_Input_Reg);    //Read Input Register
		Data16 = GPIO_RGET(GPVAL);
		Data16 = (Data16 & 0x0080);		    //Check Status of /INIT
		if(Data16 == 0x0080) break;
	}
*/
	//	here,we should check the init bit, if the init go high, we can continue to
	//	config the data, but i can not get the gpio value , so i delay it, 
	//	also it can work.
	delay(10000);	
	for(i=0; i<480148; i++) // 480148 is the .bin file length
	{
		//ShiftDataOut(*(fd+i));
		ShiftDataOut(*(fout+i));
	}

}
     
void Check_DONE_Bit(void)
{
	short Data16;
	
	Data16 = GPIO_RGET(GPVAL);
	Data16 = (Data16 & 0x4000)?1:0;
	
	if(Data16==1)
	{
		printf("config done!");
	}else
	{
		Data16 = GPIO_RGET(GPVAL);
		Data16 = (Data16 & 0x80)?1:0;
		if(Data16 == 1)
			printf("config failed, init = high");
		else
			printf("config failed, init = low" );
	}
	
	
}

⌨️ 快捷键说明

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