📄 zmac.c
字号:
/********************************************************************************************************
Filename: zmac.c
Revised: $Date: 2006-11-28 13:47:33 -0800 (Tue, 28 Nov 2006) $
Revision: $Revision: 12837 $
Description:
This file contains the ZStack MAC Porting Layer
Notes:
Copyright (c) 2006 by Texas Instruments, Inc.
All Rights Reserved. Permission to use, reproduce, copy, prepare
derivative works, modify, distribute, perform, display or sell this
software and/or its documentation for any purpose is prohibited
without the express written consent of Texas Instruments, Inc.
********************************************************************************************************/
/********************************************************************************************************
* INCLUDES
********************************************************************************************************/
#include "ZComDef.h"
#include "OSAL.h"
#include "ZMAC.h"
/********************************************************************************************************
* MACROS
********************************************************************************************************/
/********************************************************************************************************
* CONSTANTS
********************************************************************************************************/
static CONST byte TxPowerSettings[] =
{
OUTPUT_POWER_0DBM,
OUTPUT_POWER_N1DBM,
OUTPUT_POWER_N3DBM,
OUTPUT_POWER_N5DBM,
OUTPUT_POWER_N7DBM,
OUTPUT_POWER_N10DBM,
OUTPUT_POWER_N15DBM,
OUTPUT_POWER_N25DBM
};
/********************************************************************************************************
* GLOBALS
********************************************************************************************************/
uint32 _ScanChannels;
extern uint8 aExtendedAddress[];
/********************************************************************************************************
* LOCALS
********************************************************************************************************/
/* Pointer to scan result buffer */
void *ZMac_ScanBuf = NULL;
/********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
********************************************************************************************************/
/********************************************************************************************************
* TYPEDEFS
********************************************************************************************************/
/********************************************************************************************************
* FUNCTIONS
********************************************************************************************************/
/********************************************************************************************************
* @fn ZMacInit
*
* @brief Initialize MAC.
*
* @param none.
*
* @return status.
********************************************************************************************************/
ROOT uint8 ZMacInit( void )
{
uint8 stat;
MAC_Init();
MAC_InitDevice();
#if defined ( RTR_NWK )
MAC_InitCoord();
#endif
// If OK, initialize the MAC
stat = ZMacReset( TRUE );
// Turn off interrupts
osal_int_disable( INTS_ALL );
return ( stat );
}
/********************************************************************************************************
* @fn ZMacUpdate
*
* @brief Gives MAC (or others) some processing time.
*
* @param none.
*
* @return true if CPU needs to keep running (not sleep).
********************************************************************************************************/
ROOT byte ZMacUpdate( void )
{
/* Put code here that needs to run each OSAL event loop */
return ( false );
}
/********************************************************************************************************
* @fn ZMacReset
*
* @brief Reset the MAC.
*
* @param Default to PIB defaults.
*
* @return status.
********************************************************************************************************/
ROOT uint8 ZMacReset( bool SetDefaultPIB )
{
byte stat;
byte value;
stat = MAC_MlmeResetReq( SetDefaultPIB );
// Don't send PAN ID conflict
value = FALSE;
MAC_MlmeSetReq( MAC_ASSOCIATED_PAN_COORD, &value );
MAC_MlmeSetReq( MAC_EXTENDED_ADDRESS, &aExtendedAddress );
if (ZMac_ScanBuf)
{
osal_mem_free(ZMac_ScanBuf);
ZMac_ScanBuf = NULL;
}
return ( stat );
}
/********************************************************************************************************
* @fn ZMacGetReq
*
* @brief Read a MAC PIB attribute.
*
* @param attr - PIB attribute to get
* @param value - pointer to the buffer to store the attribute
*
* @return status
********************************************************************************************************/
ROOT uint8 ZMacGetReq( uint8 attr, uint8 *value )
{
if ( attr == ZMacExtAddr )
{
osal_cpyExtAddr( value, &aExtendedAddress );
return ZMacSuccess;
}
return (ZMacStatus_t) MAC_MlmeGetReq( attr, value );
}
/********************************************************************************************************
* @fn ZMacSetReq
*
* @brief Write a MAC PIB attribute.
*
* @param attr - PIB attribute to Set
* @param value - pointer to the data
*
* @return status
********************************************************************************************************/
ROOT uint8 ZMacSetReq( uint8 attr, byte *value )
{
if ( attr == ZMacExtAddr )
{
osal_cpyExtAddr( &aExtendedAddress, value );
}
return (ZMacStatus_t) MAC_MlmeSetReq( attr, value );
}
/********************************************************************************************************
* @fn ZMacAssociateReq
*
* @brief Request an association with a coordinator.
*
* @param structure with info need to associate.
*
* @return status
********************************************************************************************************/
ROOT uint8 ZMacAssociateReq( ZMacAssociateReq_t *pData )
{
/* Right now, set security to zero */
pData->Sec.SecurityLevel = false;
MAC_MlmeAssociateReq ( (macMlmeAssociateReq_t *)pData);
return ( ZMacSuccess );
}
/********************************************************************************************************
* @fn ZMacAssociateRsp
*
* @brief Request to send an association response message.
*
* @param structure with associate response and info needed to send it.
*
* @return status
********************************************************************************************************/
ROOT uint8 ZMacAssociateRsp( ZMacAssociateRsp_t *pData )
{
/* Right now, set security to zero */
pData->Sec.SecurityLevel = false;
MAC_MlmeAssociateRsp( (macMlmeAssociateRsp_t *) pData );
return ( ZMacSuccess );
}
/********************************************************************************************************
* @fn ZMacDisassociateReq
*
* @brief Request to send a disassociate request message.
*
* @param structure with info need send it.
*
* @return status
********************************************************************************************************/
ROOT uint8 ZMacDisassociateReq( ZMacDisassociateReq_t *pData )
{
/* Right now, set security to zero */
pData->Sec.SecurityLevel = false;
MAC_MlmeDisassociateReq( (macMlmeDisassociateReq_t *)pData);
return ( ZMacSuccess );
}
/********************************************************************************************************
* @fn ZMacOrphanRsp
*
* @brief Allows next higher layer to respond to an orphan indication message.
*
* @param structure with info need send it.
*
* @return status
********************************************************************************************************/
ROOT uint8 ZMacOrphanRsp( ZMacOrphanRsp_t *pData )
{
/* Right now, set security to zero */
pData->Sec.SecurityLevel = false;
MAC_MlmeOrphanRsp( (macMlmeOrphanRsp_t *)pData);
return ( ZMacSuccess );
}
/********************************************************************************************************
* @fn ZMacRxEnableReq
*
* @brief This function contains timing information that tells the
* device when to enable or disable its receiver, in order
* to schedule a data transfer between itself and another
* device. The information is sent from the upper layers
* directly to the MAC sublayer.
*
* @param structure with info need send it.
*
* @return status
********************************************************************************************************/
ROOT uint8 ZMacRxEnableReq( ZMacRxEnableReq_t *pData )
{
/* This feature is no longer in the TIMAC */
return ( ZMacUnsupported );
}
/********************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -