www.pudn.com > ARM_Ethernet.rar > main.c, change:2006-01-18,size:5798b


/****************************************Copyright (c)************************************************** 
**                               Guangzou ZLG-MCU Development Co.,LTD. 
**                                      graduate school 
**                                 http://www.zlgmcu.com 
** 
**--------------File Info------------------------------------------------------------------------------- 
** File name:			main.c 
** Last modified Date:  2004-09-16 
** Last Version:		1.0 
** Descriptions:		The main() function example template 
** 
**------------------------------------------------------------------------------------------------------ 
** Created by:			Yehaoben 
** Created date:		2004-09-16 
** Version:				1.0 
** Descriptions:		The original version 
** 
**------------------------------------------------------------------------------------------------------ 
** Modified by: 
** Modified date: 
** Version: 
** Descriptions: 
** 
********************************************************************************************************/ 
 
#include "config.h" 
 
/* 
********************************************************************************************************* 
*                                              CONSTANTS 
********************************************************************************************************* 
*/ 
 
#define          TASK_START_ID       2                /* Application tasks                             */ 
#define          TASK_1_ID           3 
 
#define          TASK_START_PRIO    2                /* Application tasks priorities                  */ 
#define          TASK_1_PRIO        3 
 
#define          TASK_0_STACK_SIZE  1024 			  /* Size of task stack */ 
#define          TASK_1_STACK_SIZE  1024 
 
OS_STK task0_stack[TASK_0_STACK_SIZE]; 
OS_STK task1_stack[TASK_1_STACK_SIZE]; 
 
/* 
 
********************************************************************************************************* 
*                                             DATA TYPES 
********************************************************************************************************* 
*/ 
 
/* 
********************************************************************************************************* 
*                                              VARIABLES 
********************************************************************************************************* 
*/ 
uint16 	TempLength,i; 
uint32	sumlen,temp32; 
uint8 tempi; 
/* 
********************************************************************************************************* 
*                                         FUNCTION PROTOTYPES 
********************************************************************************************************* 
*/ 
 
void taskA(void *pdata)  
{ 
 
uint8 	Temp; 
int 	addrlen; 
int 	ei; 
uint8 	tempdata[400]; 
 
SOCKET	s;  
struct sockaddr 	servaddr,cliaddr; 
	 
	servaddr.sin_family=0; 
	getlocalip(servaddr.sin_addr,0); 
	servaddr.sin_port=8000; 
	s=socket( AF_INET, SOCK_STREAM, TCP_PROTOCOL); 
	if(s == SOCKET_ERROR) 
	{ 
		while(1); 
	} 
	ei=bind( s, (struct sockaddr*)&servaddr,sizeof(servaddr)); 
	if(ei == SOCKET_ERROR) 
	{ 
		while(1); 
	} 
	ei=listen( s, 2 ); 
	 
	while (1) 
    { 	 
		Temp=accept( s, (struct sockaddr*)&cliaddr,&addrlen ); 
	 
		if(Temp!=SOCKET_ERROR) 
		{ 
			while(1) 
			{ 
				TempLength=recv( Temp,tempdata ,400, 0 ); 
				if(TempLength == SOCKET_RCV_ERROR) 
				{ 
					close(Temp); 
					OSTimeDly(10); 
					listen( s, 1 ); 
					break; 
				} 
				else if(TempLength>0) 
				{ 
					temp32 = 0; 
					temp32=send( Temp,tempdata,TempLength, 0 );//array3579 
				} 
			} 
		} 
    }    
} 
 
/* 
********************************************************************************************************* 
*                                               STARTUP TASK 
********************************************************************************************************* 
*/ 
 
void task0(void *pdata)   
{ /*在第1个任务中设置定时器0及中断*/ 
                                  
    #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */ 
    OS_CPU_SR  cpu_sr; 
	#endif 
	 
	TargetInit();           //add by cmj 
  	 
    OSTaskCreateExt(taskA, 
                (void *)0, 
                &task1_stack[TASK_1_STACK_SIZE-1], 
                TASK_1_PRIO, 
                TASK_1_ID, 
                &task1_stack[0], 
                TASK_1_STACK_SIZE, 
                (void *)0, 
                OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);	 
	while(1) 
	{  
		OSTimeDly(40); 
    }//end for while(1) 
} 
 
/*$PAGE*/ 
/* 
********************************************************************************************************* 
*                                                  MAIN 
********************************************************************************************************* 
*/ 
int main (void) 
{ 
	OSInit();                                           /* Initialize uC/OS-II                      */ 
    OSTaskCreateExt(task0, 
                    (void *)0, 
                    &task0_stack[TASK_0_STACK_SIZE-1], 
                    TASK_START_PRIO, 
                    TASK_START_ID, 
                    &task0_stack[0], 
                    TASK_0_STACK_SIZE, 
                    (void *)0, 
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);	 
    OSStart();                                             /* Start multitasking                       */ 
} 
 
 
 
/********************************************************************************************************* 
**                            End Of File 
********************************************************************************************************/