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

📄 hpi.c.svn-base

📁 lwip协议在arm7+uCos系统上的移植
💻 SVN-BASE
字号:
/****************************************************************************
  文件名称:hpi.c
  版本号:	1.0
  日期:	2005-12-26
  说明:	包含与5402DSP HPI通信相关的函数。
  调用列表:--
  修改历史:--
****************************************************************************/

#include "hpi.h"
#include "IHex5402.h"
#include "sys_UART.h"
/****************************************************************************
  函数名称:HInit()
  说明:	S3C44B0X初始化5402HPIC寄存器
  调用函数:无
  输入参数:无
  输出参数:无
****************************************************************************/
void HInit(void)
{
	unsigned char test;
	test = rHPICh;
	test = rHPICl;
	
	rHPICh = INIT_HPIC;
	//rHPICl = INIT_HPIC;
}
/****************************************************************************
  函数名称:HReadS(unsigned short address, unsigned short* date)
  说明:	读取5402中指定地址的16-bit word数据
  调用函数:无
  输入参数:address:5402中的地址,date:指向返回数据的指针
  输出参数:无
****************************************************************************/
void HReadS(unsigned short address, unsigned short* date)
{
	rHPIAh = *(((unsigned char*)&address)+1);
	rHPIAl = *((unsigned char*)&address);
	
	*(((unsigned char*)date)+1) = rHPIDh;
	*((unsigned char*)date) = rHPIDl;
}

/****************************************************************************
  函数名称:void HWriteS(unsigned short address, unsigned short date)
  说明:	把16-bit word 写到5402中指定地址
  调用函数:无
  输入参数:address:5402中的地址,date:要写入的数据
  输出参数:无
****************************************************************************/
void HWriteS(unsigned short address, unsigned short date)
{
	int i,j;
	
	for(i=0;i<100;i++)	//sdy060724
	{
		j = i;
	}
	
	rHPIAh = *(((unsigned char*)&address)+1);
	rHPIAl = *((unsigned char*)&address);
	
	for(i=0;i<100;i++)	//sdy060724
	{
		j = i;
	}
	
	rHPIDh = *(((unsigned char*)(&date))+1);
	rHPIDl = *((unsigned char*)(&date));
	
	for(i=0;i<100;i++)	//sdy060724
	{
		j = i;
	}
}

/****************************************************************************
  函数名称:void HReadC(unsigned short address, unsigned short* date, int len)
  说明:	把连续的16-bit word 从5402中读到44b0当中
  调用函数:无
  输入参数:address:5402中的地址,date:指向读取buffer的指针,len:读取的长度
  输出参数:无
****************************************************************************/
void HReadC(unsigned short address, unsigned short* date, int len)
{
	int i;
	
	rHPIAh = *(((unsigned char*)&address)+1);
	rHPIAl = *((unsigned char*)&address);
	
	for(i=0;i<len;i++)
	{
		*(((unsigned char*)(date+i))+1) = rCHPIDh;
		*((unsigned char*)(date+i)) = rCHPIDl;
	}
}

/****************************************************************************
  函数名称:void HWriteC(unsigned short address,unsigned short* date, int len)
  说明:	把连续的16-bit word 写到5402当中
  调用函数:无
  输入参数:address:5402中的地址,date:指向读取buffer的指针,len:写入的长度
  输出参数:无
****************************************************************************/
void HWriteC(unsigned short address,unsigned short* date, int len)
{
	int i;
	
	address--;
	rHPIAh = *(((unsigned char*)&address)+1);
	rHPIAl = *((unsigned char*)&address);
	
	for(i=0;i<len;i++)
	{
		rCHPIDh = *(((unsigned char*)(date+i))+1);
		rCHPIDl = *((unsigned char*)(date+i));
	}

}
/****************************************************************************
  函数名称:
  说明:	
  调用函数: 
  输入参数:无
  输出参数:无
****************************************************************************/
unsigned char ASIC2Hex(char *asic) //asic[0]为高位,asic[1]为低位
{
	unsigned char temp = 0;
	int i;
	
	for(i=0;i<2;i++)
	{
		switch(asic[i])
		{
			case (char)0x30:
				temp = temp | 0x00;
				break;
			case (char)0x31:
				temp = temp | 0x01;
				break;
			case (char)0x32:
				temp = temp | 0x02;
				break;
			case (char)0x33:
				temp = temp | 0x03;
				break;
			case (char)0x34:
				temp = temp | 0x04;
				break;
			case (char)0x35:
				temp = temp | 0x05;
				break;
			case (char)0x36:
				temp = temp | 0x06;
				break;
			case (char)0x37:
				temp = temp | 0x07;
				break;
			case (char)0x38:
				temp = temp | 0x08;
				break;
			case (char)0x39:
				temp = temp | 0x09;
				break;
			case (char)0x41:
				temp = temp | 0x0a;
				break;
			case (char)0x42:
				temp = temp | 0x0b;
				break;
			case (char)0x43:
				temp = temp | 0x0c;
				break;
			case (char)0x44:
				temp = temp | 0x0d;
				break;
			case (char)0x45:
				temp = temp | 0x0e;
				break;
			case (char)0x46:
				temp = temp | 0x0f;
				break;
			default:
				break;
		}
		
		if(i==0)
			temp = temp << 4;
	}
	return temp; 
}

