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

📄 lap_s.c

📁 MTK平台绝密核心代码之 外设管理(红外线)
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------    
 *    LAP.c
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *   This file contains the Secondary part of LAP
 *
 * Author:
 * -------
 * -------
 *
 *****************************************************************************/
#include "kal_release.h"      /* Basic data type */
#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h"       /* Task message communiction */
#include "stack_timer.h"      /* Stack timer */
#include "irda_enums.h"       /* irda enum */  
#include "gprs_flc_kal.h"  
#include "gprs_flc_common_data_types.h"
#include "flc_tunable_para.h"
#include "irconfig.h"	/* IrPro system configuration */
#include "lap.h"	      /* LAP source header file */
#include "lmp.h"	      /* LMP source header file */
#include "support.h"	   /* system support functions */
#include "externs.h"	   /* system external definitions */
#include "irda.h"
#include "irframer_sw.h"
#include "gprs_flc_kal.h"  
#include "flc_tunable_para.h"
#include "stack_config.h"
#include "kal_trace.h"                     
#include "irda_trace.h"

/* data declarations */
kal_uint16  wd_time;	/* watch dog timeout var */
kal_uint8   slot;		/* current slot var */
kal_uint8   old_slot;	/* discovery slot variable */
kal_uint8   frame_sent;	/* sync flag */
kal_uint8   ua_response_sent; /* sync flag */
extern kal_uint16 dbg_ctrl_buff_count;
#ifdef STORE_DEVICE_INFO
kal_uint8   rx_device_info[23]; /* device info received during discovery */
#endif

FBUF  * Format_XID_RES_packet ( FBUF  * tmpptr );

/*************************************************************************
* FUNCTION
*	Do_s_frame_s
*
* DESCRIPTION
*	Decode the S frame for secondary
*
* PARAMETERS
*  kal_uint8 * frame
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void  Do_s_frame_s ( kal_uint8  * frame )
{  
#ifdef IRDA_KAL_TRACE
     kal_trace(TRACE_FUNC, IRDA_MSG41);      	  
#endif
   if(irlap_state!=IRLAP_SCLOSE)
   STOP_WD_TIMER();
        Nr=(frame[1]&0xe0)>>5;

	if ( INVALID_NR()&&(irlap_state==IRLAP_NRMS)&&(frame[1]&0x10) )
	{		
		Com_write(Format_packet (0,RD_RESPONSE));
		START_WD_TIMER();
	   irlap_state=IRLAP_SCLOSE;
		return;
	}
		
    switch(irlap_state)
    {
       case IRLAP_NRMS:
	       switch (frame[1]&0x1f)
	       {
		       case REJ_COMMAND:
		          goto  here;
		       case SREJ_COMMAND:

here:
			       Send_NRM_Response();
			       START_WD_TIMER();
			       break;

		       case RNR_COMMAND:
			       remote_busy = TRUE;
			       Send_NRM_Response();
			       START_WD_TIMER();
			       break;

		       case RR_COMMAND:
			       remote_busy = FALSE;
			       Send_NRM_Response();
			       START_WD_TIMER();
			       break;
		       default:
	  		       if (frame[1]&0x10)
			       	 SEND_S_RESPONSE();
			       break;
				
	       }
	    break;
	 default:/*We process S frame only in NRMS state*/
	  	 break;
    }
}


/*************************************************************************
* FUNCTION
*	Do_i_frame_s
*
* DESCRIPTION
*	Decode the information frame for secondary
*
* PARAMETERS
*  FBUF * dframe
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void  Do_i_frame_s ( FBUF  * dframe )
{
kal_uint8  *  frame;
kal_uint8 tmp_free=0;
   if(irlap_state!=IRLAP_SCLOSE)
   STOP_WD_TIMER();
	frame=(kal_uint8  *)dframe+FBUF_HEAD;
   
   //IrLAP_I_frame_timer_enable(KAL_FALSE);
   Nr=(frame[1]&0xe0)>>5;
   Ns=(frame[1]&0x0e)>>1;

	if ( INVALID_NR()&&(irlap_state==IRLAP_NRMS)&&(frame[1]&0x10) )
	{
	
		Com_write( Format_packet ( 0,RD_RESPONSE));
		START_WD_TIMER();
	   irlap_state=IRLAP_SCLOSE;
		goto exit;
	}

	switch(irlap_state)
	{
	   case IRLAP_NRMS:	     		     		     
		         if ( local_busy==FALSE )
		         {
			         if (Ns==Vr)
			         {
			            Vr=(Vr+1)%8;
				         Send_NRM_Response();
				         /*@@@@ MSG_ID_LAP_DATA_INDICATION*/
				         irda_lmp_flag=MSG_ID_LAP_DATA_INDICATION;
				         irda_data_buffer=dframe;
                     tmp_free++;		
			         }
			         else 
			         {
				         SEND_S_RESPONSE();
			         }
			      }
			      else 
			      {
  			         Send_NRM_Response();
			      }
			      START_WD_TIMER(); 			     	     	      
	      break;
	   default:
	      break;
	}
