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

📄 ztcqueue.c

📁 freescale的基于802.15.4的无线通讯例程
💻 C
字号:
/******************************************************************************
* This file gives services for queuing up the messages received from test client
* or from SAP's of ZigBee layers..  
*
*
* (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 "EmbeddedTypes.h"
#include "FunctionLib.h"
#include "ZtcInterface.h"
#include "ZtcTestClientInterface.h"
#include "ZtcQueue.h"
#include "ZtcConfiguration.h"
#include "ZtcEventMonitor.h"
#include "ZtcPrimitiveHandler.h"
#if gBeeStackIncluded_d == 1  
#include "BeeStackConfiguration.h"
#include "AppZdoInterface.h"
#endif
#include "PublicConst.h"
#include "NV_Data.h"
#include "ZtcPrimitiveHandlerComplexPrimitive.h"
#include "ZtcPrimitiveHandlerComplexPrimWithOnePtr.h"
#include "ZtcPrimitiveHandlerComplexPrimWithTableList.h"
#include "ZtcPrimitiveHandlerComplexPrimSyncPrim.h"
#include "ZtcPrimitiveHandlerComplexPrimUtilitySupport.h"
#include "ZtcPrimitiveHandlerOtherComplexPrimitive.h"


/******************************************************************************
*******************************************************************************
* Private macros
*******************************************************************************
******************************************************************************/
/*****************************************************************************
* Verifies whether the opcode grp is of appOpcode group 
*
* Interface assumptions:
*       None
*
* The routine limitations.
*       None
*
* Return value:
*       None
*
* Effects on global data.
*       None
*
* Source of algorithm used.
*       None
*
* Revison history:
*
* date   Author   Comments
* ------ ------   --------
* 240306 LS,      Updated
*****************************************************************************/

#define ZTC_IsUsedOpcodeGrp( opCodeGrp )                \
         ( opCodeGrp >= gOpCodeGrpForMLMEToNwkSAP_c &&			\
         	 opCodeGrp <= gOpCodeGrpForZTCConf_c )
         	 
/*****************************************************************************
* Converts SapId used in Ztc to Opcode grp used by Test client 
*
* Interface assumptions:
*       None
*
* The routine limitations.
*       None
*
* Return value:
*       None
*
* Effects on global data.
*       None
*
* Source of algorithm used.
*       None
*
* Revison history:
*
* date   Author   Comments
* ------ ------   --------
* 240306 LS,      Updated
*****************************************************************************/

#define ZTC_ConvertSAPIdToOpcodeGrp( SAPId )  \
         gaSAPIdOpcodeGrp[SAPId];         

/******************************************************************************
*******************************************************************************
* Private prototypes
*******************************************************************************
******************************************************************************/

/*****************************************************************************
* This interface processes the message received from the test client. If
* the message is for ZTC then it processes the message. If the message is for
* the BeeStack, then it sends the message to the appropriate SAP, else it
* calls the function pointed by gpTestTollToApplicationFuncPtr
*
* Interface assumptions:
* None
*
* The routine limitations.
* None
*
* Return value:
* None
*
* Effects on global data.
* None
*
* Source of algorithm used.
* None
*
* Revison history:
*
* date   Author   Comments
* ------ ------   --------
* 240306 LS,      Updated
*****************************************************************************/
void ZTCQueue_ProcessMsgReceivedFromTestClient( void ); 

/******************************************************************************
*******************************************************************************
* Private type definitions
*******************************************************************************
******************************************************************************/
/* None */

/******************************************************************************
*******************************************************************************
* Public memory declarations
*******************************************************************************
******************************************************************************/

/* Function pointer to the Application  */  
gpfTestClientToApplication_t gpfTestClientToApplicationFuncPtr;

uint8_t aZTCBuffer[ gZTCBufferLength_c ]; /* Buffer to store the data for ZTC.
  It stores data from Test client to ZTC and Data to Test client from SAP */ 

uint8_t ghZTCBufferHead;

uint8_t gtZTCBufferTail;

/******************************************************************************
*******************************************************************************
* Public functions
*******************************************************************************
******************************************************************************/
void ZTCQueue_QueueTheMsgFromTestClient( void )
{
   if( ZTCTestClientInterface_PollTestInterface( aZTCBuffer,  gZTCBufferLength_c ))
    ZTCQueue_ProcessMsgReceivedFromTestClient();
}

/*****************************************************************************/
void ZTCQueue_SendMsgFromQToTestClient( void )
{
  uint8_t length;
  while( ghZTCBufferHead != gtZTCBufferTail ) {
    length = aZTCBuffer[ ghZTCBufferHead + gLengthIndex_c ] + gHeaderSize_c;
    ZTCTestClientInterface_SendTestInterface( &aZTCBuffer[ ghZTCBufferHead ], length );
    ghZTCBufferHead += length;
  }
  ghZTCBufferHead = gtZTCBufferTail = 0;
}


