信道配置:
Zigbee在3个频段定义了27个物理信道:868MHz频段中定义了1个信道,915MHz频段中定义了2个信道,信道间隔为2MHz,2.4GHz频段上定义了16个信道,信道间隔为5MHz.
信道编号 |
中心频率/MHz |
信道间隔/MHz |
频率上限/MHz |
频率下限/MHz |
k=0 |
868.3 |
-- |
868.6 |
868.0 |
k=1,2,…,10 |
906+2(k-1) |
2 |
928.0 |
902.0 |
k=11,12,…,26 |
2401+5(k-11) |
5 |
2483.5 |
2400.0 |
Z-stack中可以在f8wConfig.cfg里设置信道,相关部分如下:
/* Default channel is Channel 11 - 0x0B */
// Channels are defined in the following:
// 0 : 868 MHz 0x00000001
// 1 - 10 : 915 MHz 0x000007FE
// 11 - 26 : 2.4 GHz 0x07FFF800
//
//-DMAX_CHANNELS_868MHZ 0x00000001
//-DMAX_CHANNELS_915MHZ 0x000007FE
//-DMAX_CHANNELS_24GHZ 0x07FFF800
//-DDEFAULT_CHANLIST=0x04000000 // 26 - 0x1A
//-DDEFAULT_CHANLIST=0x02000000 // 25 - 0x19
//-DDEFAULT_CHANLIST=0x01000000 // 24 - 0x18
//-DDEFAULT_CHANLIST=0x00800000 // 23 - 0x17
//-DDEFAULT_CHANLIST=0x00400000 // 22 - 0x16
//-DDEFAULT_CHANLIST=0x00200000 // 21 - 0x15
//-DDEFAULT_CHANLIST=0x00100000 // 20 - 0x14
//-DDEFAULT_CHANLIST=0x00080000 // 19 - 0x13
//-DDEFAULT_CHANLIST=0x00040000 // 18 - 0x12
//-DDEFAULT_CHANLIST=0x00020000 // 17 - 0x11
//-DDEFAULT_CHANLIST=0x00010000 // 16 - 0x10
//-DDEFAULT_CHANLIST=0x00008000 // 15 - 0x0F
//-DDEFAULT_CHANLIST=0x00004000 // 14 - 0x0E
//-DDEFAULT_CHANLIST=0x00002000 // 13 - 0x0D
//-DDEFAULT_CHANLIST=0x00001000 // 12 - 0x0C
-DDEFAULT_CHANLIST=0x00000800 // 11 - 0x0B 这里默认使用的是编号为11的信道
当建网过程开始后,网络层将请求MAC层对规定的信道或由物理层默认的有效信道进行能量检测扫描,以检测可能的干扰。网络层管理实体对能量扫描的结果以递增的方式排序,丢弃那些能量值超出可允许能量水平的信道,然后再由网络层管理实体执行一次主动扫描,结合检查PAN描述符,对剩下的信道选择一个合适的建立网络。
若要在应用中查看信道,可以这样获得,_NIB.nwkLogicalChannel,读取这个就OK了。(NIB -NWK Information base-. 其中包含一些网络属性 PANID ,NETWORK ADDRESS 等等。其中_nib.nwkpanID是本网的ID标识,_NIB.extendedPANID按照字面意思是外网ID)
PANID:
在确定信道以后,下一步将是确定PANID,如果ZDAPP_CONFIG_PAN_ID被定义为0xFFFF,那么协调器将根据自身的IEEE地址建立一个随机的PANID(0~0x3FFF),如ZDAPP_CONFIG_PAN_ID没有被定义为0xFFFF,那么网络的PANID将由ZDAPP_CONFIG_PAN_ID确定。
“如果ZDAPP_CONFIG_PAN_ID被定义为0xFFFF,那么协调器将根据自身的IEEE地址建立一个随机的PANID(0~0x3FFF)”这句话怎么理解呢,我经过试验发现,这个随机的PANID并非完全随机,它有规律,与IEEE地址有一定的关系:要么就是IEEE地址的低16位,要么就是一个与IEEE地址低16位非常相似的值。如IEEE地址为0x8877665544332211,PANID很有可能就是2211,或相似的值;IEEE地址为0x8877665544337777,PANID很有可能就是3777,或其它相似的值;
Z-stack中相关部分代码如下:
/* Define the default PAN ID.
*
* Setting this to a value other than 0xFFFF causes
* ZDO_COORD to use this value as its PAN ID and
* Routers and end devices to join PAN with this ID
*/
-DZDAPP_CONFIG_PAN_ID=0xFFFF
若要在应用中查看PANID可以这样获得,_NIB.nwkPanId,读取这个就OK了。
发射功率:
传送范围的大小是和发射功率还有信道环境有关, 传送速率和传送范围之间没有直接联系。所以呢,适当的增大发射功率可增大传送范围。但也是有一定的限制的。具体详见datasheet。
在mac_radio_def.h里有可以设置:
#define MAC_RADIO_CHANNEL_DEFAULT 11
#define MAC_RADIO_TX_POWER_DEFAULT 0x1F
#define MAC_RADIO_TX_POWER_MAX_MINUS_DBM 25
这些只是举例说明一下,这些参数的意义,以及在z-stack里的什么地方修改。还有很多其它的参数,可以查看相关的源文件。
[mac_radio_def.h]
#define MAC_RADIO_SET_CHANNEL(x) st( FSCTRLL = FREQ_2405MHZ + 5 * ((x) - 11); )
#define MAC_RADIO_SET_TX_POWER(x) st( TXCTRLL = x; )
#define MAC_RADIO_SET_PAN_ID(x) st( PANIDL = (x) & 0xFF; PANIDH = (x) >> 8; )
[mac_radio.c]
void macRadioInit(void)
{
/* variable initialization for this module */
reqChannel = MAC_RADIO_CHANNEL_DEFAULT;
macPhyChannel = MAC_RADIO_CHANNEL_DEFAULT;
reqTxPower = MAC_RADIO_TX_POWER_DEFAULT;
macPhyTxPower = MAC_RADIO_TX_POWER_DEFAULT;
}
[mac_low_level.h]
uint8 macRadioRandomByte(void);
void macRadioSetPanCoordinator(uint8 panCoordinator);
void macRadioSetPanID(uint16 panID);
void macRadioSetShortAddr(uint16 shortAddr);
void macRadioSetIEEEAddr(uint8 * pIEEEAddr);
void macRadioSetTxPower(uint8 txPower);
void macRadioSetChannel(uint8 channel);
void macRadioStartScan(uint8 scanType);
void macRadioStopScan(void);
void macRadioEnergyDetectStart(void);
uint8 macRadioEnergyDetectStop(void);
设置发射功率:
CC2530 设置RF的发送功率寄存器为TXPOWER,全局搜索一下可以看到以下代码
#define MAC_RADIO_SET_PAN_COORDINATOR(b) st( FRMFILT0 = (FRMFILT0 & ~PAN_COORDINATOR) | (PAN_COORDINATOR * (b!=0)); )
#define MAC_RADIO_SET_CHANNEL(x) st( FREQCTRL = FREQ_2405MHZ + 5 * ((x) - 11); )
#define MAC_RADIO_SET_TX_POWER(x) st( TXPOWER = x; )
#define MAC_RADIO_SET_PAN_ID(x) st( PAN_ID0 = (x) & 0xFF; PAN_ID1 = (x) >> 8; )
#define MAC_RADIO_SET_SHORT_ADDR(x) st( SHORT_ADDR0 = (x) & 0xFF; SHORT_ADDR1 = (x) >> 8; )
继续跟踪MAC_RADIO_SET_TX_POWER
/**************************************************************************************************
* @fn macRadioUpdateTxPower
*
* @brief Update the radio's transmit power if a new power level has been requested
*
* @param reqTxPower - file scope variable that holds the last request power level
* macPhyTxPower - global variable that holds radio's set power level
*
* @return none
**************************************************************************************************
*/
MAC_INTERNAL_API void macRadioUpdateTxPower(void)
{
halIntState_t s;
/*
* If the requested power setting is different from the actual radio setting,
* attempt to udpate to the new power setting.
*/
HAL_ENTER_CRITICAL_SECTION(s);
if (reqTxPower != macPhyTxPower)
{
/*
* Radio power cannot be updated when the radio is physically transmitting.
* If there is a possibility radio is transmitting, do not change the power
* setting. This function will be called again after the current transmit
* completes.
*/
if (!macRxOutgoingAckFlag && !MAC_TX_IS_PHYSICALLY_ACTIVE())
{
/*
* Set new power level; update the shadow value and write
* the new value to the radio hardware.
*/
macPhyTxPower = reqTxPower;
MAC_RADIO_SET_TX_POWER(macPhyTxPower);
}
}
HAL_EXIT_CRITICAL_SECTION(s);
}
在这里我们可以看到TXPOWER的设置值实际上应该是reqTxOower,让我看一下reqTxOower在哪里设置吧,继续跟踪可以发现reqTxPower在函数MAC_INTERNAL_API uint8 macRadioSetTxPower(uint8 txPower)中得到更新,一路跟踪下去可以在函数uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)看到以下代码
case MAC_PHY_TRANSMIT_POWER:
/* Legacy transmit power attribute */
#if !defined HAL_MAC_USE_REGISTER_POWER_VALUES && \
!defined HAL_PA_LNA && !defined HAL_PA_LNA_CC2590
/* Legacy transmit power attribute value for CC2530 alone,
* or runtime selection support build means a negative absolute value.
* However, when used as register power values or
* with HAL_PA_LNAxxx definition (without runtime selection)
* the attribute value is not a negative absolute value. */
macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);
#endif /* !defined HAL_MAC_USE_REGISTER_POWER_VALUES && ... */
/* pass through to next case -- do not break*/
#endif /* MAC_OBSOLETE_PHY_TRANSMIT_POWER */
case MAC_PHY_TRANSMIT_POWER_SIGNED:
(void)macRadioSetTxPower(macPib.phyTransmitPower);
break;
到这里为止Z-Stack发送功率的设置流程已经明确,但是我找遍Z-Stack的工程也没有找到调用uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)的地方想来应该是封装在TI提供的LIB文件中了,
修改TXPOWER的方法有两种:一、在uint8 macRadioSetTxPower(uint8 txPower)函数中通过修改macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);的值来修改TXPOWER参数,系统复位后将使用调用该函数设置发送功率。修改macPib.phyTransmitPower
= (uint8)(-(int8)macPib.phyTransmitPower);可以通过修改以下结构体中的红色部分来修改
static CODE const macPib_t macPibDefaults =
{
54, /* ackWaitDuration */
FALSE, /* associationPermit */
TRUE, /* autoRequest */
FALSE, /* battLifeExt */
6, /* battLifeExtPeriods */
NULL, /* *pMacBeaconPayload */
0, /* beaconPayloadLength */
MAC_BO_NON_BEACON, /* beaconOrder */
0, /* beaconTxTime */
0, /* bsn */
{0, SADDR_MODE_EXT}, /* coordExtendedAddress */
MAC_SHORT_ADDR_NONE, /* coordShortAddress */
0, /* dsn */
FALSE, /* gtsPermit */
4, /* maxCsmaBackoffs */
3, /* minBe */
0xFFFF, /* panId */
FALSE, /* promiscuousMode */
FALSE, /* rxOnWhenIdle */
MAC_SHORT_ADDR_NONE, /* shortAddress */
MAC_SO_NONE, /* superframeOrder */
0x01F4, /* transactionPersistenceTime */
FALSE, /* assocciatedPanCoord */
5, /* maxBe */
1220, /* maxFrameTotalWaitTime */
3, /* maxFrameRetries */
32, /* ResponseWaitTime */
0, /* syncSymbolOffset */
TRUE, /* timeStampSupported */
FALSE, /* securityEnabled */
/* Proprietary */
#if defined (HAL_PA_LNA)
19, /* phyTransmitPower for CC2591 */
#elif defined (HAL_PA_LNA_CC2590)
11, /* phyTransmitPower for CC2590 */
#else
0, /* phyTransmitPower without frontend */
#endif
MAC_CHAN_11, /* logicalChannel */
{0, SADDR_MODE_EXT}, /* extendedAddress */
1, /* altBe */
MAC_BO_NON_BEACON, /* deviceBeaconOrder */
};
该值可以再-22到3之间变化具体可以参考
const uint8 CODE macRadioDefsTxPwrBare[] =
{
3, /* tramsmit power level of the first entry */
(uint8)(int8)-22, /* transmit power level of the last entry */
/* 3 dBm */ 0xF5, /* characterized as 4.5 dBm in datasheet */ //0
/* 2 dBm */ 0xE5, /* characterized as 2.5 dBm in datasheet */
/* 1 dBm */ 0xD5, /* characterized as 1 dBm in datasheet */
/* 0 dBm */ 0xD5, /* characterized as 1 dBm in datasheet */
/* -1 dBm */ 0xC5, /* characterized as -0.5 dBm in datasheet */
/* -2 dBm */ 0xB5, /* characterized as -1.5 dBm in datasheet */
/* -3 dBm */ 0xA5, /* characterized as -3 dBm in datasheet */
/* -4 dBm */ 0x95, /* characterized as -4 dBm in datasheet */
/* -5 dBm */ 0x95,
/* -6 dBm */ 0x85, /* characterized as -6 dBm in datasheet */
/* -7 dBm */ 0x85,
/* -8 dBm */ 0x75, /* characterized as -8 dBm in datasheet */
/* -9 dBm */ 0x75,
/* -10 dBm */ 0x65, /* characterized as -10 dBm in datasheet */
/* -11 dBm */ 0x65,
/* -12 dBm */ 0x55, /* characterized as -12 dBm in datasheet */
/* -13 dBm */ 0x55,
/* -14 dBm */ 0x45, /* characterized as -14 dBm in datasheet */
/* -15 dBm */ 0x45,
/* -16 dBm */ 0x35, /* characterized as -16 dBm in datasheet */
/* -17 dBm */ 0x35,
/* -18 dBm */ 0x25, /* characterized as -18 dBm in datasheet */
/* -19 dBm */ 0x25,
/* -20 dBm */ 0x15, /* characterized as -20 dBm in datasheet */
/* -21 dBm */ 0x15,
/* -22 dBm */ 0x05 /* characterized as -22 dBm in datasheet */
};
二、就是使用MT功能
void MT_SysSetTxPower(uint8 *pBuf)
{
/* A local variable to hold the signed dBm value of TxPower that is being requested. */
uint8 signed_dBm_of_TxPower_requeseted;
/*
* A local variable to hold the signed dBm value of TxPower that can be set which is closest to
* the requested dBm value of TxPower, but which is also valid according to a complex set of
* compile-time and run-time configuration which is interpreted by the macRadioSetTxPower()
* function.
*/
uint8 signed_dBm_of_TxPower_range_corrected;
/* Parse the requested dBm from the RPC message. */
signed_dBm_of_TxPower_requeseted = pBuf[MT_RPC_POS_DAT0];
/*
* MAC_MlmeSetReq() will store an out-of-range dBm parameter value into the NIB. So it is not
* possible to learn the actual dBm value that will be set by invoking MACMlmeGetReq().
* But this actual dBm value is a required return value in the SRSP to this SREQ. Therefore,
* it is necessary to make this redundant pre-call to macRadioSetTxPower() here in order to run
* the code that will properly constrain the requested dBm to a valid range based on both the
* compile-time and the run-time configurations that affect the available valid ranges
* (i.e. MAC_MlmeSetReq() itself will invoke for a second time the macRadioSetTxPower() function).
*/
signed_dBm_of_TxPower_range_corrected = macRadioSetTxPower(signed_dBm_of_TxPower_requeseted);
/*
* Call the function to store the requested dBm in the MAC PIB and to set the TxPower as closely
* as possible within the TxPower range that is valid for the compile-time and run-time
* configuration.
*/
(void)MAC_MlmeSetReq(MAC_PHY_TRANSMIT_POWER_SIGNED, &signed_dBm_of_TxPower_requeseted);
/* Build and send back the response that includes the actual dBm TxPower that can be set. */
MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS),
MT_SYS_SET_TX_POWER, 1,
&signed_dBm_of_TxPower_range_corrected);
}
转载:http://bbs.leekie.net/thread-5-1-1.html