exit:
/* free the buffer if we did not q it */
	if (tmp_free==0)  
	{
    		Freebuf((FBUF*)dframe);
	}
	IrLAP_I_frame_timer_enable(KAL_TRUE);
}


/*************************************************************************
* FUNCTION
*	Do_u_frame_s
*
* DESCRIPTION
*	Decode the U frame for secondary
*
* PARAMETERS
*  kal_uint8 * frame
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void  Do_u_frame_s ( kal_uint8  * frame )
{
  
#ifdef IRDA_KAL_TRACE
    kal_trace(TRACE_FUNC, IRDA_MSG42);  	  
#endif
   if(irlap_state!=IRLAP_SCLOSE)
   STOP_WD_TIMER();
	switch(irlap_state)
	{
	   case IRLAP_SCLOSE:
	      switch (frame[1])
	      {
		      case DISC_COMMAND:		         
		         /*set baudrate reset flag, the divisor will be reset
		           after tx done */
		         Com_ioctl( IOCTL_BAUD, CONTENTION_BAUD );         
               Com_write(Format_packet (0,UA_RESPONSE));
               LAP_disconnect_reset(USER_REQUESTED);
               irda_lmp_flag=MSG_ID_LAP_DISCONNECT_INDICATION;			      
			      break;
		   default:
	  	   	if (frame[1]&0x10)/* send secondary response */
	  	   	{			
				   Com_write(Format_packet (0,RD_RESPONSE));
				   START_WD_TIMER();
			   }
			   break;
	      }
	    break;
	   case IRLAP_NRMS:
	      switch (frame[1])
	      {
		      case DISC_COMMAND:	
		         /*set baudrate reset flag, the divisor will be reset
		           after tx done */
		         Com_ioctl( IOCTL_BAUD, CONTENTION_BAUD );  
		         Com_write(Format_packet (0,UA_RESPONSE));
		         LAP_disconnect_reset(USER_REQUESTED);				      
               irda_lmp_flag=MSG_ID_LAP_DISCONNECT_INDICATION;
			      
			      break;
		      case SNRM_COMMAND:		
			      Com_write( Format_packet ( 0,RD_RESPONSE));
			      START_WD_TIMER();
	            irlap_state=IRLAP_SCLOSE;
			      break;
		      default: 
	  		      if (frame[1]&0x10)/*send Secondary response*/
			      	SEND_S_RESPONSE();
			      break;
	      }
	      break;
	   case IRLAP_SETUP:	  	       
	      goto process_snrm;
	      break;
	   case IRLAP_QUERY:
	      goto process_snrm;
	      break;   		 
	   case IRLAP_NDM:
	      switch (frame[1])
	      {
#ifdef ULTRA_FLAG
		      case UI_COMMAND:
			      Ultra_SAR_RX ( frame );  
			      break;
#endif
		      case SNRM_COMMAND:
process_snrm:
		         irlap_state=IRLAP_CONN;
		         connection_address = frame[CONN_ADDRESS_OFFSET];/* dest 32bit address */		
			      xmemcpy ((kal_uint8 *)&destination_address, (kal_uint8  *)&frame[DEST_ADDRESS_OFFSET],4); 
			      irp_connect = CONNECTION_INDICATION;
			      IrLAP_CONNECT_response (frame);
               /*@@@@MSG_ID_LAP_CONNECT_INDICATION*/
               irda_lmp_flag=MSG_ID_LAP_CONNECT_INDICATION;
               gprs_flc_activate_context(IRDA_DATA, 0, GPRS_FLC_DL, 0);
			      break;
		      default:/* received an unknown u command  */		
			      break;
	      }
	      break;	   
	default:/* unknown u state  */		
		break;
	}
}

/*************************************************************************
* FUNCTION
*	IrLAP_DISCONNECT_request_s
*
* DESCRIPTION
*	Perform a LAP disconnect request for a secondary
*
* PARAMETERS
*  
* RETURNS
* None
*
* GLOBALS AFFECTED
* Disconnects the LAP link and update the link states
*************************************************************************/
void IrLAP_DISCONNECT_request_s ( void  )
{

#ifdef IRDA_KAL_TRACE
     kal_trace(TRACE_FUNC, IRDA_MSG43);  	  
#endif     
	      Com_write(Format_packet (0,RD_RESPONSE));
	      START_WD_TIMER();
	      irlap_state=IRLAP_SCLOSE;
       
}