/****************************************************************************
  函数名称:
  说明:	
  调用函数: HWriteS();
  			HWriteC();

  输入参数:无
  输出参数:无
****************************************************************************/
/*void PartLoad(char *data)
{
	char tem;
	unsigned char type;
	int i, m, LineP, LineS, LineLen;
	unsigned short address;
	
	i = 0;
	while(1)
	{
		tem = data[i++];
		if(tem == '\0')	//sdy060717
			break;		//the file end
		
		if(tem != ':')
			break;
		
			
		LineLen = (int)ASIC2Hex(data+i);	//get the data length
		i = i + 2;
		
		*(((unsigned char*)&address)+1) = ASIC2Hex(data+i);  //high part of the beginning address
		i = i + 2;
		*((unsigned char*)&address) = ASIC2Hex(data+i);		//low part of the beginning address
		i = i + 2;
		address--;		//decrease the address before continuous copy 
		rHPIAh = *(((unsigned char*)&address)+1);
		rHPIAl = *((unsigned char*)&address);
		
		type = ASIC2Hex(data+i);		//the line type
		i = i + 2;
		
		if(type == 0x01)	//sdy060717
			break;

		m = 0;
		while(1)		//copy the datas to 5402	//sdy060717
		{
			rCHPIDh = ASIC2Hex(data+i);
			i = i + 2;
			m = m+1;
			if(m>=LineLen)
				break;
			
			rCHPIDl = ASIC2Hex(data+i);
			i = i + 2;
			m = m+1;
			if(m>=LineLen)
				break;
		}

		if(m%2==1)
		{
			rCHPIDl = 0x00;
		}
		
		i = i+2;		//skip over the CRC byte
	}
}*/
/****************************************************************************
  函数名称:
  说明:	
  调用函数: HWriteS();
  			HWriteC();

  输入参数:无
  输出参数:无
****************************************************************************/
//sdy060724
void PartLoad(char *data)
{
	char tem;
	unsigned char type;
	int i, m, LineP, LineS, LineLen;
	unsigned short address, content,test_con;
	
	i = 0;
	while(1)
	{
		tem = data[i++];
		if(tem == '\0')	//sdy060717
			break;		//the file end
		
		if(tem != ':')
			break;
		
			
		LineLen = (int)ASIC2Hex(data+i);	//get the data length
		i = i + 2;
		
		*(((unsigned char*)&address)+1) = ASIC2Hex(data+i);  //high part of the beginning address
		i = i + 2;
		*((unsigned char*)&address) = ASIC2Hex(data+i);		//low part of the beginning address
		i = i + 2;
		
		type = ASIC2Hex(data+i);		//the line type
		i = i + 2;
		
		if(type == 0x01)	//sdy060717
			break;

		LineLen = LineLen>>1;
		for(m=0;m<LineLen;m++)		//copy the datas to 5402	//sdy060717
		{
			*(((unsigned char*)&content)+1) = ASIC2Hex(data+i);  //high part of the beginning address
			i = i + 2;
			*((unsigned char*)&content) = ASIC2Hex(data+i);		//low part of the beginning address
			i = i + 2;
			

REWITE:
			HWriteS(address, content);
			HReadS(address,&test_con);
			if(test_con != content)
			{
				#if UART_DEBUG == 1
					UART_Printf("5402 Hpi writing error.\n");
				#endif
				goto REWITE;
			}

			address++;
		}
		
		i = i+2;		//skip over the CRC byte
	}
}
/****************************************************************************
  函数名称:void HBootLoad()
  说明:	通过HPI接口对5402进行bootload
  调用函数: PartLoad()
  输入参数:无
  输出参数:无
****************************************************************************/
void HBootLoad(void)
{

	//PartLoad(D_data);		//load the data part
	PartLoad(P_data);		//load the program part
	
	HWriteS(0x007f, Begin_Ad); //make the 5402 run
}
/****************************************************************************
  函数名称:void Hint(void)
  说明:	
  调用函数: 
  输入参数:无
  输出参数:无
****************************************************************************/
void Hint(void)
{
	rHPICh = INT_HPIC;
	//rHPICl = INT_HPIC;
}
/****************************************************************************
  函数名称:void Hint(void)
  说明:	
  调用函数: 
  输入参数:无
  输出参数:无
****************************************************************************/
void HintClear(void)
{
	rHPICh = INT_CLEAR_HPIC;
	//rHPICl = INT_CLEAR_HPIC;
}

⌨️ 快捷键说明

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