Microchip® Advanced Software Framework

tal_ed.c File Reference

This file implements ED scan.

Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "pal.h"
#include "return_val.h"
#include "tal.h"
#include "ieee_const.h"
#include "tal_config.h"
#include "tal_internal.h"
#include "mac_build_config.h"

Macros

#define LOWER_ED_LIMIT   -100
 
#define UPPER_ED_LIMIT   -30
 Values used for ED scaling in dBm. More...
 

Functions

void handle_ed_end_irq (trx_id_t trx_id)
 Handles ED scan end interrupt. More...
 
uint8_t scale_ed_value (int8_t ed)
 Scale ED value. More...
 
void set_ed_sample_duration (trx_id_t trx_id, uint16_t sample_duration_us)
 Sets the energy measurement duration. More...
 
void stop_ed_scan (trx_id_t trx_id)
 Stops ED Scan. More...
 
retval_t tal_ed_start (trx_id_t trx_id, uint8_t scan_duration)
 Starts ED Scan. More...
 

Variables

static int8_t max_ed_level [NUM_TRX]
 The peak_ed_level is the maximum ED value received from the transceiver for the specified Scan Duration. More...
 
static uint32_t sampler_counter [NUM_TRX]
 

#define LOWER_ED_LIMIT   -100

Referenced by scale_ed_value().

#define UPPER_ED_LIMIT   -30

Values used for ED scaling in dBm.

Referenced by scale_ed_value().

void handle_ed_end_irq ( trx_id_t  trx_id)
uint8_t scale_ed_value ( int8_t  ed)

Scale ED value.

This function scales the trx ED value to the range 0x00 - 0xFF.

Parameters
edRF215 register value EDV.
Returns
Scaled ED value

References LOWER_ED_LIMIT, and UPPER_ED_LIMIT.

Referenced by process_incoming_frame().

void set_ed_sample_duration ( trx_id_t  trx_id,
uint16_t  sample_duration_us 
)

Sets the energy measurement duration.

Parameters
trx_idTransceiver identifier
sample_duration_usSample duration in us

References RF_BASE_ADDR_OFFSET, RG_RF09_EDD, and trx_reg_write().

Referenced by config_phy(), handle_ed_end_irq(), tal_ed_start(), and tal_pib_set().

void stop_ed_scan ( trx_id_t  trx_id)

Stops ED Scan.

This function stops an ED Scan and completes it by calling tal_ed_end_cb().

Parameters
trx_idTransceiver identifier

References handle_ed_end_irq(), RF_BASE_ADDR_OFFSET, RF_EDAUTO, RF_IRQ_EDC, sampler_counter, SR_RF09_EDC_EDM, TAL_RF_IRQ_CLR, and trx_bit_write().

Referenced by handle_trxerr().

retval_t tal_ed_start ( trx_id_t  trx_id,
uint8_t  scan_duration 
)

Starts ED Scan.

This function starts an ED Scan for the scan duration specified by the MAC layer. The result is returned from the TAL by calling tal_ed_end_cb().

Parameters
trx_idTransceiver identifier
scan_durationSpecifies the ED scan duration in superframe duration
Returns
MAC_SUCCESS - ED scan duration timer started successfully TAL_BUSY - TAL is busy servicing the previous request from MAC TAL_TRX_ASLEEP - Transceiver is currently sleeping FAILURE otherwise

References aBaseSuperframeDuration, Assert, ED_SAMPLE_DURATION_SYM, MAC_SUCCESS, max_ed_level, NUM_TRX, pal_timer_delay, RF_BASE_ADDR_OFFSET, RF_EDCONT, RF_RX, RF_TXPREP, RG_RF09_CMD, sampler_counter, scan_duration, set_ed_sample_duration(), SR_BBC0_PC_BBEN, SR_RF09_AGCC_FRZC, SR_RF09_EDC_EDM, SR_RF09_IRQM_EDC, switch_to_txprep(), TAL_BUSY, TAL_ED_SCAN, TAL_IDLE, tal_pib, TAL_SLEEP, tal_state, TAL_TRX_ASLEEP, trx_bit_write(), trx_default_state, trx_reg_write(), and trx_state.

Referenced by per_mode_initiator_ed_end_cb(), and start_ed_scan().

int8_t max_ed_level[NUM_TRX]
static

The peak_ed_level is the maximum ED value received from the transceiver for the specified Scan Duration.

Referenced by handle_ed_end_irq(), and tal_ed_start().

uint32_t sampler_counter[NUM_TRX]
static