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

📄 main.c

📁 52arm_ucos_ii_new.最新版本UCOSII程序
💻 C
字号:
/****************************************************************************
 * file name	: main.c
 * By 			: 52arm
 * Update       : 52arm
****************************************************************************/

#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"
#include "../ucos_ii/ucos_ii.h"
#include "../inc/target.h"

/* allocate memory for tasks' stacks */
#ifdef SEMIHOSTED
#define STACKSIZE       (SEMIHOSTED_STACK_NEEDS+64)
#else
#define	STACKSIZE_H  8192
#define STACKSIZE_L  512
#endif

OS_STK Stack0[STACKSIZE_L];
OS_STK Stack1[STACKSIZE_L];
OS_STK Stack2[STACKSIZE_L];


OS_EVENT *UartSem;
OS_EVENT *KeySem;
/*-----------------------------------------------------------------------------------*/

void TaskLED(void *i)
{
    for (;;)
    {
		rPDATE=rPDATE&0x17f;
		OSTimeDly(500);
		rPDATE=rPDATE|0x80;
		OSTimeDly(500);
    }
}


void TaskKey(void *i)
{
	INT8U err;
	void *msg;
	
	for (;;)
	{
		msg = OSMboxPend(KeySem, 0, &err);
		OSSemPend(UartSem, 0, &err);
		Uart_Printf("msg = %d\n", msg);
		OSSemPost(UartSem);
	}
}

void TaskStart(void *i)
{
	INT8U err;
	
	ARMStartTimer();
	OSStatInit();
	
	for(;;)
	{
		OSTimeDly(2000);
		OSSemPend(UartSem, 0, &err);
		Uart_Printf("++++++++++++++++++++++++++++++++++++++ ");
		Uart_Printf("OSCPUUsage = %d%% \n",OSCPUUsage);
		OSSemPost(UartSem);
	}
}

//volatile char which_int=0;
unsigned char default_mac[MACLEN] = {0x12,0x34,0x56,0x78,0x90,0xab};
NODE locnode;

unsigned int SERIAL_BAUD = 57600;		//串口波特率设定
//unsigned int SERIAL_BAUD = 115200;		//串口波特率设定

#ifdef SDT251
	ETHERFRAME etherframe;
#endif

#ifdef ADS120
	ETHERFRAME __align(4) etherframe;
#endif

TIME_STRUC SysTime;

unsigned int IP_ADDRESS;
unsigned int GATE_ADDRESS;
unsigned int MASK_ADDRESS;

unsigned char MCLK_M;
unsigned char MCLK_P;
unsigned char MCLK_S;

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)
{
	IP_ADDRESS = IP4_ADDR(192,168,1,8);
	locnode.ip = IP_ADDRESS;
	MASK_ADDRESS = IP4_ADDR(255,255,255,0);
	locnode.mask = MASK_ADDRESS;
	GATE_ADDRESS = IP4_ADDR(192,168,1,1);
	locnode.gate = GATE_ADDRESS;
	memcpy(locnode.mac,default_mac,6);
	locnode.port = 9000;
}

void NetIntPreInit(void)
{
	rPCONG = rPCONG | 0x00c0;
	rPUPG = rPUPG & 0xf7;
	rEXTINT |= 0x4000;
}
/****************************************************************************
【功能说明】系统主函数
****************************************************************************/
void Main(void)
{	

	char Id0 = '1';
	char Id1 = '2';
	char Id2 = '3';

	
	int seconds, i;
	void (*fp)(void) = (void (*)(void))(0x10000);

    rSYSCFG=SYSCFG_8KB;		//使用8K字节的指令缓存
	rNCACHBE0=((unsigned int)(Non_Cache_End>>12)<<16)|(Non_Cache_Start>>12); 
    //在上面的数据区域不使用高速缓存

	MCLK_M = 40; MCLK_P = 2; MCLK_S = 1;
	
	Port_Init();		//IO端口功能、方向设定
	Led_Disp();		//LED来回闪烁显示 
	
	rPCONG &= 0x00ff;

	ChangePllValue(MCLK_M,MCLK_P,MCLK_S);		//修改系统主频为8倍频
	Uart_Init(0,SERIAL_BAUD);		//异步串行口初始化,设置波特率为115200
	Delay(0);		//利用系统时钟校准延时函数

	NodeInit();
	NetIntPreInit();
	ArpInit();	

	Uart_Select(0);
	Uart_Printf("\n\n*******************************\n"
	                " Welcome to 52arm BIOS Ver 6.0\n"
	                "  For 44B0X ARM Develop Board\n"
	                "     http://www.52arm.net\n"
	                "*******************************\n\n"
	                "SDRAM Size: %d MB\n",  ((rBANKCON6&3)==1)?16:8);
	GetFlashID();
	Uart_Printf("IP Address: %u.%u.%u.%u\n\n", (IP_ADDRESS>>24)&0xff, (IP_ADDRESS>>16)&0xff, (IP_ADDRESS>>8)&0xff, IP_ADDRESS&0xff);
	// Uart_Printf("Build  date : " __DATE__ "-" __TIME__ "\n\n");





	/*********************************/	
	/******* start ucos/ii os ********/
	/*********************************/	
	Uart_Printf("OSrunning\n");
	OSInit();
	OSTimeSet(0);    
	UartSem = OSSemCreate(1);
	KeySem = OSMboxCreate((void *)0);
    /* 
     * create the tasks in uC/OS and assign decreasing
     * priority to them 
     */
	OSTaskCreate(TaskStart, (void *)&Id0, (void *)&Stack0[STACKSIZE_L - 1], 1);
	OSTaskCreate(TaskLED, (void *)&Id1, (void *)&Stack1[STACKSIZE_L - 1], 51);
	OSTaskCreate(TaskKey, (void *)&Id2, (void *)&Stack2[STACKSIZE_L - 1], 50);        
    /* Start the  system running */
	ARMTargetStart();
    /* start the system */
	OSStart();
    /* never reached */


	


	
	
	// Auto boot
	if ( *((unsigned *)0x10000) == 0xffffffff ) {
		Uart_Printf("It seems no image at 0x10000, auto boot disabled.\n\n");
		ShellIn();
	}
	
	for (seconds = 3; seconds>=0; seconds--) {
		Uart_Printf("\rAuto boot in progress, press any key in %d seconds to run BIOS...  ", seconds);
		for (i=0; i<10; i++) {
			if (Uart_GetKey()) {
				Uart_Printf("\n\n");
				ShellIn();
			}
			Delay(1000);
		}
	}
	
	Uart_Printf("\n\n");
	(*fp)();
}
//***************************************************************************

⌨️ 快捷键说明

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