/** * @brief Start CCA. * * @param parameter Pointer to trx_id */ static void cca_start(void *parameter) { trx_id_t trx_id = *(trx_id_t *)parameter; /* Check if trx is currently detecting a frame ota */ if (trx_state[trx_id] == RF_RX) { uint16_t reg_offset = RF_BASE_ADDR_OFFSET * trx_id; uint8_t agc_freeze = trx_bit_read(reg_offset + SR_RF09_AGCC_FRZS); if (agc_freeze) { csma_continue(trx_id); } else { #ifdef SUPPORT_MODE_SWITCH if (tal_pib[trx_id].ModeSwitchEnabled) { trigger_cca_meaurement(trx_id); } else #endif { transmit_frame(trx_id, WITH_CCA); } } } else { #ifdef SUPPORT_MODE_SWITCH if (tal_pib[trx_id].ModeSwitchEnabled) { trigger_cca_meaurement(trx_id); } else #endif { transmit_frame(trx_id, WITH_CCA); } } }
/** * @brief Callback function for CCA completion. * * @param trx_id Transceiver identifier */ void cca_done_handling(trx_id_t trx_id) { switch_to_txprep(trx_id); /* Leave state Rx */ /* Switch BB on again */ uint16_t reg_offset = RF_BASE_ADDR_OFFSET * trx_id; trx_bit_write(reg_offset + SR_BBC0_PC_BBEN, 1); /* Determine if channel is idle */ if (tal_current_ed_val[trx_id] < tal_pib[trx_id].CCAThreshold) { /* Idle */ tx_ms_ppdu(trx_id); } else { /* Busy */ csma_continue(trx_id); } }
/* * \brief TAL task handling * * This function * - Checks and allocates the receive buffer. * - Processes the TAL incoming frame queue. * - Implements the TAL state machine. */ void tal_task(void) { /* Check if the receiver needs to be switched on. */ if (tal_rx_on_required && (tal_state == TAL_IDLE)) { /* Check if a receive buffer has not been available before. */ if (tal_rx_buffer == NULL) { tal_rx_buffer = bmm_buffer_alloc(LARGE_BUFFER_SIZE); } /* Check if buffer could be allocated */ if (NULL != tal_rx_buffer) { /* * Note: * This flag needs to be reset BEFORE the received is * switched on. */ tal_rx_on_required = false; #ifdef PROMISCUOUS_MODE if (tal_pib.PromiscuousMode) { set_trx_state(CMD_RX_ON); } else { set_trx_state(CMD_RX_AACK_ON); } #else /* Normal operation */ set_trx_state(CMD_RX_AACK_ON); #endif } } else { /* no free buffer is available; try next time again */ } /* * If the transceiver has received a frame and it has been placed * into the queue of the TAL, the frame needs to be processed further. */ if (tal_incoming_frame_queue.size > 0) { buffer_t *rx_frame; /* Check if there are any pending data in the * incoming_frame_queue. */ rx_frame = qmm_queue_remove(&tal_incoming_frame_queue, NULL); if (NULL != rx_frame) { process_incoming_frame(rx_frame); } } /* Handle the TAL state machines */ switch (tal_state) { case TAL_IDLE: /* Do nothing, but fall through... */ case TAL_TX_AUTO: /* Wait until state is changed to TAL_TX_DONE inside tx end ISR **/ break; #ifdef SW_CONTROLLED_CSMA case TAL_BACKOFF: /* Do nothing, but fall through... */ case TAL_CCA: /* Do nothing */ break; case TAL_CSMA_CONTINUE: csma_continue(); break; case TAL_CCA_DONE: cca_done_handling(); break; #endif case TAL_TX_DONE: tx_done_handling(); /* see tal_tx.c */ break; #ifdef BEACON_SUPPORT case TAL_SLOTTED_CSMA: slotted_csma_state_handling(); /* see tal_slotted_csma.c */ break; #endif /* BEACON_SUPPORT */ #if (MAC_SCAN_ED_REQUEST_CONFIRM == 1) case TAL_ED_RUNNING: /* Do nothing here. Wait until ED is completed. */ break; case TAL_ED_DONE: ed_scan_done(); break; #endif /* (MAC_SCAN_ED_REQUEST_CONFIRM == 1) */ default: Assert("tal_state is not handled" == 0); break; } } /* tal_task() */