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

📄 main.c

📁 S3C44BOX的BIOS。可使用的命令:help --- show help ? --- = help date --- show or set current date time --
💻 C
字号:
/****************************************************************************
 * file name	: main.c
 * By 			: hugang, hgx2000@mail.china.com
****************************************************************************/

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "../inc/option.h"
#include "../inc/44b.h"
#include "../inc/44blib.h"
#include "../inc/def.h"
#include "../inc/rtc.h"
#include "../net/armnet.h"
#include "../inc/shell.h"
#include "../inc/flash.h"


volatile char which_int=0;
unsigned char default_mac[MACLEN] = {0xea,0xff,0x56,0x00,0x90,0xab};
NODE locnode;
unsigned int SERIAL_BAUD = 57600;
ETHERFRAME etherframe;
TIME_STRUC SysTime;
unsigned int IP_ADDRESS;
unsigned int download_addr;
unsigned int download_begin;
unsigned int download_end;
unsigned int download_len;

void NetSever(void)
{	
	unsigned short rxlen,ip_len;
	unsigned char net_isr;
	ARPKT *arp;
	ETHERFRAME *efp;
	IPKT *ip;
	efp = &etherframe;

	net_isr = EN_ISR;
	
	if(net_isr & ENISR_RX)
	{
		DEBUGF(DEMO_DEBUG,("Rtl8019 Interrupted RX\n"));
		EN_ISR |= ENISR_RX;

		memset((unsigned char *)efp, 0, sizeof(ETHERFRAME));
		rxlen = GetEthernet(efp);
		SwapEther(efp);
		
		if(IsArp(efp, rxlen))
		{
			arp = (ARPKT *)(efp->edata);
			if(READ_PACKED(arp->dip)==locnode.ip &&(arp->op==ARPREQ || arp->op==ARPRESP))
			{
				DEBUGF(ARP_DEBUG,("Get ARP\n"));
				ArpRcvPacket(efp);
			}
		}
		else
		{
			ip_len = IsIp(efp, rxlen);
			if(ip_len)
			{
				ip = (IPKT *)(efp->edata);
				DEBUGF(DEMO_DEBUG,("Get IP\n"));
				if(IsIcmp(ip, ip_len))
				{
					DEBUGF(ICMP_DEBUG,("Get ICMP\n"));
					IcmpRcvPacket(efp);
				}
				else if(IsUdp(ip, ip_len))
				{
					DEBUGF(DEMO_DEBUG,("Get UDP\n"));
					UdpRcvPacket(efp);
				}
			}
		}
	}
	
	if(net_isr & ENISR_RX_ERR)
	{
		DEBUGF(DEMO_DEBUG,("Rtl8019 Interrupted RX_ERR\n"));
		EN_ISR |= ENISR_RX_ERR;
	}
	
	if(net_isr & ENISR_TX)
	{
		DEBUGF(DEMO_DEBUG,("Rtl8019 Interrupted TX\n"));
		EN_ISR |= ENISR_TX;
	}
	
	if(net_isr & ENISR_TX_ERR)
	{
		DEBUGF(DEMO_DEBUG,("Rtl8019 Interrupted TX_ERR\n"));
		EN_ISR |= ENISR_TX_ERR;
	}		
}
//***************************************************************************

void NodeInit(void)
{
	unsigned short temp,i;
	U8		data[8];

	Init_Iic();
	//24c02    0x10 -0x15 MAC address
	//			0x16-0x19	IP address
	//			0x1a- 01d	Mask
	//			0x1e-0x21	Gaste way			
	for(i=0;i<6;i++)
		Rd24LCxx(0xa0,(U8)(0x10+i),&(default_mac[i])); 
	for(i=0;i<4;i++)
		Rd24LCxx(0xa0,(U8)(0x16+i),&(data[i])); 
	IP_ADDRESS = IP4_ADDR(data[0],data[1],data[2],data[3]);
	locnode.ip = IP_ADDRESS;
	locnode.gate = IP4_ADDR(data[0],data[1],data[2],1);
	for(i=0;i<4;i++)
		Rd24LCxx(0xa0,(U8)(0x1a+i),&(data[i])); 
	locnode.mask = IP4_ADDR(data[0],data[1],data[2],data[3]);

	locnode.mask = IP4_ADDR(255,255,255,0);
//	locnode.gate = IP4_ADDR(219,133,81,1);
	memcpy(locnode.mac,default_mac,6);
	locnode.port = 9000;
}

void NetIntPreInit(void)
{
	rPCONG = rPCONG | 0x00c0;
	rPUPG = rPUPG & 0xf7;
	rEXTINT |= 0x4000;
}
/****************************************************************************
【功能说明】系统主函数
****************************************************************************/
void Main(void)
{	
	unsigned short ID8019,temp,i;	
	
    	rSYSCFG=SYSCFG_8KB;		//使用8K字节的指令缓存
	rNCACHBE0=((unsigned int)(Non_Cache_End>>12)<<16)|(Non_Cache_Start>>12); 
    //在上面的数据区域不使用高速缓存

	Port_Init();		//IO端口功能、方向设定
//	Led_Disp();		//LED来回闪烁显示 

	rPDATE=rPDATE|0x10;
	
	
	
	EN_CR = ENCR_PAGE0 + ENCR_NODMA + ENCR_STOP;
	ID8019 = EN_8019ID0 ;
	ID8019 = ID8019 *256 + EN_8019ID1;


	ChangePllValue(52,2,1);		//修改系统主频为8倍频
	Uart_Init(0,SERIAL_BAUD);		//异步串行口初始化,设置波特率为115200
	Delay(0);
	
	NodeInit();
	NetIntPreInit();
	ArpInit();
	ResetNic();

	Beep(1000);	

	
	Uart_Printf("\n\n");
	Uart_Printf("Bios for S3C44B0x - %dMHz\n",(52+8));
//	Uart_Printf("Flash ID is : %x\n", GetFlashID());
	
	Uart_Printf("Net Controler ID: %x\n",ID8019);
	Uart_Printf("IP address : %u.%u.%u.%u\n", (IP_ADDRESS>>24)&0xff, (IP_ADDRESS>>16)&0xff, (IP_ADDRESS>>8)&0xff, IP_ADDRESS&0xff);
	Uart_Printf("Build date:");
	Uart_Printf(__DATE__);
	Uart_SendByte('-');
	Uart_Printf(__TIME__);
	Uart_Printf("\n");
	
	ShellIn();
}
//***************************************************************************

⌨️ 快捷键说明

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