/** * @brief Handles interrupts issued due to end of transmission */ void handle_tx_end_irq(bool underrun_occured) { uint8_t trac_status; if (tal_state == TAL_TX_AUTO) { if (underrun_occured) { trac_status = TRAC_INVALID; } else { trac_status = pal_trx_bit_read(SR_TRAC_STATUS); } /* Map status message of transceiver to TAL constants. */ switch (trac_status) { case TRAC_SUCCESS_DATA_PENDING: tal_state |= TAL_TX_FRAME_PENDING; break; case TRAC_SUCCESS: tal_state |= TAL_TX_SUCCESS; break; case TRAC_CHANNEL_ACCESS_FAILURE: tal_state |= TAL_TX_ACCESS_FAILURE; break; case TRAC_NO_ACK: tal_state |= TAL_TX_NO_ACK; break; case TRAC_INVALID: tal_state |= TAL_TX_FAILURE; break; default: ASSERT("not handled trac status" == 0); tal_state |= TAL_TX_FAILURE; break; } } else if (tal_state == TAL_TX_BASIC) { tal_state |= TAL_TX_SUCCESS; } #if ((MAC_START_REQUEST_CONFIRM == 1) && (defined BEACON_SUPPORT)) else // TAL_TX_BEACON { // debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h PIN_BEACON_END(); tal_state |= TAL_TX_SUCCESS; } #endif /* ((MAC_START_REQUEST_CONFIRM == 1) && (defined BEACON_SUPPORT)) */ }
/* * \brief Parses received frame and create the frame_info_t structure * * This function parses the received frame and creates the frame_info_t * structure to be sent to the MAC as a parameter of tal_rx_frame_cb(). * * \param buf Pointer to the buffer containing the received frame */ void process_incoming_frame(buffer_t *buf_ptr) { #ifndef TRX_REG_RAW_VALUE uint8_t frame_len; uint8_t *frame_ptr; uint8_t ed_level; uint8_t lqi; #endif frame_info_t *receive_frame = (frame_info_t *)BMM_BUFFER_POINTER(buf_ptr); /* The frame is present towards the end of the buffer. */ #ifndef TRX_REG_RAW_VALUE /* * Store the last frame length for IFS handling. * Substract LQI and length fields. */ frame_len = last_frame_length = receive_frame->mpdu[0]; #else last_frame_length = receive_frame->mpdu[0]; #endif #ifdef PROMISCUOUS_MODE if (tal_pib.PromiscuousMode) { #ifndef TRX_REG_RAW_VALUE frame_ptr = &(receive_frame->mpdu[frame_len + LQI_LEN]); /* * The LQI is stored after the FCS. * The ED value is stored after the LQI. */ lqi = *frame_ptr++; ed_level = *frame_ptr; /* * The LQI normalization is done using the ED level measured during * the frame reception. */ #ifdef RSSI_TO_LQI_MAPPING lqi = normalize_lqi(ed_level); #else lqi = normalize_lqi(lqi, ed_level); #endif /* Store normalized LQI value again. */ frame_ptr--; *frame_ptr = lqi; #endif /* #ifndef TRX_REG_RAW_VALUE */ receive_frame->buffer_header = buf_ptr; /* The callback function implemented by MAC is invoked. */ tal_rx_frame_cb(receive_frame); return; } #endif /* #ifdef PROMISCUOUS_MODE */ #ifdef BEACON_SUPPORT /* * Are we waiting for a beacon for slotted CSMA? * Check if received frame is a beacon. */ if ((receive_frame->mpdu[PL_POS_FCF_1] & FCF_FRAMETYPE_MASK) == FCF_FRAMETYPE_BEACON) { /* Debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */ PIN_BEACON_START(); if (tal_csma_state == BACKOFF_WAITING_FOR_BEACON) { /* Debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */ PIN_WAITING_FOR_BEACON_END(); tal_pib.BeaconTxTime = TAL_CONVERT_US_TO_SYMBOLS(receive_frame->time_stamp); tal_csma_state = CSMA_HANDLE_BEACON; } /* Debug pin to switch on: define ENABLE_DEBUG_PINS, pal_config.h */ PIN_BEACON_END(); } #endif /* BEACON_SUPPORT */ #ifndef TRX_REG_RAW_VALUE /* * The LQI is stored after the FCS. * The ED value is stored after the LQI. */ frame_ptr = &(receive_frame->mpdu[frame_len + LQI_LEN]); lqi = *frame_ptr++; ed_level = *frame_ptr; /* * The LQI normalization is done using the ED level measured during * the frame reception. */ #ifdef RSSI_TO_LQI_MAPPING lqi = normalize_lqi(ed_level); #else lqi = normalize_lqi(lqi, ed_level); #endif /* Store normalized LQI value again. */ frame_ptr--; *frame_ptr = lqi; #endif /* #ifndef TRX_REG_RAW_VALUE */ receive_frame->buffer_header = buf_ptr; #ifdef ENABLE_RTB /* The callback function implemented by RTB is invoked. */ rtb_rx_frame_cb(receive_frame); #else /* The callback function implemented by MAC is invoked. */ tal_rx_frame_cb(receive_frame); #endif } /* process_incoming_frame() */