www.pudn.com > TCPmodbushy.rar > memory.c


/****************************************************************************** 
 * Project     : t_box 
 * Module Name : memory.C 
 * CPU Type    : C8051F340 
 * 
 * Description : 
 * 
 * History        Author     Version       Comment 
 * 2006.10.22       HY       V0.0         Original version 
 * 
 * Copyright (C) 2006 HY. All rights reserved. 
 ******************************************************************************/ 
#include "o:\sysdef.h" 
#include "o:\memory.h" 
#include  
 
struct MEMB  xdata  memory[MEMEORY_SIZE]; 
uchar	data	affair_head; 
uchar	data	affair_tail; 
 
/********************************************************************* 
initialize memory block 
**********************************************************************/ 
void init_memb( void ) 
{ 
	uchar i=0; 
 
	for(i = 0;i m ) 
	{ 
#ifdef   TESTDEBUG	 
		test[1]++; 
#endif 
		return( MEMORY_EER ); 
	} 
	/* GetSpaceHead and assign the head, used 'm' record */ 
	for( i=0; ilink; 
		memb_point->link = NULL; 
		memb_point->tag = 0; 
		memb_point->size = 0; 
		memb_point->TCP_connect_num = 0; 
	} 
} 
 
/************************************************************************ 
* Free queue data be Used a TCP LINK 
************************************************************************/ 
void FreeTcpQueue( uchar iIndex ) 
{ 
	uchar	i;  
	for( i=0; ispace[*offset] ) ); 
		/* change FlashAddress and len */ 
		FlashDataAdd += TmpLen; 
		Len -= TmpLen; 
		if( ( *offset + TmpLen ) == SPACE_SIZE ) 
		{ 
			*offset = 0; 
			pd = pd->link; 
		} 
		else 
		{ 
			*offset = (*offset) + TmpLen; 
		} 
	} 
	return( pd ); 
} 
 
/* apply_process()-->TCP_MODBUS_analyse() as slave mode enter slave mode,faild? */	 
/****************************************************************************** 
* memory enter affair queue 
* input: the number of the first memory block 
* Note:	 tail is empty 
******************************************************************************/ 
uchar enter_affair_queue( uchar head_num ) 
{ 
	if( affair_tail < MAX_AFFAIR ) 
	{ 
		if( affair_head == (affair_tail+1) ) 
		{ 
			return(ERR);			/*affair queue is full*/ 
		} 
		else 
		{ 
			memory[head_num].tag |= affair_tail;	 /*set the number of the send queue*/ 
			affair_tail++; 
			return(OK); 
		} 
	} 
 
	if( affair_tail == MAX_AFFAIR ) 
	{ 
		if(affair_head == MIN_AFFAIR) 
		{ 
			return(ERR); 
		} 
		else 
		{ 
			affair_tail = MIN_AFFAIR; 
			memory[head_num].tag |= MAX_AFFAIR; 
			return(OK);	 
		} 
	} 
} 
 
/********************************************************************************* 
* memory go out from affair queue 
* input: the number of the first memory block 
**********************************************************************************/ 
void out_affair_queue() 
{ 
	if(affair_head < MAX_AFFAIR) 
	{ 
		affair_head++; 
	} 
	else 
	{ 
		affair_head = MIN_AFFAIR; 
	} 
} 
 
/*********************************************************************************** 
* find the first memory block of affair queue's head 
* input:affair_head 
* output:a point that point to  the first memory block of affair queue's head 
***********************************************************************************/ 
MEMB xdata *find_head( void ) 
{ 
	uchar i; 
 
	while(1) 
	{ 
		for( i=0; i