This file implements the TAL state machine and provides general functionality used by the TAL.
Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include "pal.h"
#include "return_val.h"
#include "tal.h"
#include "ieee_const.h"
#include "tal_pib.h"
#include "tal_config.h"
#include "stack_config.h"
#include "bmm.h"
#include "qmm.h"
#include "tal_internal.h"
#include "mac_build_config.h"
Macros | |
#define | AGC_LEG_OQPSK_DEAF_PERIOD 300 |
Functions | |
void | cancel_any_reception (trx_id_t trx_id) |
Cancel any ongoing receive transaction incl. More... | |
static void | handle_trxerr (trx_id_t trx_id) |
Handles a transceiver error. More... | |
void | start_rpc (trx_id_t trx_id) |
SW workaround for errata reference 4841. More... | |
void | stop_rpc (trx_id_t trx_id) |
Stops RPC; SW workaround for errata reference 4841. More... | |
void | stop_tal_timer (trx_id_t trx_id) |
Stops TAL timer. More... | |
void | switch_to_rx (trx_id_t trx_id) |
Switches the transceiver to Rx. More... | |
void | switch_to_txprep (trx_id_t trx_id) |
Switches the transceiver to TxPREP. More... | |
void | tal_task (void) |
TAL task handling. More... | |
void | wait_for_txprep (trx_id_t trx_id) |
Wait to reach TXPREP. More... | |
Variables | |
bool | ack_transmitting [NUM_TRX] |
Flag indicating ongoing ACK transmission. More... | |
frame_info_t * | mac_frame_ptr [NUM_TRX] |
Frame pointer for the frame structure provided by the MCL. More... | |
uint32_t | rxe_txe_tstamp [NUM_TRX] |
Timestamp for end of reception, i.e. More... | |
volatile bb_irq_t | tal_bb_irqs [NUM_TRX] = {BB_IRQ_NO_IRQ, BB_IRQ_NO_IRQ} |
Shadow variable for BB IRQS; variable is filled during TRX ISR, see trx_irq_handler_cb() in tal_irq_handler.c. More... | |
bool | tal_buf_shortage [NUM_TRX] |
Indicates if a buffer shortage issue needs to handled by tal_task(). More... | |
int8_t | tal_current_ed_val [NUM_TRX] |
Last retrieved energy value; variable is filled by handle_ed_end_irq() in tal_ed.c. More... | |
uint8_t * | tal_frame_to_tx [NUM_TRX] |
Pointer to the 15.4 frame created by the TAL to be handed over to the transceiver. More... | |
queue_t | tal_incoming_frame_queue [NUM_TRX] |
Queue that contains all frames that are uploaded from the trx, but have not be processed by the MCL yet. More... | |
tal_pib_t | tal_pib [NUM_TRX] |
TAL PIBs. More... | |
volatile rf_irq_t | tal_rf_irqs [NUM_TRX] = {RF_IRQ_NO_IRQ, RF_IRQ_NO_IRQ} |
Shadow variable for RF IRQS; variable is filled during TRX ISR, see trx_irq_handler_cb() in tal_irq_handler.c. More... | |
buffer_t * | tal_rx_buffer [NUM_TRX] |
Pointer to receive buffer that can be used to upload a frame from the trx. More... | |
tal_state_t | tal_state [NUM_TRX] |
Current state of the TAL state machine. More... | |
const uint8_t | timer_cb_parameter [NUM_TRX] = {RF09, RF24} |
Parameter to handle timer callback functions. More... | |
rf_cmd_state_t | trx_default_state [NUM_TRX] |
Default/Previous trx state while entering a transaction. More... | |
rf_cmd_state_t | trx_state [NUM_TRX] |
Current trx state. More... | |
tx_state_t | tx_state [NUM_TRX] |
Current state of the TX state machine. More... | |
uint8_t | txc [NUM_TRX][2] |
TX calibration values. More... | |
#define AGC_LEG_OQPSK_DEAF_PERIOD 300 |
void cancel_any_reception | ( | trx_id_t | trx_id | ) |
Cancel any ongoing receive transaction incl.
ACK transmission
trx_id | Transceiver identifier |
References ack_transmitting, Assert, ENTER_TRX_REGION, LEAVE_TRX_REGION, NUM_TRX, RF09, RF_TXPREP, RG_BBC0_IRQS, RG_BBC1_IRQS, RG_RF09_IRQS, RG_RF24_IRQS, stop_rpc(), switch_to_txprep(), TAL_BB_IRQ_CLR_ALL, TAL_RF_IRQ_CLR_ALL, trx_reg_read(), and trx_state.
Referenced by transmit_frame().
|
static |
Handles a transceiver error.
This function handles a TRXERR interrupt.
trx_id | Transceiver identifier |
References FAILURE, PHY_RX_ON, RF_BASE_ADDR_OFFSET, RF_RX, RF_TRXOFF, RG_RF09_CMD, stop_ed_scan(), stop_tal_timer(), TAL_ED_SCAN, TAL_IDLE, tal_rx_enable(), tal_state, TAL_TX, trx_default_state, trx_reg_write(), trx_state, tx_done_handling(), TX_IDLE, and tx_state.
Referenced by tal_task().
void start_rpc | ( | trx_id_t | trx_id | ) |
SW workaround for errata reference 4841.
trx_id | Transceiver identifier |
References else, FSK, OQPSK, RF_BASE_ADDR_OFFSET, RG_BBC0_FSKPLL, RG_RF09_PLL, SR_BBC0_FSKC1_FSKPLH, SR_BBC0_FSKRPC_EN, SR_BBC0_OQPSKC2_RPC, SUPPORT_FSK, SUPPORT_OQPSK, tal_pib, trx_bit_write(), and trx_reg_write().
Referenced by conf_trx_modulation(), handle_rx_end_irq(), set_channel(), switch_to_rx(), tal_rx_enable(), and tx_done_handling().
void stop_rpc | ( | trx_id_t | trx_id | ) |
Stops RPC; SW workaround for errata reference 4841.
trx_id | Transceiver identifier |
References FSK, OQPSK, RF_BASE_ADDR_OFFSET, RG_BBC0_FSKPLL, RG_RF09_PLL, SR_BBC0_FSKC1_FSKPLH, SR_BBC0_FSKRPC_EN, SR_BBC0_OQPSKC2_RPC, tal_pib, trx_bit_write(), and trx_reg_write().
Referenced by cancel_any_reception(), conf_trx_modulation(), handle_rx_end_irq(), set_channel(), and tal_rx_enable().
void stop_tal_timer | ( | trx_id_t | trx_id | ) |
Stops TAL timer.
trx_id | Transceiver identifier |
References pal_timer_stop(), RF09, TAL_T_0, and TAL_T_1.
Referenced by cleanup_tal(), handle_incoming_frame(), handle_rx_end_irq(), and handle_trxerr().
void switch_to_rx | ( | trx_id_t | trx_id | ) |
Switches the transceiver to Rx.
This function tries to switch the transceiver to Rx. It checks if a Rx buffer is available. Only if a buffer is available, the receiver is actually switched on. If no buffer is available, the tal_buf_shortage flag is set. This buffer shortage issue is tried to solve within tal_task() again.
trx_id | Transceiver identifier |
References RF_BASE_ADDR_OFFSET, RF_RX, RG_RF09_CMD, start_rpc(), switch_to_txprep(), tal_buf_shortage, trx_reg_write(), and trx_state.
Referenced by ack_transmission_done(), conf_trx_modulation(), handle_ed_end_irq(), handle_incoming_frame(), handle_rx_end_irq(), handle_tx_end_irq(), set_channel(), tal_rx_enable(), tal_task(), tfa_cca_perform(), tfa_continuous_tx_stop(), and tx_done_handling().
void switch_to_txprep | ( | trx_id_t | trx_id | ) |
Switches the transceiver to TxPREP.
This function switches the transceiver to TxPREP and waits until it has has reached this state. Do not call this function within an ISR.
trx_id | Transceiver identifier |
References RF_BASE_ADDR_OFFSET, RF_TXPREP, RG_RF09_CMD, trx_reg_write(), trx_write(), txc, and wait_for_txprep().
Referenced by ack_timout_cb(), cancel_any_reception(), conf_trx_modulation(), handle_tx_end_irq(), set_channel(), set_transceiver_state(), start_backoff(), switch_to_rx(), tal_ed_start(), tal_generate_rand_seed(), tal_rx_enable(), tfa_cca_perform(), tfa_continuous_tx_start(), and tfa_continuous_tx_stop().
void tal_task | ( | void | ) |
TAL task handling.
This function
References BB_IRQ_AGCH, BB_IRQ_AGCR, BB_IRQ_NO_IRQ, BB_IRQ_RXAM, BB_IRQ_RXEM, BB_IRQ_RXFE, BB_IRQ_RXFS, BB_IRQ_TXFE, bmm_buffer_alloc(), ENTER_CRITICAL_REGION, handle_batmon_irq(), handle_ed_end_irq(), handle_rx_end_irq(), handle_trxerr(), handle_tx_end_irq(), LARGE_BUFFER_SIZE, LEAVE_CRITICAL_REGION, NUM_TRX, process_incoming_frame(), qmm_queue_remove(), RF_IRQ_BATLOW, RF_IRQ_EDC, RF_IRQ_IQIFSF, RF_IRQ_TRXERR, RF_IRQ_TRXRDY, RF_IRQ_WAKEUP, switch_to_rx(), TAL_BB_IRQ_CLR, tal_bb_irqs, tal_buf_shortage, TAL_IDLE, TAL_RF_IRQ_CLR, tal_rf_irqs, TAL_SLEEP, tal_state, TX_CCATX, and tx_state.
Referenced by performance_analyzer_task().
void wait_for_txprep | ( | trx_id_t | trx_id | ) |
Wait to reach TXPREP.
trx_id | Transceiver identifier |
References MAX_PLL_LOCK_DURATION, pal_get_current_time(), pal_timer_delay, PLL_FRZ_SETTLING_DURATION, POLL_TIME_GAP, RF_BASE_ADDR_OFFSET, RF_TXPREP, RG_RF09_PLL, RG_RF09_STATE, start_time, trx_reg_read(), trx_reg_write(), and trx_state.
Referenced by switch_to_txprep().
Flag indicating ongoing ACK transmission.
Referenced by ack_transmission_done(), cancel_any_reception(), cca_start(), handle_incoming_frame(), and handle_tx_end_irq().
frame_info_t* mac_frame_ptr[NUM_TRX] |
Frame pointer for the frame structure provided by the MCL.
Referenced by is_ack_valid(), tal_tx_frame(), transmit_frame(), and tx_done_handling().
uint32_t rxe_txe_tstamp[NUM_TRX] |
Timestamp for end of reception, i.e.
RXFE IRQ; used during Rx transaction to calculate ACK transmission time. Timestamp for end of transmission; used during Tx transaction to calculate ACK timeout. Both scenarios use the same variable
Referenced by handle_ifs(), handle_tx_end_irq(), and trx_irq_handler_cb().
volatile bb_irq_t tal_bb_irqs[NUM_TRX] = {BB_IRQ_NO_IRQ, BB_IRQ_NO_IRQ} |
Shadow variable for BB IRQS; variable is filled during TRX ISR, see trx_irq_handler_cb() in tal_irq_handler.c.
Referenced by tal_task(), and trx_irq_handler_cb().
Indicates if a buffer shortage issue needs to handled by tal_task().
Referenced by cleanup_tal(), switch_to_rx(), tal_rx_enable(), tal_task(), and tal_trx_sleep().
int8_t tal_current_ed_val[NUM_TRX] |
Last retrieved energy value; variable is filled by handle_ed_end_irq() in tal_ed.c.
Referenced by handle_ed_end_irq(), and tfa_cca_perform().
uint8_t* tal_frame_to_tx[NUM_TRX] |
Pointer to the 15.4 frame created by the TAL to be handed over to the transceiver.
Referenced by tal_tx_frame().
Queue that contains all frames that are uploaded from the trx, but have not be processed by the MCL yet.
Referenced by cleanup_tal(), complete_rx_transaction(), init_after_disconnect(), and tal_init().
TAL PIBs.
Referenced by ack_timout_cb(), ack_transmission_done(), app_transmit_frame(), apply_channel_settings(), calc_ch_page(), calculate_cca_duration_us(), calculate_pib_values(), cca_start(), ceiling_sym(), check_valid_freq_range(), complete_rx_transaction(), conf_fsk(), conf_leg_oqpsk(), conf_ofdm(), conf_oqpsk(), conf_trx_modulation(), config_fsk_rpc(), config_phy(), configure_frame_sending(), configure_pibs(), configure_range_test_frame_sending(), continue_deferred_transmission(), csma_continue(), csma_start(), fsk_rfcfg(), get_AckTiming_us(), get_AckWaitDuration_us(), get_board_details(), get_cca_duration_us(), get_cca_thres(), get_data_rate(), get_node_info(), get_sun_max_ch_no(), get_supported_channels_tuple(), handle_ed_end_irq(), handle_ifs(), handle_incoming_frame(), handle_incoming_msg(), handle_rx_end_irq(), handle_tx_end_irq(), init_tal_pib(), ofdm_rfcfg(), oqpsk_ack_psdu_duration_sym(), oqpsk_get_chip_rate(), oqpsk_rfcfg(), per_mode_initiator_rx_cb(), per_mode_initiator_task(), per_mode_initiator_tx_done_cb(), per_mode_receptor_rx_cb(), perf_set_sun_page(), phr_duration_sym(), process_incoming_frame(), send_peer_conf(), set_channel(), set_channel_app(), set_fsk_pibs(), set_phy_based_on_channel_page(), set_phy_frame_length(), set_sfd(), set_tx_pwr(), shr_duration_sym(), start_ack_wait_timer(), start_backoff(), start_rpc(), stop_rpc(), tal_ed_start(), tal_get_symbol_duration_us(), tal_init(), tal_pib_get(), tal_pib_set(), tal_set_tx_pwr(), tal_tx_frame(), tfa_cca_perform(), tfa_continuous_tx_start(), transmit_frame(), tx_done_handling(), upload_frame(), usr_range_test_beacon_rsp(), usr_range_test_beacon_tx(), usr_range_test_marker_ind(), and write_all_tal_pib_to_trx().
volatile rf_irq_t tal_rf_irqs[NUM_TRX] = {RF_IRQ_NO_IRQ, RF_IRQ_NO_IRQ} |
Shadow variable for RF IRQS; variable is filled during TRX ISR, see trx_irq_handler_cb() in tal_irq_handler.c.
Referenced by tal_task(), and trx_irq_handler_cb().
Pointer to receive buffer that can be used to upload a frame from the trx.
Referenced by cleanup_tal(), complete_rx_transaction(), init_after_disconnect(), tal_init(), tal_trx_sleep(), tal_trx_wakeup(), and upload_frame().
tal_state_t tal_state[NUM_TRX] |
Current state of the TAL state machine.
Referenced by handle_ed_end_irq(), handle_rx_end_irq(), handle_trxerr(), init_after_disconnect(), tal_ed_start(), tal_generate_rand_seed(), tal_get_trx_status(), tal_init(), tal_pib_set(), tal_reset(), tal_rx_enable(), tal_task(), tal_trx_sleep(), tal_trx_wakeup(), tal_tx_frame(), tfa_cca_perform(), tfa_continuous_tx_start(), tfa_continuous_tx_stop(), tfa_get_batmon_voltage(), trx_irq_handler_cb(), trx_reset(), and tx_done_handling().
Parameter to handle timer callback functions.
rf_cmd_state_t trx_default_state[NUM_TRX] |
Default/Previous trx state while entering a transaction.
Referenced by handle_ed_end_irq(), handle_trxerr(), start_backoff(), tal_ed_start(), tal_pib_set(), tal_rx_enable(), and tx_done_handling().
rf_cmd_state_t trx_state[NUM_TRX] |
Current trx state.
Referenced by apply_channel_settings(), cancel_any_reception(), cca_start(), conf_trx_modulation(), handle_incoming_frame(), handle_rx_end_irq(), handle_trxerr(), handle_tx_end_irq(), set_channel(), set_transceiver_state(), start_ack_wait_timer(), start_backoff(), switch_to_rx(), tal_ed_start(), tal_generate_rand_seed(), tal_reset(), tal_rx_enable(), tal_trx_sleep(), tal_trx_wakeup(), tfa_cca_perform(), tfa_continuous_tx_start(), tfa_continuous_tx_stop(), transmit_frame(), trx_reset(), tx_done_handling(), and wait_for_txprep().
tx_state_t tx_state[NUM_TRX] |
Current state of the TX state machine.
Referenced by ack_transmission_done(), handle_ed_end_irq(), handle_incoming_frame(), handle_rx_end_irq(), handle_trxerr(), handle_tx_end_irq(), start_ack_wait_timer(), start_backoff(), tal_init(), tal_reset(), tal_task(), transmit_frame(), and tx_done_handling().
uint8_t txc[NUM_TRX][2] |
TX calibration values.
Referenced by switch_to_txprep().