Skip to content

Commit 61315d1

Browse files
author
Arto Kinnunen
committed
Squashed 'connectivity/drivers/802.15.4_RF/atmel-rf-driver/' changes from ae4ef1b197..b1a8186d75
b1a8186d75 Merge pull request ARMmbed#105 from PelionIoT/sync_with_mbed_os 4b24dd04f0 Allow builds with Mbed OS version less than 6.0 81666bd114 Replace calls to deprecated functions in the Timer API c1b436b1f7 Merge pull request ARMmbed#104 from PelionIoT/IOTTHD-4408 6cd27661c0 Use given OFDM configuration 292da06289 Merge pull request ARMmbed#102 from ARMmbed/IOTTHD-4320 079dfa7dd8 Atmel & PA: Output power at 900MHz: -4 dBm with FSK/QPSK, less than -10 dBm with OFDM git-subtree-dir: connectivity/drivers/802.15.4_RF/atmel-rf-driver git-subtree-split: b1a8186d7571fb49e048bb91910cc18c17861bda
1 parent 6e89573 commit 61315d1

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

source/AT86RF215Reg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extern "C" {
9696

9797
// RF_PAC
9898
#define TXPWR 0x1F
99+
#define TXPWR_7 (7 << 0)
99100
#define TXPWR_11 (11 << 0)
100101
#define TXPWR_0 (0 << 0)
101102
#define TXPWR_31 (31 << 0)

source/NanostackRfPhyAT86RF215.cpp

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,24 @@
3030
#include <Timer.h>
3131
#include "Timeout.h"
3232
#include "SPI.h"
33+
#include "platform/mbed_version.h"
3334

3435
#define TRACE_GROUP "AtRF"
3536

37+
#if (MBED_VERSION > MBED_ENCODE_VERSION(6, 0, 0))
38+
/* Mbed OS 6.0 introduces support for chrono time management */
39+
using namespace std::chrono_literals;
40+
#define ATMEL_RF_TIME_65MS 65ms
41+
#define ATMEL_RF_TIME_1US 1us
42+
#define ATMEL_RF_ATTACH(timer_ref, signal_ref, timeout_ref) timer_ref.attach(signal_ref, timeout_ref)
43+
#define ATMEL_RF_DRIVER_CHRONO_SUPPORTED
44+
#else
45+
#define ATMEL_RF_TIME_65MS 65000
46+
#define ATMEL_RF_TIME_1US 1
47+
48+
#define ATMEL_RF_ATTACH(timer_ref, signal_ref, timeout_ref) timer_ref.attach_us(signal_ref, timeout_ref)
49+
#endif
50+
3651
#define RF_MTU_15_4_2011 127
3752
#define RF_MTU_15_4G_2012 2047
3853

@@ -196,7 +211,11 @@ static Se2435Pins *se2435_pa_pins = NULL;
196211

197212
static uint32_t rf_get_timestamp(void)
198213
{
214+
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
215+
return (uint32_t)rf->tx_timer.elapsed_time().count();
216+
#else
199217
return (uint32_t)rf->tx_timer.read_us();
218+
#endif
200219
}
201220

202221
static void rf_lock(void)
@@ -485,7 +504,7 @@ static void rf_init_registers(rf_modules_e module)
485504
// Set low frequency offset bit
486505
rf_write_bbc_register_field(BBC_OFDMC, module, LFO, 0);
487506
// Configure using bandwidth option
488-
rf_configure_by_ofdm_bandwidth_option(4, 300000, module);
507+
rf_configure_by_ofdm_bandwidth_option(phy_current_config.ofdm_option, phy_current_config.datarate, module);
489508
// Set Gain control settings
490509
rf_write_rf_register_field(RF_AGCC, module, AVGS, AVGS_8_SAMPLES);
491510
rf_write_rf_register_field(RF_AGCC, module, AGCI, 0);
@@ -499,8 +518,8 @@ static void rf_init_registers(rf_modules_e module)
499518
se2435_pa_pins->ANT_SEL = 0;
500519
// Enable external front end with configuration 3
501520
rf_write_rf_register_field(RF_PADFE, module, PADFE, RF_FEMODE3);
502-
// Output power at 900MHz: 0 dBm with FSK/QPSK, less than -5 dBm with OFDM
503-
rf_tx_power = TXPWR_11;
521+
// Output power at 900MHz: -4 dBm with FSK/QPSK, less than -10 dBm with OFDM
522+
rf_tx_power = TXPWR_7;
504523
}
505524
// Set TX output power
506525
rf_write_rf_register_field(RF_PAC, module, TXPWR, rf_tx_power);
@@ -564,17 +583,21 @@ static int8_t rf_start_csma_ca(uint8_t *data_ptr, uint16_t data_length, uint8_t
564583
mac_tx_handle = tx_handle;
565584

566585
if (tx_time) {
586+
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
587+
std::chrono::microseconds backoff_time(tx_time - rf_get_timestamp());
588+
#else
567589
uint32_t backoff_time = tx_time - rf_get_timestamp();
590+
#endif
568591
// Max. time to TX can be 65ms, otherwise time has passed already -> send immediately
569-
if (backoff_time <= 65000) {
570-
rf->cca_timer.attach_us(rf_csma_ca_timer_signal, backoff_time);
592+
if (backoff_time <= ATMEL_RF_TIME_65MS) {
593+
ATMEL_RF_ATTACH(rf->cca_timer, rf_csma_ca_timer_signal, backoff_time);
571594
TEST_CSMA_STARTED
572595
rf_unlock();
573596
return 0;
574597
}
575598
}
576599
// Short timeout to start CCA immediately.
577-
rf->cca_timer.attach_us(rf_csma_ca_timer_signal, 1);
600+
ATMEL_RF_ATTACH(rf->cca_timer, rf_csma_ca_timer_signal, ATMEL_RF_TIME_1US);
578601
TEST_CSMA_STARTED
579602
rf_unlock();
580603
return 0;
@@ -607,12 +630,16 @@ static void rf_handle_cca_ed_done(void)
607630
if (cca_prepare_status == PHY_RESTART_CSMA) {
608631
device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, PHY_LINK_CCA_OK, 0, 0);
609632
if (tx_time) {
633+
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
634+
std::chrono::microseconds backoff_time(tx_time - rf_get_timestamp());
635+
#else
610636
uint32_t backoff_time = tx_time - rf_get_timestamp();
637+
#endif
611638
// Max. time to TX can be 65ms, otherwise time has passed already -> send immediately
612-
if (backoff_time > 65000) {
613-
backoff_time = 1;
639+
if (backoff_time > ATMEL_RF_TIME_65MS) {
640+
backoff_time = ATMEL_RF_TIME_1US;
614641
}
615-
rf->cca_timer.attach_us(rf_csma_ca_timer_signal, backoff_time);
642+
ATMEL_RF_ATTACH(rf->cca_timer, rf_csma_ca_timer_signal, backoff_time);
616643
TEST_CSMA_STARTED
617644
}
618645
return;
@@ -994,7 +1021,11 @@ static uint32_t rf_backup_timer_start(uint16_t bytes, uint32_t time_us)
9941021
time_us = (uint32_t)(8000000 / phy_current_config.datarate) * bytes + PACKET_PROCESSING_TIME;
9951022
}
9961023
// Using cal_timer as backup timer
1024+
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
1025+
rf->cal_timer.attach(rf_backup_timer_signal, std::chrono::microseconds(time_us));
1026+
#else
9971027
rf->cal_timer.attach_us(rf_backup_timer_signal, time_us);
1028+
#endif
9981029

9991030
return (rf_get_timestamp() + time_us);
10001031
}

0 commit comments

Comments
 (0)