📄 mac_radio.c
字号:
/**************************************************************************************************
Filename:
Revised: $Date: 2007-03-26 16:18:09 -0700 (Mon, 26 Mar 2007) $
Revision: $Revision: 13860 $
Description:
Describe the purpose and contents of the file.
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
* ------------------------------------------------------------------------------------------------
*/
/* hal */
#include "hal_types.h"
/* high-level */
#include "mac_pib.h"
/* exported low-level */
#include "mac_low_level.h"
/* low-level specific */
#include "mac_radio.h"
#include "mac_tx.h"
#include "mac_rx.h"
#include "mac_rx_onoff.h"
#include "mac_sleep.h"
#include "mac_backoff_timer.h"
/* target specific */
#include "mac_radio_defs.h"
/* debug */
#include "mac_assert.h"
/* ------------------------------------------------------------------------------------------------
* Includes
* ------------------------------------------------------------------------------------------------
*/
#define ED_RF_POWER_MIN_DBM (MAC_RADIO_RECEIVER_SENSITIVITY_DBM + MAC_SPEC_ED_MIN_DBM_ABOVE_RECEIVER_SENSITIVITY)
#define ED_RF_POWER_MAX_DBM MAC_RADIO_RECEIVER_SATURATION_DBM
/* ------------------------------------------------------------------------------------------------
* Global Variables
* ------------------------------------------------------------------------------------------------
*/
uint8 macPhyTxPower;
uint8 macPhyChannel;
/* ------------------------------------------------------------------------------------------------
* Local Variables
* ------------------------------------------------------------------------------------------------
*/
static uint8 reqChannel;
static uint8 reqTxPower;
/* ------------------------------------------------------------------------------------------------
* Local Functions
* ------------------------------------------------------------------------------------------------
*/
static uint8 radioComputeED(int8 rssiDbm);
/**************************************************************************************************
* @fn macRadioInit
*
* @brief Initialize radio software.
*
* @param none
*
* @return none
**************************************************************************************************
*/
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;
}
/**************************************************************************************************
* @fn macRadioReset
*
* @brief Resets the radio module.
*
* @param none
*
* @return none
**************************************************************************************************
*/
void macRadioReset(void)
{
macRadioStopScan();
macRadioEnergyDetectStop();
}
/**************************************************************************************************
* @fn macRadioRandomByte
*
* @brief Return a random byte derived from previously set random seed.
*
* @param none
*
* @return a random byte
**************************************************************************************************
*/
uint8 macRadioRandomByte(void)
{
return(MAC_RADIO_RANDOM_BYTE());
}
/**************************************************************************************************
* @fn macRadioSetPanCoordinator
*
* @brief Configure the pan coordinator status of the radio
*
* @param panCoordFlag - non-zero to configure radio to be pan coordinator
* zero to configure radio as NON pan coordinator
*
* @return none
**************************************************************************************************
*/
void macRadioSetPanCoordinator(uint8 panCoordFlag)
{
/* abstracted radio configuration */
MAC_RADIO_SET_PAN_COORDINATOR(panCoordFlag);
}
/**************************************************************************************************
* @fn macRadioSetPanID
*
* @brief Set the pan ID on the radio.
*
* @param panID - 16 bit PAN identifier
*
* @return none
**************************************************************************************************
*/
void macRadioSetPanID(uint16 panID)
{
/* abstracted radio configuration */
MAC_RADIO_SET_PAN_ID(panID);
}
/**************************************************************************************************
* @fn macRadioSetShortAddr
*
* @brief Set the short addrss on the radio.
*
* @param shortAddr - 16 bit short address
*
* @return none
**************************************************************************************************
*/
void macRadioSetShortAddr(uint16 shortAddr)
{
/* abstracted radio configuration */
MAC_RADIO_SET_SHORT_ADDR(shortAddr);
}
/**************************************************************************************************
* @fn macRadioSetIEEEAddr
*
* @brief Set the IEEE address on the radio.
*
* @param pIEEEAddr - pointer to array holding 64 bit IEEE address; array must be little
* endian format (starts with lowest signficant byte)
*
* @return none
**************************************************************************************************
*/
void macRadioSetIEEEAddr(uint8 * pIEEEAddr)
{
/* abstracted radio configuration */
MAC_RADIO_SET_IEEE_ADDR(pIEEEAddr);
}
/**************************************************************************************************
* @fn macRadioSetTxPower
*
* @brief Set transmitter power of the radio.
*
* @param txPower - the minus dBm for power but as a postive integer (or if configured
* for it, txPower is the raw register value).
*
* @return none
**************************************************************************************************
*/
#ifndef HAL_MAC_USE_REGISTER_POWER_VALUES
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void macRadioSetTxPower(uint8 txPower)
{
halIntState_t s;
/* if the selected dBm is out of range, use the closest available */
if (txPower > MAC_RADIO_TX_POWER_MAX_MINUS_DBM)
{
txPower = MAC_RADIO_TX_POWER_MAX_MINUS_DBM;
}
/*
* Set the global variable reqTxPower. This variable is referenced
* by the function macRadioUpdateTxPower() to write the radio register.
*
* A lookup table is used to translate the power level to the register
* value.
*/
HAL_ENTER_CRITICAL_SECTION(s);
reqTxPower = macRadioDefsTxPowerTable[txPower];
HAL_EXIT_CRITICAL_SECTION(s);
/* update the radio power setting */
macRadioUpdateTxPower();
}
#else
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void macRadioSetTxPower(uint8 txPower)
{
halIntState_t s;
/* same as above but with no lookup table, use raw register value */
HAL_ENTER_CRITICAL_SECTION(s);
reqTxPower = txPower;
HAL_EXIT_CRITICAL_SECTION(s);
/* update the radio power setting */
macRadioUpdateTxPower();
}
#endif
/**************************************************************************************************
* @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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -