예제 #1
0
/**************************************************************************************************
 * @fn          macTxDoneCallback
 *
 * @brief       -
 *
 * @param       -
 *
 * @return      none
 **************************************************************************************************
 */
void macTxDoneCallback(uint8 status)
{
  if (status == MAC_TXDONE_SUCCESS)
  {
    /* see if ACK was requested */
    if (!txAckReq)
    {
      /* ACK was not requested, transmit is complete */
      txComplete(MAC_SUCCESS);
    }
    else
    {
      /*
       *  ACK was requested - must wait to receive it.  A timer is set
       *  to expire after the timeout duration for waiting for an ACK.
       *  If an ACK is received, the function macTxAckReceived() is called.
       *  If an ACK is not received within the timeout period,
       *  the function macTxAckTimeoutCallback() is called.
       */
      macTxListenForAck = TRUE;
      MAC_RADIO_TX_REQUEST_ACK_TIMEOUT_CALLBACK();
    }
  }
  else if (status == MAC_TXDONE_CHANNEL_BUSY)
  {
    MAC_ASSERT((macTxType == MAC_TX_TYPE_SLOTTED_CSMA) || (macTxType == MAC_TX_TYPE_UNSLOTTED_CSMA));

    /*  clear channel assement failed, follow through with CSMA algorithm */
    nb++;
    if (nb > macPib.maxCsmaBackoffs)
    {
      txComplete(MAC_CHANNEL_ACCESS_FAILURE);
    }
    else
    {
      macTxBe = MIN(macTxBe+1, macPib.maxBe);
      txCsmaPrep();
      txCsmaGo();
    }
  }
  else
  {
    MAC_ASSERT(status == MAC_TXDONE_INSUFFICIENT_TIME);

    txComplete(MAC_NO_TIME);
  }
}
예제 #2
0
파일: mac_tx.c 프로젝트: LILCMU/WRATIOT
/**************************************************************************************************
 * @fn          macTxDoneCallback
 *
 * @brief       This callback is executed when transmit completes.
 *
 * @param       none
 *
 * @return      none
 **************************************************************************************************
 */
MAC_INTERNAL_API void macTxDoneCallback(void)
{
  halIntState_t  s;

  /*
   *  There is a small chance this function could be called twice for a single transmit.
   *  To prevent logic from executing twice, the state variable macTxActive is used as
   *  a gating mechanism to guarantee single time execution.
   */
  HAL_ENTER_CRITICAL_SECTION(s);
  if (macTxActive == MAC_TX_ACTIVE_GO)
  {
    if (macRxActive)
    {
      /* RX was partly done just before TX. Reset the RX state. */
      macTxCollisionWithRxCallback();
    }
    
    /* see if ACK was requested */
    if (!txAckReq)
    {
      macTxActive = MAC_TX_ACTIVE_DONE;
      HAL_EXIT_CRITICAL_SECTION(s);

      /* ACK was not requested, transmit is complete */
      txComplete(MAC_SUCCESS);
    }
    else
    {
      /*
       *  ACK was requested - must wait to receive it.  A timer is set
       *  to expire after the timeout duration for waiting for an ACK.
       *  If an ACK is received, the function macTxAckReceived() is called.
       *  If an ACK is not received within the timeout period,
       *  the function macTxAckNotReceivedCallback() is called.
       */
      macTxActive = MAC_TX_ACTIVE_LISTEN_FOR_ACK;
      MAC_RADIO_TX_REQUEST_ACK_TIMEOUT_CALLBACK();
      HAL_EXIT_CRITICAL_SECTION(s);
    }
  }
  else
  {
    HAL_EXIT_CRITICAL_SECTION(s);
  }
}