📄 mrfi_f1f2.c
字号:
/**************************************************************************************************
* @fn MRFI_SetLogicalChannel
*
* @brief Set logical channel.
*
* @param chan - logical channel number
*
* @return none
**************************************************************************************************
*/
void MRFI_SetLogicalChannel(uint8_t chan)
{
/* logical channel is not valid? */
MRFI_ASSERT( chan < MRFI_NUM_LOGICAL_CHANS );
/* make sure radio is off before changing channels */
Mrfi_RxModeOff();
MRFI_WRITE_REGISTER( CHANNR, mrfiLogicalChanTable[chan] );
/* turn radio back on if it was on before channel change */
if(mrfiRadioState == MRFI_RADIO_STATE_RX)
{
Mrfi_RxModeOn();
}
}
/**************************************************************************************************
* @fn MRFI_SetRFPwr
*
* @brief Set RF Output power level.
*
* @param idx - index into power table.
*
* @return none
**************************************************************************************************
*/
void MRFI_SetRFPwr(uint8_t idx)
{
/* is power level specified valid? */
MRFI_ASSERT( idx < MRFI_NUM_POWER_SETTINGS );
/* make sure radio is off before changing power levels */
Mrfi_RxModeOff();
MRFI_WRITE_REGISTER( PA_TABLE0, mrfiRFPowerTable[idx] );
/* turn radio back on if it was on before power level change */
if(mrfiRadioState == MRFI_RADIO_STATE_RX)
{
Mrfi_RxModeOn();
}
}
/**************************************************************************************************
* @fn MRFI_SetRxAddrFilter
*
* @brief Set the address used for filtering received packets.
*
* @param pAddr - pointer to address to use for filtering
*
* @return zero : successfully set filter address
* non-zero : illegal address
**************************************************************************************************
*/
uint8_t MRFI_SetRxAddrFilter(uint8_t * pAddr)
{
/*
* If first byte of filter address match fir byte of broadcast address,
* there is a conflict with hardware filtering.
*/
if (pAddr[0] == mrfiBroadcastAddr[0])
{
/* unable to set filter address */
return( 1 );
}
/*
* Set the hardware address register. The hardware address filtering only recognizes
* a single byte but this does provide at least some automatic hardware filtering.
*/
MRFI_WRITE_REGISTER( ADDR, pAddr[0] );
/* save a copy of the filter address */
{
uint8_t i;
for (i=0; i<MRFI_ADDR_SIZE; i++)
{
mrfiRxFilterAddr[i] = pAddr[i];
}
}
/* successfully set filter address */
return( 0 );
}
/**************************************************************************************************
* @fn MRFI_EnableRxAddrFilter
*
* @brief Enable received packet filtering.
*
* @param none
*
* @return none
**************************************************************************************************
*/
void MRFI_EnableRxAddrFilter(void)
{
MRFI_ASSERT(mrfiRxFilterAddr[0] != mrfiBroadcastAddr[0]); /* filter address must be set before enabling filter */
/* set flag to indicate filtering is enabled */
mrfiRxFilterEnabled = 1;
/* enable hardware filtering on the radio */
MRFI_WRITE_REGISTER( PKTCTRL1, PKTCTRL1_ADDR_FILTER_ON );
}
/**************************************************************************************************
* @fn MRFI_DisableRxAddrFilter
*
* @brief Disable received packet filtering.
*
* @param pAddr - pointer to address to test for filtering
*
* @return none
**************************************************************************************************
*/
void MRFI_DisableRxAddrFilter(void)
{
/* clear flag that indicates filtering is enabled */
mrfiRxFilterEnabled = 0;
/* disable hardware filtering on the radio */
MRFI_WRITE_REGISTER( PKTCTRL1, PKTCTRL1_ADDR_FILTER_OFF );
}
/**************************************************************************************************
* @fn MRFI_RxAddrIsFiltered
*
* @brief Determine if address is filtered.
*
* @param none
*
* @return zero : address is not filtered
* non-zero : address is filtered
**************************************************************************************************
*/
uint8_t MRFI_RxAddrIsFiltered(uint8_t * pAddr)
{
uint8_t i;
uint8_t addrByte;
uint8_t filterAddrMatches;
uint8_t broadcastAddrMatches;
/* first check to see if filtering is even enabled */
if (!mrfiRxFilterEnabled)
{
/*
* Filtering is not enabled, so by definition the address is
* not filtered. Return zero to indicate address is not filtered.
*/
return( 0 );
}
/* clear address byte match counts */
filterAddrMatches = 0;
broadcastAddrMatches = 0;
/* loop through address to see if there is a match to filter address of broadcast address */
for (i=0; i<MRFI_ADDR_SIZE; i++)
{
/* get byte from address to check */
addrByte = pAddr[i];
/* compare byte to filter address byte */
if (addrByte == mrfiRxFilterAddr[i])
{
filterAddrMatches++;
}
if (addrByte == mrfiBroadcastAddr[i])
{
broadcastAddrMatches++;
}
}
/*
* If address is *not* filtered, either the "filter address match count" or
* the "broadcast address match count" will equal the total number of bytes
* in the address.
*/
if ((broadcastAddrMatches == MRFI_ADDR_SIZE) || (filterAddrMatches == MRFI_ADDR_SIZE))
{
/* address *not* filtered, return zero */
return( 0 );
}
else
{
/* address filtered, return non-zero */
return( 1 );
}
}
/**************************************************************************************************
* Compile Time Integrity Checks
**************************************************************************************************
*/
/*
* These asserts happen if there is extraneous compiler padding of arrays.
* Modify compiler settings for no padding, or, if that is not possible,
* comment out the offending asserts.
*/
BSP_STATIC_ASSERT(sizeof(mrfiLogicalChanTable) == ((sizeof(mrfiLogicalChanTable)/sizeof(mrfiLogicalChanTable[0])) * sizeof(mrfiLogicalChanTable[0])));
BSP_STATIC_ASSERT(sizeof(mrfiBroadcastAddr) == ((sizeof(mrfiBroadcastAddr)/sizeof(mrfiBroadcastAddr[0])) * sizeof(mrfiBroadcastAddr[0])));
/**************************************************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -