当前位置:文档之家› 设置发射功率

设置发射功率

设置发射功率:CC2530 设置RF的发送功率寄存器为TXPOWER,全局搜索一下可以看到以下代码1.#define MAC_RADIO_SET_PAN_COORDINATOR(b) st( FRMFILT0 = (FRMFILT0 & ~PAN_COORDINATOR) | (PAN_COORDINATOR * (b!=0)); )2.#define MAC_RADIO_SET_CHANNEL(x) st( FREQCTRL = FREQ_2405MHZ + 5 * ((x) - 11); )3.#define MAC_RADIO_SET_TX_POWER(x) st( TXPOWER = x; )</font>4.5.#define MAC_RADIO_SET_PAN_ID(x) st( PAN_ID0 = (x) & 0xFF; PAN_ID1 = (x) >> 8; )6.#define MAC_RADIO_SET_SHORT_ADDR(x) st( SHORT_ADDR0 = (x)& 0xFF; SHORT_ADDR1 = (x) >> 8; )继续跟踪MAC_RADIO_SET_TX_POWER/********************************************************************************** ****************1.* @fn macRadioUpdateTxPower2.*3.* @brief Update the radio's transmit power if a new power level has been requested4.*5.* @param reqTxPower - file scope variable that holds the last requestpower level6.* macPhyTxPower - global variable that holds radio's set powerlevel7.*8.* @return none9.**************************************************************************************************10.*/11.MAC_INTERNAL_API void macRadioUpdateTxPower(void)12.{13. halIntState_t s;14.15./*16. * If the requested power setting is different from the actual radio setting,17. * attempt to udpate to the new power setting.18. */19. HAL_ENTER_CRITICAL_SECTION(s);20.if (reqTxPower != macPhyTxPower)21. {22./*23. * Radio power cannot be updated when the radio is physically transmitting.24. * If there is a possibility radio is transmitting, do not change the power25. * setting. This function will be called again after the current transmit26. * completes.27. */28.if (!macRxOutgoingAckFlag && !MAC_TX_IS_PHYSICALLY_ACTIVE())29. {30./*31. * Set new power level; update the shadow value and write32. * the new value to the radio hardware.33. */34. macPhyTxPower = reqTxPower;35.<font color="#ff0000"> MAC_RADIO_SET_TX_POWER(macPhyTxPower);</font>36. }37. }38. HAL_EXIT_CRITICAL_SECTION(s);39.}在这里我们可以看到TXPOWER的设置值实际上应该是reqTxOower,让我看一下reqTxOower在哪里设置吧,继续跟踪可以发现reqTxPower在函数MAC_INTERNAL_API uint8 macRadioSetTxPower(uint8 txPower)中得到更新,一路跟踪下去可以在函数uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)看到以下代码case MAC_PHY_TRANSMIT_POWER:1./* Legacy transmit power attribute */2.#if !defined HAL_MAC_USE_REGISTER_POWER_VALUES && \3. !defined HAL_PA_LNA && !defined HAL_PA_LNA_CC25904./* Legacy transmit power attribute value for CC2530 alone,5. * or runtime selection support build means a negative absolute value.6. * However, when used as register power values or7. * with HAL_PA_LNAxxx definition (without runtime selection)8. * the attribute value is not a negative absolute value. */9. macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);10.#endif /* !defined HAL_MAC_USE_REGISTER_POWER_VALUES && ... */11./* pass through to next case -- do not break*/12.13.#endif /* MAC_OBSOLETE_PHY_TRANSMIT_POWER */14.15.case MAC_PHY_TRANSMIT_POWER_SIGNED:16. (void)macRadioSetTxPower(macPib.phyTransmitPower);17.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 =1.{2. 54, /* ackWaitDuration */3. FALSE, /* associationPermit */4. TRUE, /* autoRequest */5. FALSE, /* battLifeExt */6. 6, /* battLifeExtPeriods */7.8. NULL, /* *pMacBeaconPayload */9. 0, /* beaconPayloadLength */10. MAC_BO_NON_BEACON, /* beaconOrder */11. 0, /* beaconTxTime */12. 0, /* bsn */13.14. {0, SADDR_MODE_EXT}, /* coordExtendedAddress */15. MAC_SHORT_ADDR_NONE, /* coordShortAddress */16. 0, /* dsn */17. FALSE, /* gtsPermit */18. 4, /* maxCsmaBackoffs */19.20. 3, /* minBe */21. 0xFFFF, /* panId */22. FALSE, /* promiscuousMode */23. FALSE, /* rxOnWhenIdle */24. MAC_SHORT_ADDR_NONE, /* shortAddress */25.26. MAC_SO_NONE, /* superframeOrder */27. 0x01F4, /* transactionPersistenceTime */28. FALSE, /* assocciatedPanCoord */29. 5, /* maxBe */30. 1220, /* maxFrameTotalWaitTime */31.32. 3, /* maxFrameRetries */33. 32, /* ResponseWaitTime */34. 0, /* syncSymbolOffset */35. TRUE, /* timeStampSupported */36. FALSE, /* securityEnabled */37.38./* Proprietary */39.#if defined (HAL_PA_LNA)40. 19, /* phyTransmitPower for CC2591 */41.#elif defined (HAL_PA_LNA_CC2590)42. 11, /* phyTransmitPower for CC2590 */43.#else44.<span style="color:#ff0000;">0, /*phyTransmitPower without frontend */</span>45.#endif46. MAC_CHAN_11, /* logicalChannel */47. {0, SADDR_MODE_EXT}, /* extendedAddress */48. 1, /* altBe */49. MAC_BO_NON_BEACON, /* deviceBeaconOrder */50.};该值可以再-22到3之间变化具体可以参考const uint8 CODE macRadioDefsTxPwrBare[] =1.{2. 3, /* tramsmit power level of the first entry */3. (uint8)(int8)-22, /* transmit power level of the last entry */4./* 3 dBm */ 0xF5, /* characterized as 4.5 dBm in datasheet *///5./* 2 dBm */ 0xE5, /* characterized as 2.5 dBm in datasheet */6./* 1 dBm */ 0xD5, /* characterized as 1 dBm in datasheet */7./* 0 dBm */ 0xD5, /* characterized as 1 dBm in datasheet */8./* -1 dBm */ 0xC5, /* characterized as -0.5 dBm in datasheet */9./* -2 dBm */ 0xB5, /* characterized as -1.5 dBm in datasheet */10./* -3 dBm */ 0xA5, /* characterized as -3 dBm in datasheet */11./* -4 dBm */ 0x95, /* characterized as -4 dBm in datasheet */12./* -5 dBm */ 0x95,13./* -6 dBm */ 0x85, /* characterized as -6 dBm in datasheet */14./* -7 dBm */ 0x85,15./* -8 dBm */ 0x75, /* characterized as -8 dBm in datasheet */16./* -9 dBm */ 0x75,17./* -10 dBm */ 0x65, /* characterized as -10 dBm in datasheet */18./* -11 dBm */ 0x65,19./* -12 dBm */ 0x55, /* characterized as -12 dBm in datasheet */20./* -13 dBm */ 0x55,21./* -14 dBm */ 0x45, /* characterized as -14 dBm in datasheet */22./* -15 dBm */ 0x45,23./* -16 dBm */ 0x35, /* characterized as -16 dBm in datasheet */24./* -17 dBm */ 0x35,25./* -18 dBm */ 0x25, /* characterized as -18 dBm in datasheet */26./* -19 dBm */ 0x25,27./* -20 dBm */ 0x15, /* characterized as -20 dBm in datasheet */28./* -21 dBm */ 0x15,29./* -22 dBm */ 0x05 /* characterized as -22 dBm in datasheet */30.};二、就是使用MT功能void MT_SysSetTxPower(uint8 *pBuf)1.{2./* A local variable to hold the signed dBm value of TxPower that is beingrequested. */3. uint8 signed_dBm_of_TxPower_requeseted;4. /* * A local variable to hold the signed dBm value of TxPower that can beset which is closest to5. * the requested dBm value of TxPower, but which is also valid according to a complex set of6. * compile-time and run-time configuration which is interpreted by the macRadioSetTxPower()7. * function. */8. uint8 signed_dBm_of_TxPower_range_corrected;9.10./* Parse the requested dBm from the RPC message. */11. signed_dBm_of_TxPower_requeseted = pBuf[MT_RPC_POS_DAT0];12./*13. * MAC_MlmeSetReq() will store an out-of-range dBm parameter value into the NIB. So it is not14. * possible to learn the actual dBm value that will be set by invoking MACMlmeGetReq().15. * But this actual dBm value is a required return value in the SRSP to this SREQ. Therefore,16. * it is necessary to make this redundant pre-call to macRadioSetTxPower()here in order to run17. * the code that will properly constrain the requested dBm to a valid range based on both the18. * compile-time and the run-time configurations that affect the availablevalid ranges19. * (i.e. MAC_MlmeSetReq() itself will invoke for a second time the macRadioSetTxPower() function). */20.<font color="#ff0000"> signed_dBm_of_TxPower_range_corrected = macRadioSetTxPower(signed_dBm_of_TxPower_requeseted);</font>21.22. /* * Call the function to store the requested dBm in the MAC PIB and to set the TxPower as closely23. * as possible within the TxPower range that is valid for the compile-timeand run-time24. * configuration. */25. (void)MAC_MlmeSetReq(MAC_PHY_TRANSMIT_POWER_SIGNED, &signed_dBm_of_TxPower_requeseted);26.27./* Build and send back the response that includes the actual dBm TxPower that can be set. */28.MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS),29. MT_SYS_SET_TX_POWER, 1,30. &signed_dBm_of_TxPower_range_corrected);31.}。

相关主题