コード例 #1
0
/**************************************************************************************************
 * @fn          macRxOff
 *
 * @brief       Turn off the receiver if it's not already off.
 *
 * @param       none
 *
 * @return      none
 **************************************************************************************************
 */
MAC_INTERNAL_API void macRxOff(void)
{
  halIntState_t  s;

  DBG_PRINT1(DBGSYS, "macRxOff(): macRxOnFlag = 0x%X", macRxOnFlag);
  HAL_ENTER_CRITICAL_SECTION(s);
  if (macRxOnFlag)
  {
    macRxOnFlag = 0;
    DBG_PRINT0(DBGSYS, "MAC_RADIO_RXTX_OFF()");
    MAC_RADIO_RXTX_OFF();

    /* Wait till RX is completely off before issuing another RX related
     * command which may fail if issued beforehand. */
    macCheckCommnadDone(&macRxEdScan.rxCmd.rfOpCmd);
    
    /* Wait till all FG commands are done */
    macCheckCommnadDone(&macCsmaCaCmd.rfOpCmd);
    macCheckCommnadDone(&macTxCmd.rfOpCmd); 
    macCheckCommnadDone(&macRxAckCmd.rfOpCmd);
       
    MAC_DEBUG_TURN_OFF_RX_LED();
    
    /* just in case a receive was about to start, flush the receive FIFO */
    MAC_RADIO_FLUSH_RX_FIFO();

    /* clear any receive interrupt that happened to squeak through */
    MAC_RADIO_CLEAR_RX_THRESHOLD_INTERRUPT_FLAG();

  }
  HAL_EXIT_CRITICAL_SECTION(s);
}
コード例 #2
0
/**************************************************************************************************
 * @fn          znpTestRF
 *
 * @brief       This function initializes and checks the ZNP RF Test Mode NV items. It is designed
 *              to be invoked before/instead of MAC radio initialization.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 */
void znpTestRF(void)
{
  uint8 rfTestParms[4] = { 0, 0, 0, 0 };

  if ((SUCCESS != osal_nv_item_init(ZNP_NV_RF_TEST_PARMS, 4, rfTestParms))  ||
      (SUCCESS != osal_nv_read(ZNP_NV_RF_TEST_PARMS, 0, 4, rfTestParms)) ||
      (rfTestParms[0] == 0))
  {
    return;
  }

  // Settings from SmartRF Studio
  MDMCTRL0 = 0x85;
  RXCTRL = 0x3F;
  FSCTRL = 0x5A;
  FSCAL1 = 0x2B;
  AGCCTRL1 = 0x11;
  ADCTEST0 = 0x10;
  ADCTEST1 = 0x0E;
  ADCTEST2 = 0x03;

  FRMCTRL0 = 0x43;
  FRMCTRL1 = 0x00;

  MAC_RADIO_RXTX_OFF();
  MAC_RADIO_SET_CHANNEL(rfTestParms[1]);
  MAC_RADIO_SET_TX_POWER(rfTestParms[2]);
  TX_PWR_TONE_SET(rfTestParms[3]);

  switch (rfTestParms[0])
  {
  case 1:  // Rx promiscuous mode.
    MAC_RADIO_RX_ON();
    break;

  case 2:  // Un-modulated Tx.
    TX_PWR_MOD__SET(1);
    // no break;

  case 3:  // Modulated Tx.
    // Modulated is default register setting, so no special action.

    // Now turn on Tx power for either mod or un-modulated Tx test.
    MAC_RADIO_TX_ON();
    break;

  default:  // Not expected.
    break;
  }

  // Clear the RF test mode.
  (void)osal_memset(rfTestParms, 0, 4);
  (void)osal_nv_write(ZNP_NV_RF_TEST_PARMS, 0, 4, rfTestParms);

  while (1);  // Spin in RF test mode until a hard reset.
}
コード例 #3
0
ファイル: Mac_sleep.c プロジェクト: freedream520/zigbeeWSN
/**************************************************************************************************
 * @fn          macSleep
 *
 * @brief       Puts radio into the selected sleep mode.
 *
 * @param       sleepState - selected sleep level, see #defines in .h file
 *
 * @return      TRUE if radio was successfully put into selected sleep mode.
 *              FALSE if it was not safe for radio to go to sleep.
 **************************************************************************************************
 */
