/**************************************************************************************************
 * @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);
}
/**************************************************************************************************
 * @fn          macRxHardDisable
 *
 * @brief       Clear all enable flags and turn off receiver.
 *
 * @param       none
 *
 * @return      none
 **************************************************************************************************
 */
MAC_INTERNAL_API void macRxHardDisable(void)
{
  halIntState_t  s;

  DBG_PRINT0(DBGSYS, "macRxHardDisable()");
  HAL_ENTER_CRITICAL_SECTION(s);
  macRxEnableFlags = 0;
  MAC_DEBUG_TURN_OFF_RX_LED();
  HAL_EXIT_CRITICAL_SECTION(s);

  /* force off and clean up */
  macRxHaltCleanup();

  /* Power management state may change. Hence, vote. */
  macPwrVote();
}
/**************************************************************************************************
 * @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();
}
/**************************************************************************************************
 * @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);
}