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

📄 uart_rec.c

📁 本程序是arm开发bios的实例代码
💻 C
字号:
#include "console.h"
#include "utils.h"#include "bios.h"

unsigned long exactnum(int number,int degree,int flag)
{
	int i=0;	unsigned long value=1;
	for(i=1;i<degree;i++)
		value=value*flag;	value=value*number;
	return value;
}


unsigned long getnumber(int flag)
{
	unsigned long bytenum=0;
	int sh,temp[16],array[16];
	int value=0,k=0,i;
	int maxdegree;
	int ch;
		
	while(1)
	{
		ch=getch();		putch(ch);				if((ch==KEY_ENTER)||(ch==KEY_ESC))			break;		value+=1;		temp[value]=(int) ch;	}		for(i=1;i<=value;i++)	{			if (temp[i] >= '0' && temp[i] <= '9')		{				sh = temp[i] - '0';			k+=1;			array[k]=sh;		}		else if (temp[i] >= 'a' && temp[i] <= 'f')		{			sh= temp[i] - 'a' + 0xa;			k+=1;			array[k]=sh;		}		else if (temp[i] >= 'A' && temp[i] <= 'F')		{			sh = temp[i] - 'A' + 0xa;			k+=1;			array[k]=sh;		}		else 			;	
		
	}
	
	maxdegree=k;
	
	for(i=1;i<=k;i++)
	{
		bytenum+=exactnum(array[i],maxdegree,flag);
		maxdegree--;	}
	
	return bytenum;	
}
		
		
int uart_receive(void)
{
	int ch,i,j;
	unsigned long imagebytes=0,linkaddress;	char *p;
	typedef void (FP)(void);
	FP *run_ptr;
	
	
	console_init();		//19200,N,0
	printf("In order to receive binary file properly\r\n");
	printf("Please input the precise bytes of your image\r\n");
	printf("The precise bytes of image is:");
	
	while(kbhit())		getch();		imagebytes=getnumber(10);
	
	printf("\r\nimagebytes=%d",imagebytes);		if(!imagebytes)
		return 1;
	
	printf("\n\nPlease input the link address of the image!\r\n");
	printf("The link address of image is 0x");
		while(kbhit())		getch();
	linkaddress=getnumber(16);				printf("\n\nlinkaddress=%d\n",linkaddress);	
	
	p=(char *)linkaddress;
	memset(p,0,0x200000);	
	
	printf("\n\nUART0 is listening image from PC......\r\n");
	printf("Enter ESC to quit!\r\n\r\n");
	
	while(kbhit())		getch();		for(i=0;i<imagebytes;i++)
	{
		ch=getch();
			
		*p=ch;
		p+=1;
					
	}
	
	printf("Image is already received from uart0\r\n\n\n");
	printf("There will be some delay to running\r\n");	for(i=1;i<2000;i++)		for(j=1;j<2000;j++)			;
	
	
	run_ptr=(FP *)linkaddress;
	run_ptr();				
	return 0;		
}

⌨️ 快捷键说明

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