BOOL macSleep(void)
{
    BOOL  s;

    /* disable interrupts until macSleepState can be set */
    HAL_ENTER_CRITICAL_SECTION(s);

    /* assert checks */
    //MAC_ASSERT(macSleepState == MAC_SLEEP_STATE_AWAKE); /* radio must be awake to put it to sleep */
    //MAC_ASSERT(macRxFilter == RX_FILTER_OFF); /* do not sleep when scanning or in promiscuous mode */
    if (macSleepState != MAC_SLEEP_STATE_AWAKE)
    {
        HAL_EXIT_CRITICAL_SECTION(s);
        return(FALSE);
    }

    /* if either RX or TX is active or any RX enable flags are set, it's not OK to sleep */
    if (macTXBusy())
    {
        HAL_EXIT_CRITICAL_SECTION(s);
        return(FALSE);
    }

    /* turn off the receiver */
    MAC_RADIO_RXTX_OFF();
    MAC_RADIO_FLUSH_RX_FIFO();

    /* update sleep state variable */
    macSleepState = MAC_SLEEP_STATE_RADIO_OFF;

    /* macSleepState is now set, re-enable interrupts */
    HAL_EXIT_CRITICAL_SECTION(s);

    /* put MAC timer to sleep */
    /* MAC timer 关闭时,
    T2THD:T2TLD自动保存到T2CAPHPH:T2CAPLPL,T2OF2:T2OF1:T2OF0自动保存到T2PEROF2:T2PEROF1:T2PEROF0 */
    MAC_RADIO_TIMER_SLEEP();

    /* put radio in selected sleep mode */
    MAC_RADIO_TURN_OFF_POWER();

    /* radio successfully entered sleep mode */
    return(TRUE);
}
コード例 #4
0
ファイル: mac_rx_onoff.c プロジェクト: kricnam/blackboxreader
/**************************************************************************************************
 * @fn          macRxHardDisable
 *
 * @brief       Clear all enable flags and turn off receiver.
 *
 * @param       none
 *
 * @return      none
 **************************************************************************************************
 */
void macRxHardDisable(void)
{
  halIntState_t  s;

  HAL_ENTER_CRITICAL_SECTION(s);

  macRxEnableFlags = 0;
  macRxOnFlag = 0;

  /* force receiver off */
  MAC_RADIO_RXTX_OFF();
  MAC_RADIO_FLUSH_RX_FIFO();
  MAC_DEBUG_TURN_OFF_RX_LED();

  HAL_EXIT_CRITICAL_SECTION(s);

  /* clean up after being forced off */
  macRxHaltCleanup();
}
コード例 #5
0
ファイル: mac_rx_onoff.c プロジェクト: kricnam/blackboxreader
/**************************************************************************************************
 * @fn          macRxOff
 *
 * @brief       Turn off the receiver if it's not already off.
 *
 * @param       none
 *
 * @return      none
 **************************************************************************************************
 */
void macRxOff(void)
{
  halIntState_t  s;

  HAL_ENTER_CRITICAL_SECTION(s);
  if (macRxOnFlag)
  {
    macRxOnFlag = 0;
    MAC_RADIO_RXTX_OFF();
    MAC_DEBUG_TURN_OFF_RX_LED();

    /* just in case a receive was about to start, flush the receive FIFO */
    MAC_RADIO_FLUSH_RX_FIFO();

    /* clear any receive interrupt that happened to squeak through */
    MAC_RADIO_CLEAR_RX_THRESHOLD_INTERRUPT_FLAG();

  }
  HAL_EXIT_CRITICAL_SECTION(s);
}