/*****************************************************************************/
uint8_t ZTCQueue_QueueToTestClient
  ( 
  const uint8_t* const pData,  /*  IN:Pointer to message */ 
  const uint8_t  opCodeGrp,	   /*  IN:Opcode group to send msg to Test client  */ 
  const uint8_t  opCodeGrpId,  /*  IN:Opcode to recognise the config attribute */
  const uint8_t  lengthOfData  /*  IN:Length of data */ 
  ) 
{
  uint8_t status = gZTCSucess_c ;
  if(( ZTCQueue_SpaceAvailableToWriteIntoBuffer ) >= 
       ( gHeaderSize_c + lengthOfData )) {
    aZTCBuffer [gtZTCBufferTail + gOpcodeGrpIndex_c ] = opCodeGrp; 
    aZTCBuffer [gtZTCBufferTail + gOpcodeIndex_c ] = opCodeGrpId;
    aZTCBuffer [gtZTCBufferTail + gLengthIndex_c ] = lengthOfData;
    
    FLib_MemCpy(&aZTCBuffer[ gtZTCBufferTail + gDataIndex_c ], 
      ( uint8_t * )pData, lengthOfData);
  
    gtZTCBufferTail += gHeaderSize_c + lengthOfData;
    TS_SendEvent( gZTCTaskId, gDataFromZTCToTestClientEvent_c );
    
  }
  else  {
    status = gZTCFailure_c;
  }
  return status;
}


/*****************************************************************************/
void ZTCQueue_QueueToSendToTestClient
  (
  const uint8_t* pMsg,				  /* IN : Pointer to the msg sent to the SAP */
  const uint8_t SAPId,					/* IN : SAP ID used in ZTC */
  const uint8_t msgIdUsedInZTC, /* IN : Message ID used in ZTC  */
  const uint8_t status					/* IN : Status returned from the SAP Handler */
  )
{
  uint8_t msgInfo;
  uint8_t opCodeGrp; 
  uint8_t length = 1;

  msgInfo = ZTCPrimHandle_GetInfoOnPrimitive( msgIdUsedInZTC );
  opCodeGrp = ZTC_ConvertSAPIdToOpcodeGrp(SAPId);
  
  if( ZTCQueue_SpaceAvailableToWriteIntoBuffer < gHeaderSize_c ) return;
  
  aZTCBuffer[ gtZTCBufferTail + gOpcodeGrpIndex_c ] = opCodeGrp; 

#if gBeeStackIncluded_d == 1  
  
  /* pMSG is incremented to point to the data part of the primitive. Since AF 
  to APP message sending happens throough the call back fucntion, all the 
  messages doesn't have magType */
  if((SAPId !=  gAFDEAppSAPHandlerId_c )&&(SAPId !=  gAppAFDE_SAPHandlerId_c)) {  
    aZTCBuffer[ gtZTCBufferTail + gOpcodeIndex_c ] = *pMsg; /* Opcode Id  */
    pMsg++;
  } 
  else {
    if( SAPId ==  gAFDEAppSAPHandlerId_c ) {
      aZTCBuffer[ gtZTCBufferTail + gOpcodeIndex_c ] = msgIdUsedInZTC - 
        gZTC_AFDataConf_c + 2; 
    } 
    else {	  aZTCBuffer[ gtZTCBufferTail + gOpcodeIndex_c ] = msgIdUsedInZTC - 
       gZTCRegEp_c; 
      
    }
  }
  
  /* The following part of the code checks whether the ZDO response is supported, 
  if not,then it sends unsupported request and the length of the ZDP response is 1.
  ZDP event also handled here */
  if(( SAPId ==  gZDPAppSAPHandlerId_c ) && (*( pMsg - 1 ) == gzdo2AppEventInd_c )) {
    
    return;
  }
  else if(( SAPId ==  gZDPAppSAPHandlerId_c ) && (*( pMsg - 1 ) & gGetRespBit_c ) && 
    ( *pMsg == gNotSupported_c )) {
     if(( ZTCQueue_SpaceAvailableToWriteIntoBuffer) >= ( gHeaderSize_c + length )){
        aZTCBuffer[ gtZTCBufferTail + gDataIndex_c ] = *pMsg; 	   
      }   
  } 
  else  
#endif /* gBeeStackIncluded_d */  
  {
    length = ZTCPrimHandle_StorePrimInZTCQueue( msgInfo, status, pMsg );    
  }

  if( length != gZTCCannotBeQueued_c ){
#if gZTC_SyncPrimitiveHandlingCapability_d == 1  
    if( ZTCPrimHandle_IsLengthFieldUpdationNeeded( msgIdUsedInZTC )){
#endif  /*  gZTC_SyncPrimitiveHandlingCapability_d  */          
      aZTCBuffer[ gtZTCBufferTail + gLengthIndex_c ] = length;
#if gZTC_SyncPrimitiveHandlingCapability_d == 1      
    }
#endif  /*  gZTC_SyncPrimitiveHandlingCapability_d  */    
    gtZTCBufferTail += gHeaderSize_c + length;
  
    TS_SendEvent( gZTCTaskId, gDataFromZTCToTestClientEvent_c );
  }
}
  
/******************************************************************************
*******************************************************************************
* Private functions
*******************************************************************************
******************************************************************************/
/*****************************************************************************/

void ZTCQueue_ProcessMsgReceivedFromTestClient( void ) 
{
  if( ZTC_IsUsedOpcodeGrp( aZTCBuffer[ gOpcodeGrpIndex_c ] )){
    if( aZTCBuffer[ gOpcodeGrpIndex_c ] != gOpCodeGrpForZTCReq_c ){
      ( void ) ZTCPrimHandle_SendToTheLayer(( ZTCMessage_t * )aZTCBuffer  );    
    }
    else{
     ZTCConfigure_Configure(( ZTCMessage_t* )aZTCBuffer );
    }
  } 
  else{
    ( *gpfTestClientToApplicationFuncPtr )(( ZTCMessage_t* )aZTCBuffer );  
       
  }
}
/******************************************************************************
*******************************************************************************
* Private Debug stuff
*******************************************************************************
******************************************************************************/
/*  None  */


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

⌨️ 快捷键说明

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