/*************************************************************************
* FUNCTION
*	IrLAP_CONNECT_response
*
* DESCRIPTION
*	Perform a LAP connect response
*
* PARAMETERS
*  kal_uint8 * frame 
* RETURNS
* None
*
* GLOBALS AFFECTED
* Determines final negotiation field params based on the recieved primary
  parameters and the defined secondary parameters
*************************************************************************/
kal_uint8 result_params[CONNECT_PARAMS_SIZE];
void IrLAP_CONNECT_response ( kal_uint8  * frame  )
{
kal_int16   i1;
kal_uint8   *tmpptr;
kal_uint8   i2,offset=0;
kal_uint8   bit_mask=0;
  
#ifdef IRDA_KAL_TRACE
     kal_trace(TRACE_FUNC, IRDA_MSG44);  	  
#endif
	new_ttt   =0;
	new_baud  =0;
	new_size  =0;
	new_xbofs =0;
	new_minttt=0;
	new_ld    =0;


/* point to received connection params:21*/
	tmpptr=(kal_uint8  *)frame+11;  

	if (( tmpptr[0]==1 )&& /* add one if additional baud byte */
	    ( tmpptr[1]==2 )) 
		offset=1;	
	else
	   offset=0;	

	/* copy the old params */

	for (i2=0;i2<CONNECT_PARAMS_SIZE;i2++)
	{
		result_params[i2] = connect_params[i2];
	}

/* if offset=1 additional baud byte is included in response */
/* if offset=0 additional baud byte is not included in response */
	if (offset==0)
	{  
		for (i2=3;i2<CONNECT_PARAMS_SIZE;i2++)
		{
			result_params[i2] = connect_params[i2+1];
		}
		result_params[1]=1; /* set baud parameter size to 1 */
	}


/* determine least common denominator for params */
/* process baud */
	if ( (tmpptr[0]==0x01)&&
	     ((tmpptr[1]==1)||(tmpptr[1]==2)) )
	{
		bit_mask = connect_params[2]&tmpptr[2];
		for (i1=7;i1>-1&&(!new_baud); )
		{
			switch(bit_mask&(1<<i1--))
			{
/*bit0*/	   case 1    : new_baud=0;		
/*bit1*/	   case 2    : new_baud=9600l;	break;
/*bit2*/	   case 4    : new_baud=19200l;	break;
/*bit3*/		case 8    : new_baud=38400l;	break;
/*bit4*/		case 0x10 : new_baud=57600l;	break;
/*bit5*/		case 0x20 : new_baud=115200l;	break;
/*bit6*/		case 0x40 : new_baud=576000l;	break;
/*bit7*/		case 0x80 : new_baud=1152000l;	break;
			}
		}
		if ( bit_mask )
		{
			bit_mask=1<<(i1+1);
			result_params[2]=bit_mask;			
		}

		if (new_baud==0)/* set mask and BAUD to defaults */
		{  
			new_baud=9600;
			bit_mask=2;
			result_params[2]=bit_mask;			
		}
		#ifdef __IRDA_FIR_SUPPORT__
		if ((tmpptr[0]==0x01)&&
		 (tmpptr[1]==2)&& /* remote 4Mbps field included */
		 (connect_params[1]==2)&& /* our 4Mbps field is included */
		 (connect_params[3]&tmpptr[3]==1))/* 4Mbps is set */
  { 
		new_baud=4000000l;
		bit_mask=1;
		result_params[2]=0;
		result_params[3]=1;
	}
#endif
	}
	else
   {
      new_baud=9600;
	   bit_mask=2;
	   result_params[2]=bit_mask;
   }  

/* process ttt */
   if (new_baud >= 115200 )
   {  
	    if ( (tmpptr[3+offset]==0x82)&&
	    (tmpptr[4+offset]==1) )
	    {
	            bit_mask=connect_params[6]&tmpptr[5+offset];
	          for (i1=3;i1>-1&&!new_ttt; )
	          {
	          	switch(bit_mask&(1<<i1--))
	          	{
	          		case 1    : new_ttt=500;break;		
	          		case 2    : new_ttt=250;break;
	          		case 4    : new_ttt=100;break;
	          		case 8    : new_ttt=50;break;
	          	}
	          }
	      if (bit_mask)
			   bit_mask=1<<(i1+1);
		   else /* set defaults */
		   {  
		      bit_mask=1;
		      new_ttt=500;
		   }
		   result_params[5+offset]=bit_mask;
	   }
	   else /*set default*/
	   {
	      bit_mask=1;
		   new_ttt=500;		   
		   result_params[5+offset]=bit_mask;
	   }   
	}
	else 
	{
		bit_mask=1;  /* 500ms */
		result_params[5+offset]=bit_mask;
		new_ttt=500;
	}
/* process data size */
	if ( (tmpptr[6+offset]==0x83)&&
	     (tmpptr[7+offset]==1) )
   {
		bit_mask=connect_params[9]&tmpptr[8+offset];
		for (i1=5;i1>-1&&!new_size;)
		{
			switch(bit_mask&(1<<i1--))
			{
				case 1    : new_size=64;break;
				case 2    : new_size=128;break;
				case 4    : new_size=256;break;
				case 8    : new_size=512;break;

⌨️ 快捷键说明

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