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

📄 task2_getnetdata.c.svn-base

📁 lwip协议在arm7+uCos系统上的移植
💻 SVN-BASE
字号:
/****************************************************************************
  函数名称:Task2()
  说明:	任务1,初始化网络,当rtl8019产生中断后,读取IP包
  调用函数:
  			OSTimeDlyHMSM()
  输入参数:*Id 任务ID
  输出参数:无
****************************************************************************/

#include "includes.h"
#include "os_tasks.h"
#include "globe.h"

#include "netif.h"
#include "ne2kif.h"
#include "tcpip.h"
#include "memp.h"
#include "watchdog.h"

OS_STK Task2Stack[TASK2_STACKSIZE];

OS_EVENT *g_sem_NetIRQ;		//this semaphore is uesd to make the task2 and the ne2k_isr synchro.
//OS_EVENT *g_sem_ZDMA0IRQ;	//this semaphore is uesd to make the task2 and the ZDMA0_isr synchro.

//unsigned int tem_DMA;
/*
*********************************************************************************************************
*                                       FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void LwipInit(void);
/*************task2:net initialization and get data*************/
void Task2(void *pdata)
{
	#if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
    	OS_CPU_SR  cpu_sr;
	#endif
	INT8U err;
	u8_t  curr,bnry;
	
	pdata = pdata;	//just aviod warning
	
	g_sem_NetIRQ = OSSemCreate(0);
	
	LwipInit();	//initializ lwip

	Wat_Enable(WAT_BIT_NET);	//sdy060630
	//receive rtl8019 data and process
	while(1)
	{
		OSSemPend(g_sem_NetIRQ, (INT16U)0, &err);
		
		Wat_Feed(WAT_BIT_NET);//sdy060621
		//OS_ENTER_CRITICAL();	//sdy060614
		rINTMSK |= BIT_EINT1;
		outb(CMD_PAGE1 | CMD_NODMA | CMD_RUN, NE_CR);
		curr  =  inb(NE_CURR);
		outb(CMD_PAGE0 | CMD_NODMA | CMD_RUN, NE_CR);
		bnry = inb(NE_BNRY);
		//OS_EXIT_CRITICAL();		//sdy060614
		//get more than one packet until receive buffer is empty
		while(curr != bnry)
		{
			ne2k_recv_packet(rtl8019if_netif);
			
			//OS_ENTER_CRITICAL();	//sdy060614
			outb(CMD_PAGE1 | CMD_NODMA | CMD_RUN, NE_CR);
			curr =  inb(NE_CURR);
			outb(CMD_PAGE0 | CMD_NODMA | CMD_RUN, NE_CR);
			bnry = 	inb(NE_BNRY);
			//OS_EXIT_CRITICAL();		//sdy060614
		}
		rINTMSK &= ~BIT_EINT1;				
	} 

	//OSTaskSuspend(OS_PRIO_SELF);	  
}
/*************end task2:net initialization and get data*************/


//show TCP initialize has done, used in LwipInit().
void tcpip_init_done(void *arg)
{
  sys_sem_t *sem;
  sem = arg;
  sys_sem_signal(*sem);
}
/*
//DMA ISR
void ZDMA0_isr(void)
{
	unsigned int temp;
	
	temp = rZDCON0 | (0x3<<4);	//get the STE
	
	switch(temp)
	{
		case (0x0<<4):	//Ready
			tem_DMA++;
			break;
		case (0x1<<4): 	//Not TC yet
			tem_DMA++;
			break;
		case (0x2<<4):	//Terminal Count
			OSSemPost(g_sem_ZDMA0IRQ);
			break;
		default:
			tem_DMA++;
	}
	//OSSemPost(g_sem_ZDMA0IRQ);
	rI_ISPC = BIT_ZDMA0;
}

//initialize the ZDMA0
void ZDMA0_init(void)
{
	rINTMSK |= BIT_ZDMA0;	//close the ZDMA0 interrupt
	//rI_ISPC = BIT_ZDMA0;	//changeif
	
	//CMD = 00(no commend) //QDS = 11(disable)
	rZDCON0 = (unsigned int)(0x0) | (0x3<<2);
	// ISADDR = NE_DMA//DAL = 11(fixed)//DST = 00(byte)
	rZDISRC0 = (unsigned int)NE_DMA | (0x3<<28) | (0x0<<30);
	//IDADDR = buf//DAS = 01(increment)//OPT = 10(normal)
	rZDIDES0 = ((unsigned int)0x0) | (0x1<<28) | (0x2<<30);
	//ICNT = count//EN = 0(disable)//AR = 0(disable)//INTS = 11(whenever terminal count)
	//OTF = 00(N/A)//TMD = 00(not used)//QTY = 10(Whole Service)//QSC = 10(N/A)
	rZDICNT0 = ((unsigned int)0x0) | (0x0<<20) | (0x0<<21) | (0x3<<22) | (0x0<<24) | (0x0<<26) | (0x2<<28) | (0x2<<30);
	//

	pISR_ZDMA0 = (U32)ZDMA0_isr;
	g_sem_ZDMA0IRQ = OSSemCreate(0);
	
	rINTMSK &= ~BIT_ZDMA0;	//open the ZDMA0 interrupt
	
	tem_DMA = 0;	//changeif
}*/
//initialization before use Lwip.
void LwipInit(void)
{
	struct ip_addr ipaddr, netmask, gw;
  	struct netif *netif;
  	sys_sem_t sem;
  	void *state;
  	
 	//lwip initialization
	#ifdef STATS
  	stats_init();
	#endif /* STATS */
  	sys_init();
  	mem_init();
  	memp_init();
  	pbuf_init();
  	netif_init();
  	//ZDMA0_init();
  	PRINT("System initialized.\n");
  	
  	//creat a tcp server task	
   	sem = sys_sem_new(0);
  	tcpip_init(tcpip_init_done, &sem);
  	sys_sem_wait(sem);
  	sys_sem_free(sem);
  	PRINT("TCP/IP initialized.\n");
  	
  	//add ne2k interface
  	netif = mem_malloc(sizeof(struct netif));	
    	IP4_ADDR(&ipaddr, 	192,168,14,138);	/*set the local IP address*/
  	IP4_ADDR(&netmask, 	255,255,255,0);		/*set the local subnet mask*/
  	IP4_ADDR(&gw, 		192,168,14,33);  	/*set the local gateway address*/
  	netif_set_default(netif_add(netif,
  								&ipaddr, &netmask, &gw,
  								state, 
                    			ne2k_init,
                    			tcpip_input));
                    
  	netif_set_up(netif);
}


⌨️ 快捷键说明

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