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

📄 nwk_general.h

📁 ucos在NEC平台下的移植
💻 H
字号:
/*
 *******************************************************************************************************
 * CONFIDENTIAL                                                                                        *
 * The use of this file is restricted by SkywiseSystems                    *
 *                                                                                                     *
 * Copyright liquanling 02/09/2006                                                                          *
 *******************************************************************************************************
 * This module contains general types, constants, macros and functions used by many other NWK modules.  
 *******************************************************************************************************
 * Compiler: NEC-CC78K0                                                                                  *
 * Target platform:                                                   *
 *******************************************************************************************************
 * The revision history is located at the bottom of this file                                          *
 *******************************************************************************************************/
 #ifndef NWK_GENERAL_H
 #define NWK_GENERAL_H
 /*******************************************************************************************************
 *******************************************************************************************************
 **************************               CONSTANTS AND MACROS                **************************
 *******************************************************************************************************
 *******************************************************************************************************/

//-------------------------------------------------------------------------------------------------------
// NWK command packet types
  typedef enum {
    NWK_CMD_ROUTE_REQUEST = 1,
    NWK_CMD_ROUTE_REPLY,
    NWK_CMD_ROUTE_ERROR,
    NWK_CMD_LEAVE_REQUEST,
    NWK_CMD_LEAVE_INDICATION
} NWK_COMMAND_TYPE;
//-------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------
// NWK command payload lengths, including the command frame identifier

#define CMD_ROUTE_REQUEST_PAYLOAD_LENGTH          6
#define CMD_ROUTE_REPLY_PAYLOAD_LENGTH               8
#define CMD_ROUTE_ERROR_PAYLOAD_LENGTH               4
#define CMD_LEAVE_REQUEST_PAYLOAD_LENGTH           2
#define CMD_LEAVE_INDICATION_PAYLOAD_LENGTH      2

//-------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------
// Frame control field formatting

// FRAME_TYPE
#define FRAME_TYPE_NWK_DATA                     0
#define FRAME_TYPE_NWK_COMMAND              1
#define FRAME_TYPE_10                                   2 
#define FRAME_TYPE_11                                   3

// Frame control field formatting

// Bit masks
#define NWK_FRAME_TYPE_BM               0x0003
#define NWK_PROTOCOL_VERSION_BM         0x003C
#define NWK_DISCOVER_ROUTE_BM            0x00C0
#define NWK_SECURITY_BM                  0x0200
// Data holding structure + a mask to tell which ones to update
typedef struct {
    ZBOOL macBattLifeExt;
    UINT8 macBeaconOrder;
    ZBOOL macRxOnWhenIdle;
    UINT8 macSuperframeOrder;
    BYTE updateMask;
} NWK_PIB_TEMP_BUFFER;
// Internal module data

typedef struct {
    volatile NWK_STATE_TYPE state;
    NWK_PIB_TEMP_BUFFER nibTempBuffer;
    BYTE flags;
} NWK_INFO;
extern NWK_INFO nwkInfo;


#define TickCompare(a,b) (a - b)
//-------------------------------------------------------------------------------------------------------
//TICK getCurrentime();
//
//DESCRIPTION:
//       Catch the current time.we can use the register to implement or we can use 
//       the API of the ucOS.
//PARAMETER:
//        NO
//RETURN_VALUE
//        The current time-maybe a snap of some register
//--------------------------------------------------------------------------------------------
TICK getCurrentime();
//#define getCurrentime()  time(&now) 


//-------------------------------------------------------------------------------------------------------
//  ZBOOL nwkSetState(NWK_STATE_TYPE newState)
//
//  DESCRIPTION:
//      Changes the internal NWK state, which is used to control polling and scanning. Only specific
//      sequences of transitions are allowed.
//
//  PARAMETER:
//      NWK_STATE_TYPE newState
//          The new NWK state
//
//  RETURN VALUE:
//      ZBOOL 
//          TRUE if successful (legal transition to newState)
//          FALSE otherwise (the state was not changed)
//-------------------------------------------------------------------------------------------------------
ZBOOL nwkSetState(NWK_STATE_TYPE newState); 
//------------------------------------------------------------------
//     void ByteArrayToUint16(BYTE *shortAddress,UINT16 *myShortAddress);	  
//
//     DESCRIPTION:
//            Transfer the byte array to UINT16 data type.
//     PARAMETER:
//            BYTE *shortAddress,
//            A pointer points to the byte array.
//            short *myShortAddress,
//            A 'value-result' parameter,take back the result.
//    RETURN VALUE:
//            NO;
//    NOTE:in the program,the address information stored in the NWK header and some
//             NWK payload are in the byte format,some time we need to transmit.
//--------------------------------------------------------------------

void ByteArrayToUint16(BYTE *shortAddress,UINT16*myShortAddress);	

//--------------------------------------------------------------------
//     void InitNWKCommonVariable();
//
//     DESCRIPTION:
//           Some variable such as the short addres of the device and the device'PanId and 
//           so on,these variables will be used in every .c file in the NWK layer,so use this 
//           the global variable to store these common information.This function initialize 
//           these global variables.
//     PARAMETER:
//           NO.
//     RETURN-VALUE:
//           NO.
//    NOTE:This function must be called at the startup of the program.
//-------------------------------------------------------------------
void InitNWKCommonVariable();

//----------------------------------------------------------------------
//     void getAddressInfoInNwkHeader();
//
//      DESCRIPTION:
//            There are some global variables in this program,such as  nwkSrcAddrInHeaderOfRecivedPacket
//             and nwkDstAddrInHeaderOfRecivedPacket,these variables will be used in 
//             nwkDealWithRecivedLeaveIndicationFromMCPS()and other functions,so use global
//             variable instead of passing parameters to every relate function.
//      PARAMETER:
//             NO.
//      RETURN-VALUE:
//             NO.
//      NOTE:This function should only be called in mcpsDataIndication() function.
//-------------------------------------------------------------------------
void getAddressInfoInNwkHeader();


//---------------------------------------------------------------------------------------------
//    ZBOOL longAddressIsNULL(BYTE * longAddress);
//
//    DESCRIPTION:
//         This function wraps the operation about justifying is the device's long address is NULL.This function is used 
//          when the device leaves the network;
//    PARAMETER:
//          BYTE * longAddress:
//            This pointer points to the device's long address.
//    RETURN_VALUE:
//          TRUE:the device's long address is NULL.
//          FALSE:the device's long address is not NULL.
//----------------------------------------------------------------------------------------------
ZBOOL longAddressIsNULL(BYTE * longAddress);

//-----------------------------------------------------------------------------------------------
//    UINT8 randNumGenerator(UINT8 maxNum);
//
//    DESCRIPTION:
//          This function is used to generat a random number between 0 and maxNum.
//    PARAMETER:
//          UINT8 maxNum:
//              The right  range of the generated random value.
//    RETURN_VALUE:
//          The generated random value.
//    NOTE:This function depends on system function.
//-----------------------------------------------------------------------------------------------
UINT8 randNumGenerator(UINT8 maxNum);

#endif

⌨️ 快捷键说明

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