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

📄 ztctestclientinterface.c

📁 freescale的基于802.15.4的无线通讯例程
💻 C
字号:
/******************************************************************************
* This file interfaces services with the UART module.It provides functionality
* to poll for available data from Test client, removes SYNC and FCS makes the frame
* suitable for ZTC. It also provides functionality to send the string to the
* test client by adding SYNC and FCS
*
*
* (c) Copyright 2006, Freescale, Inc. All rights reserved.
*
* Freescale Semiconductor Confidential Proprietary
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale Semiconductor Danmark A/S.
*
******************************************************************************/
#if ( gZtcIncluded_d == 1  ) 

#include "ZtcInterface.h"
#include "ZtcTestClientInterface.h"	 
#include "ZtcConfiguration.h"

/******************************************************************************
*******************************************************************************
* Private macros
*******************************************************************************
******************************************************************************/
#define mUART_STXWord_c     0x02
/******************************************************************************
*******************************************************************************
* Private prototypes
*******************************************************************************
******************************************************************************/
/* None */
/******************************************************************************
*******************************************************************************
* Private type definitions
*******************************************************************************
******************************************************************************/
/* None */
/******************************************************************************
*******************************************************************************
* Public memory declarations
*******************************************************************************
******************************************************************************/

/*This  table maps Opcode Grp from Test Client to SAPIds used by ZTC */

 const uint8_t gaOpcodeGrpToSAPId[] = {
  gMLMENwkSAPHandlerId_c,               /*  0x84  */
	gNwkMLME_SAPHandlerId_c,              /*  0x85  */
	gMCPSNwkSAPHandlerId_c,               /*  0x86  */
	gNwkMCPS_SAPHandlerId_c,              /*  0x87  */
	0,0,0,0,0,0,0,0,0,0,0,0,        
	gASPNwkSAPHandlerId_c,                /*  0x94  */
	gNwkASP_SAPHandlerId_c,               /*  0x95  */
  gZDO_NLME_SAPHandlerId_c,             /*  0x96  */
  gNLME_ZDO_SAPHandlerId_c,             /*  0x97  */
  gAPSME_ZDO_SAPHandlerId_c,            /*  0x98  */
  gZDO_APSME_SAPHandlerId_c,            /*  0x99  */
  gAPS_NLDE_SAPHandlerId_c,             /*  0x9A  */
  gNLDE_APS_SAPHandlerId_c,             /*  0x9B  */
  gAF_APSDE_SAPHandlerId_c,             /*  0x9C  */
  gAPSDE_AF_SAPHandlerId_c,             /*  0x9D  */
  gAFDEAppSAPHandlerId_c,               /*  0x9E  */
  gAppAFDE_SAPHandlerId_c,              /*  0x9F  */
  0, 0,						                
  gAppZDP_SAPHandlerId_c                /*  0xA2  */
};

/*This table maps SAPIds used by ZTC To Opcode Grp used by Test Client */
 const uint8_t gaSAPIdOpcodeGrp[] = {
  gOpCodeGrpForNwkToMCPS_SAP_c,		      /*  0x87  */
  gOpCodeGrpForMCPSToNwkSAP_c,		      /*  0x86  */
  gOpCodeGrpForNwkToMLME_SAP_c,		      /*  0x85  */
  gOpCodeGrpForMLMEToNwkSAP_c,		      /*  0x84  */
  gOpCodeGrpForNwkToASP_SAP_c,		      /*  0x95  */
  gOpCodeGrpForNwkToASP_SAP_c,		      /*  0x94  */
  gOpCodeGrpForAPSToNLDE_SAP_c,		      /*  0x9A  */
  gOpCodeGrpForNLDEToAPD_SAP_c,		      /*  0x9B  */
  gOpCodeGrpForZDOToNLME_SAP_c,		      /*  0x96  */
  gOpCodeGrpForNLMEToZDO_SAP_c,		      /*  0x97  */
  gOpCodeGrpForAFToAPSDE_SAP_c,		      /*  0x9C  */
  gOpCodeGrpForAPSDEToAF_SAP_c,		      /*  0x9D  */
  gOpCodeGrpForAppToAF_SAP_c,			      /*  0x9F  */
  gOpCodeGrpForAFDEToAppSAP_c,		      /*  0x9E  */
  gOpCodeGrpForZDOToAPSME_SAP_c,		    /*  0x99  */
  gOpCodeGrpForAPSMEToZDO_SAP_c ,		    /*  0x98  */
  gOpCodeGrpForAppToZDP_SAP_c,
  gOpCodeGrpForZDPToAppSAP_c
  
};

/******************************************************************************
*******************************************************************************
* Public functions
*******************************************************************************
******************************************************************************/

