/** * @brief Finalizes the CSMA procedure * * @param status Result of the slotted transmission */ static void tx_done(retval_t status) { #if (DEBUG > 0) switch (tal_state) { case TAL_SLOTTED_CSMA: /* That's the state we are expecting */ break; default: ASSERT("unexpected tal_state" == 0); break; } #endif #if (DEBUG > 0) if (pal_is_timer_running(TAL_CSMA_BEACON_LOSS_TIMER)) { ASSERT("beacon lost timer is still running" == 0); } #endif tal_state = TAL_IDLE; tal_csma_state = CSMA_IDLE; /* debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */ PIN_CSMA_END(); tal_tx_frame_done_cb(status, mac_frame_ptr); }
/** * \brief Finalizes the CSMA procedure * * \param status Result of the slotted transmission */ static void tx_done(retval_t status) { #if (_DEBUG_ > 0) switch (tal_state) { case TAL_SLOTTED_CSMA: case TAL_TX_BASIC: break; #if ((MAC_START_REQUEST_CONFIRM == 1) && (defined BEACON_SUPPORT)) case TAL_TX_BEACON: Assert("unexpected tal_state TAL_TX_BEACON" == 0); return; /* break; */ #endif /* ((MAC_START_REQUEST_CONFIRM == 1) && (defined BEACON_SUPPORT)) */ default: Assert("unexpected tal_state" == 0); break; } #endif #if (_DEBUG_ > 0) if (pal_is_timer_running(TAL_CSMA_BEACON_LOSS_TIMER)) { Assert("beacon lost timer is still running" == 0); } #endif tal_state = TAL_IDLE; tal_csma_state = CSMA_IDLE; /* * Restore the interrupt handler. * Install a handler for the transceiver interrupt. */ pal_trx_irq_init((FUNC_PTR)trx_irq_handler_cb); pal_trx_reg_read(RG_IRQ_STATUS); /* Check if a receive buffer is available. */ if (NULL != tal_rx_buffer) { pal_trx_reg_write(RG_TRX_STATE, CMD_RX_AACK_ON); } else { tal_rx_on_required = true; } pal_trx_irq_en(); /* debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */ PIN_CSMA_END(); tal_tx_frame_done_cb(status, mac_frame_ptr); }
/* * \brief Implements the handling of the transmission end. * * This function handles the callback for the transmission end. */ void tx_done_handling(void) { tal_state = TAL_IDLE; #if (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP) /* * The entire timestamp calculation is only required for beaconing * networks * or if timestamping is explicitly enabled. */ mac_frame_ptr->time_stamp = pal_tx_timestamp; #endif /* #if (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP) */ retval_t status; switch (trx_trac_status) { case TRAC_SUCCESS: status = MAC_SUCCESS; break; case TRAC_SUCCESS_DATA_PENDING: status = TAL_FRAME_PENDING; break; case TRAC_CHANNEL_ACCESS_FAILURE: status = MAC_CHANNEL_ACCESS_FAILURE; break; case TRAC_NO_ACK: status = MAC_NO_ACK; break; case TRAC_INVALID: status = FAILURE; break; default: Assert("Unexpected tal_tx_state" == 0); status = FAILURE; break; } #ifdef ENABLE_RTB rtb_tx_frame_done_cb(status, mac_frame_ptr); #else /* Regular handling without RTB */ tal_tx_frame_done_cb(status, mac_frame_ptr); #endif } /* tx_done_handling() */
/* * \brief Implements the handling of the transmission end. * * This function handles the callback for the transmission end. */ void tx_done_handling(void) { tal_state = TAL_IDLE; #if (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP) /* * The entire timestamp calculation is only required for beaconing *networks * or if timestamping is explicitly enabled. */ /* Calculate negative offset of timestamp */ uint16_t offset; /* Calculate the tx time */ offset = TAL_CONVERT_SYMBOLS_TO_US( (PHY_OVERHEAD + LENGTH_FIELD_LEN) * SYMBOLS_PER_OCTET) + TAL_PSDU_US_PER_OCTET(*tal_frame_to_tx + FCS_LEN) + IRQ_PROCESSING_DLY_US; if (mac_frame_ptr->mpdu[PL_POS_FCF_1] & FCF_ACK_REQUEST) { /* Tx timestamp needs to be reduced by ACK duration etc. */ offset += TAL_CONVERT_SYMBOLS_TO_US( (PHY_OVERHEAD + LENGTH_FIELD_LEN) * SYMBOLS_PER_OCTET) + TAL_PSDU_US_PER_OCTET(ACK_PAYLOAD_LEN + FCS_LEN); #ifdef HIGH_DATA_RATE_SUPPORT if (tal_pib.CurrentPage == 0) { offset += TAL_CONVERT_SYMBOLS_TO_US(aTurnaroundTime); } else { offset += 32; } #else offset += TAL_CONVERT_SYMBOLS_TO_US(aTurnaroundTime); #endif /* #ifdef HIGH_DATA_RATE_SUPPORT */ } mac_frame_ptr->time_stamp -= offset; #endif /* #if (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP) */ retval_t status; switch (trx_trac_status) { case TRAC_SUCCESS: status = MAC_SUCCESS; break; case TRAC_SUCCESS_DATA_PENDING: status = TAL_FRAME_PENDING; break; case TRAC_CHANNEL_ACCESS_FAILURE: status = MAC_CHANNEL_ACCESS_FAILURE; break; case TRAC_NO_ACK: status = MAC_NO_ACK; break; case TRAC_INVALID: status = FAILURE; break; default: Assert("Unexpected tal_tx_state" == 0); status = FAILURE; break; } tal_tx_frame_done_cb(status, mac_frame_ptr); } /* tx_done_handling() */
/* * \brief Implements the TAL tx state machine. * * This function implements the TAL tx state machine. */ void tx_state_handling(void) { tal_tx_sub_state_t tx_sub_state = (tal_tx_sub_state_t)(tal_state & TAL_TX_SUB_STATE_MASK); switch (tal_state & TAL_MAIN_STATE_MASK) { case TAL_TX_AUTO: switch (tx_sub_state) { case TAL_TX_FRAME_PENDING: tal_state = TAL_IDLE; tal_tx_frame_done_cb(TAL_FRAME_PENDING, mac_frame_ptr); break; case TAL_TX_SUCCESS: tal_state = TAL_IDLE; tal_tx_frame_done_cb(MAC_SUCCESS, mac_frame_ptr); break; case TAL_TX_ACCESS_FAILURE: tal_state = TAL_IDLE; tal_tx_frame_done_cb(MAC_CHANNEL_ACCESS_FAILURE, mac_frame_ptr); break; case TAL_TX_NO_ACK: tal_state = TAL_IDLE; tal_tx_frame_done_cb(MAC_NO_ACK, mac_frame_ptr); break; case TAL_TX_FAILURE: tal_state = TAL_IDLE; tal_tx_frame_done_cb(FAILURE, mac_frame_ptr); break; default: break; } break; case TAL_TX_BASIC: switch (tx_sub_state) { case TAL_TX_SUCCESS: tal_state = TAL_IDLE; tal_tx_frame_done_cb(MAC_SUCCESS, mac_frame_ptr); break; default: break; } break; #if ((MAC_START_REQUEST_CONFIRM == 1) && (defined BEACON_SUPPORT)) case TAL_TX_BEACON: switch (tx_sub_state) { case TAL_TX_SUCCESS: if (tal_csma_state == BACKOFF_WAITING_FOR_BEACON) { tal_csma_state = CSMA_HANDLE_BEACON; tal_state = TAL_SLOTTED_CSMA; } else { tal_state = TAL_IDLE; } break; default: break; } break; #endif /* ((MAC_START_REQUEST_CONFIRM == 1) && (defined BEACON_SUPPORT)) */ } } /* tx_state_handling() */
/* * \brief Implements the handling of the transmission end. * * This function handles the callback for the transmission end. */ void tx_done_handling(void) { tal_state = TAL_IDLE; #if (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP) #if (DISABLE_TSTAMP_IRQ == 0) /* * The Tx timestamp IRQ is enabled and provided via DIG2. * The actual value is stored within trx_irq_timestamp_handler_cb(); * see file "tal_irq_handler.c". * The value gets stored into the mac_frame_ptr structure during the * tx end interrupt; see handle_tx_end_irq(). * So, here is nothing left to do. */ #else /* (DISABLE_TSTAMP_IRQ == 1) */ /* * The entire timestamp calculation is only required for beaconing networks * or if timestamping is explicitly enabled. */ /* Calculate negative offset of timestamp */ uint16_t offset; /* Calculate the tx time */ offset = TAL_CONVERT_SYMBOLS_TO_US((PHY_OVERHEAD + LENGTH_FIELD_LEN) * SYMBOLS_PER_OCTET) + TAL_PSDU_US_PER_OCTET(*tal_frame_to_tx + FCS_LEN) + TRX_IRQ_DELAY_US; if (mac_frame_ptr->mpdu[PL_POS_FCF_1] & FCF_ACK_REQUEST) { /* Tx timestamp needs to be reduced by ACK duration etc. */ offset += TAL_CONVERT_SYMBOLS_TO_US((PHY_OVERHEAD + LENGTH_FIELD_LEN) * SYMBOLS_PER_OCTET) + TAL_PSDU_US_PER_OCTET(ACK_PAYLOAD_LEN + FCS_LEN); offset += TAL_CONVERT_SYMBOLS_TO_US(aTurnaroundTime); } mac_frame_ptr->time_stamp -= offset; #endif /* #if (DISABLE_TSTAMP_IRQ == 0) */ #endif /* #if (defined BEACON_SUPPORT) || (defined ENABLE_TSTAMP) */ retval_t status; switch (trx_trac_status) { case TRAC_SUCCESS: status = MAC_SUCCESS; break; case TRAC_SUCCESS_DATA_PENDING: status = TAL_FRAME_PENDING; break; case TRAC_CHANNEL_ACCESS_FAILURE: status = MAC_CHANNEL_ACCESS_FAILURE; break; case TRAC_NO_ACK: status = MAC_NO_ACK; break; case TRAC_INVALID: status = FAILURE; break; default: Assert("Unexpected tal_tx_state" == 0); status = FAILURE; break; } tal_tx_frame_done_cb(status, mac_frame_ptr); } /* tx_done_handling() */