Пример #1
0
/***********************************************************************************
 * @fn      halRfSetTxPower
 *
 * @brief   Set TX output power
 *
 * @param   uint8 power - power level
 *
 * @return  SUCCESS or FAILED
 */
uint8 halRfSetTxPower(uint8 power) {
	uint8 n;

	switch (power) {
#ifdef INCLUDE_PA
	case HAL_RF_TXPOWER_MIN1_DBM: n = CC2520_TXPOWER_MIN1_DBM; break;
	case HAL_RF_TXPOWER_11_DBM: n = CC2520_TXPOWER_11_DBM; break;
	case HAL_RF_TXPOWER_14_DBM: n = CC2520_TXPOWER_14_DBM; break;
	case HAL_RF_TXPOWER_16_DBM: n = CC2520_TXPOWER_16_DBM; break;
	case HAL_RF_TXPOWER_17_DBM: n = CC2520_TXPOWER_17_DBM; break;
#else
	case HAL_RF_TXPOWER_MIN_4_DBM:
		n = CC2520_TXPOWER_MIN_4_DBM;
		break;
	case HAL_RF_TXPOWER_0_DBM:
		n = CC2520_TXPOWER_0_DBM;
		break;
	case HAL_RF_TXPOWER_4_DBM:
		n = CC2520_TXPOWER_4_DBM;
		break;
#endif
	default:
		return FAILED;
	}
	CC2520_REGWR8(CC2520_TXPOWER, n);
	return SUCCESS;
}
Пример #2
0
/**
 * PB0 => FIFOP
 */
void CC2520_ENABLE_FIFOP( void)
{
    NVIC_InitTypeDef NVIC_InitStructure;

    CC2520_REGWR8(CC2520_GPIOCTRL0, CC2520_GPIO_FIFOP);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOB, &GPIO_InitStructure);


    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);    
    NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    EXTI_ClearITPendingBit(EXTI_Line0);
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource0);
    EXTI_InitStructure.EXTI_Line = EXTI_Line0;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);

}
Пример #3
0
/***********************************************************************************
* @fn          halSampleED
*
* @brief      Sample Energy Detect
*
* @param      uint8 channel - channel between 11 and 26
*             uint16 sampleTime - sample time in us
*            
* @return     int8 - sampled RSSI value      
*/
int8 halSampleED(uint8 channel, uint16 sampleTime)
{
    int8 rssi=0;
    
    CC2520_REGWR8(CC2520_FREQCTRL, 0x0B + ( (channel-11) * 5));
    CC2520_SRXON();
    while (!CC2520_REGRD8(CC2520_RSSISTAT));
    
    // Enable ED scan mode
    CC2520_BSET(CC2520_MAKE_BIT_ADDR(CC2520_FRMCTRL0, 4));
    
    // Spend sampleTime us accumulating the peak RSSI value
    halMcuWaitUs(sampleTime);
    rssi = CC2520_REGRD8(CC2520_RSSI);
    
    // Exit the current channel
    CC2520_SRFOFF();
    // Disable ED scan mode
    CC2520_BCLR(CC2520_MAKE_BIT_ADDR(CC2520_FRMCTRL0, 4));
    
    return rssi;
}
Пример #4
0
/***********************************************************************************
* @fn          halSetRxScanMode
*
* @brief       Set chip in RX scanning mode
*
* @param       none 
*            
*
* @return     none
*/
void halSetRxScanMode(void)
{
    // Make CC2520 enter infinite RX mode
    CC2520_REGWR8(CC2520_FRMCTRL0, 0x0C);
}
Пример #5
0
/***********************************************************************************
 * @fn      halRfSetChannel
 *
 * @brief   Set RF channel in the 2.4GHz band. The Channel must be in the range 11-26,
 *          11= 2005 MHz, channel spacing 5 MHz.
 *
 * @param   channel - logical channel number
 *
 * @return  none
 */
void halRfSetChannel(uint8 channel) {
	CC2520_REGWR8(CC2520_FREQCTRL,
			MIN_CHANNEL + ((channel - MIN_CHANNEL) * CHANNEL_SPACING));
}
Пример #6
0
/***********************************************************************************
* @fn      cc2520_setChannel
*
* @brief   Set RF channel in the 2.4GHz band. The Channel must be in the range 11-26,
*          11= 2005 MHz, channel spacing 5 MHz.
*
* @param   channel - logical channel number
*
* @return  none
*/
void cc2520_setChannel(uint8_t channel)
{
    CC2520_REGWR8(CC2520_FREQCTRL, MIN_CHANNEL + ((channel - MIN_CHANNEL) * CHANNEL_SPACING));
}