bool_t ZTCTestClientInterface_PollTestInterface
  (
  uint8_t * pRxBuffer,  /*  IN: Ztc Buffer in to which data from
                                Test cleint get filled */
  uint16_t maxLen       /*  IN: Maximum length of the ZTC buffer  */
  )
{
 
  #define sync_c                            0
  #define lengthOfDataFieldForSyncError     11
  #define lengthOfDataFieldForRxLengthError 13
  #define lengthOfDataFieldForRxFcsError    10
  #define minimumLengthOfPacket             4
  #define LenFcsIndex_c                     2
  
  bool_t syncErrorDetected_c = FALSE;
  bool_t syncErrorReported_c = FALSE;
  uint8_t iBuf;
  uint8_t len;
  uint8_t FCSCheck=0;
  uint8_t temp;
	uint8_t bytesInBuffer;

	/* Check for fast exit*/
	if ( ghSCIHeadRxBuf == gtSCITailRxBuf ) {
	  return FALSE;
	}

	/* Poll any pre-STX bytes out of the buffer*/
	for(;;){
		if ( ghSCIHeadRxBuf == gtSCITailRxBuf ) {  /* This must be before the
		                                   next line due to interrupt issues*/
      break;
		}
	/* If sync bytes arrives between checks these two lines handles it*/	
		if (UART_ReadFromRxCirc(sync_c) == mUART_STXWord_c )  {  
		  break;
		}
		
		iBuf=UART_GetFromRxCirc(); /* Simply discard the data*/
		syncErrorDetected_c = TRUE;
	}

  if ((syncErrorDetected_c) && (!syncErrorReported_c)) {
		ZTCTestClientInterface_SendTestInterface("RxSyncError",lengthOfDataFieldForSyncError);
		syncErrorReported_c = TRUE;
	}

	/* Check for Rx busy (packet not completely received)*/
	bytesInBuffer = ghSCIHeadRxBuf - gtSCITailRxBuf;
	if (bytesInBuffer > gSCIRxBufferLen_c) {
	  bytesInBuffer += gSCIRxBufferLen_c; /* Unsigned calculation*/
	}
	/* Full packet is at least 4 bytes long
	   (necessary check to ensure valid length field, used in next line)*/
	if (bytesInBuffer < minimumLengthOfPacket)  {
	  return FALSE; 
	}
	/* The ReadIndexRxBuf function does NOT increment the
	                                   tailpointer (2=Len+FCS)*/
	if(bytesInBuffer < ( UART_ReadFromRxCirc(gLengthIndex_c+1) +
	                                       (gLengthIndex_c+1) + LenFcsIndex_c)) {
	  return FALSE; 
	}

	/*...At this point, we have confirmed that (at least) one complete packet
	                               is waiting in the Rx buffer...*/
	syncErrorReported_c = FALSE;


	/* Strip sync word (STX)  */
	iBuf=UART_GetFromRxCirc();

	/* Read length field  */
	len = UART_ReadFromRxCirc(gLengthIndex_c);
	if ( len > maxLen ) {
   ZTCTestClientInterface_SendTestInterface("RxLengthError",lengthOfDataFieldForRxLengthError);
		return FALSE;
	}

	/* Copy 'len+gHeaderSize_c' data bytes, while computing FCS check value */
	for (iBuf=0;iBuf<len+(gLengthIndex_c+1);iBuf++ ) { /*skips sync word
	                                                         and length*/
		temp = UART_GetFromRxCirc();
		*(pRxBuffer++) = temp;
		FCSCheck ^= temp; /* FCS computed on length and data fields*/
	}

	/* Strip and check FCS*/
	if ( UART_GetFromRxCirc() != FCSCheck ) {
  	ZTCTestClientInterface_SendTestInterface("RxFcsError",lengthOfDataFieldForRxFcsError);
		return FALSE;
	}

	return TRUE;							/* True indicates new data ready for parser*/ 

}



/****************************************************************************/

void ZTCTestClientInterface_SendTestInterface
  (
  uint8_t* pTxBuffer,  /* IN: pointer to string  */
  uint8_t length			 /* IN: Length of the string  */
  )
{
	uint8_t iBuf, FCSCheck;

	/* Add sync word*/
	UART_PutInTxCirc(mUART_STXWord_c);  /*Puts 1 char in the circular TX buffer*/

	/* Compute and add FCS*/
	FCSCheck = 0;
	for ( iBuf=0; iBuf<length; iBuf++ ) {
		FCSCheck ^= *pTxBuffer;          /* FCS computed on length and data fields*/
		UART_PutInTxCirc(*pTxBuffer++);
	}

	UART_PutInTxCirc(FCSCheck); 
  UART_EnableTransmitInterrupt();

	return;
}

/******************************************************************************
*******************************************************************************
* Private functions
*******************************************************************************
******************************************************************************/
/* None */
/******************************************************************************
*******************************************************************************
* Private Debug stuff
*******************************************************************************
******************************************************************************/
/* None */

#endif /* ( gZtcIncluded_d == 1  ) */

⌨️ 快捷键说明

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