30
30
#include < Timer.h>
31
31
#include " Timeout.h"
32
32
#include " SPI.h"
33
+ #include " platform/mbed_version.h"
33
34
34
35
#define TRACE_GROUP " AtRF"
35
36
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
+
36
51
#define RF_MTU_15_4_2011 127
37
52
#define RF_MTU_15_4G_2012 2047
38
53
@@ -164,8 +179,6 @@ static const phy_device_channel_page_s phy_channel_pages[] = {
164
179
{ CHANNEL_PAGE_0, NULL }
165
180
};
166
181
167
- using namespace std ::chrono_literals;
168
-
169
182
using namespace mbed ;
170
183
using namespace rtos ;
171
184
@@ -198,7 +211,11 @@ static Se2435Pins *se2435_pa_pins = NULL;
198
211
199
212
static uint32_t rf_get_timestamp (void )
200
213
{
214
+ #ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
201
215
return (uint32_t )rf->tx_timer .elapsed_time ().count ();
216
+ #else
217
+ return (uint32_t )rf->tx_timer .read_us ();
218
+ #endif
202
219
}
203
220
204
221
static void rf_lock (void )
@@ -487,7 +504,7 @@ static void rf_init_registers(rf_modules_e module)
487
504
// Set low frequency offset bit
488
505
rf_write_bbc_register_field (BBC_OFDMC, module , LFO, 0 );
489
506
// Configure using bandwidth option
490
- 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 );
491
508
// Set Gain control settings
492
509
rf_write_rf_register_field (RF_AGCC, module , AVGS, AVGS_8_SAMPLES);
493
510
rf_write_rf_register_field (RF_AGCC, module , AGCI, 0 );
@@ -501,8 +518,8 @@ static void rf_init_registers(rf_modules_e module)
501
518
se2435_pa_pins->ANT_SEL = 0 ;
502
519
// Enable external front end with configuration 3
503
520
rf_write_rf_register_field (RF_PADFE, module , PADFE, RF_FEMODE3);
504
- // Output power at 900MHz: 0 dBm with FSK/QPSK, less than -5 dBm with OFDM
505
- 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 ;
506
523
}
507
524
// Set TX output power
508
525
rf_write_rf_register_field (RF_PAC, module , TXPWR, rf_tx_power);
@@ -566,17 +583,21 @@ static int8_t rf_start_csma_ca(uint8_t *data_ptr, uint16_t data_length, uint8_t
566
583
mac_tx_handle = tx_handle;
567
584
568
585
if (tx_time) {
586
+ #ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
569
587
std::chrono::microseconds backoff_time (tx_time - rf_get_timestamp ());
588
+ #else
589
+ uint32_t backoff_time = tx_time - rf_get_timestamp ();
590
+ #endif
570
591
// Max. time to TX can be 65ms, otherwise time has passed already -> send immediately
571
- if (backoff_time <= 65ms ) {
572
- rf->cca_timer . attach ( 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);
573
594
TEST_CSMA_STARTED
574
595
rf_unlock ();
575
596
return 0 ;
576
597
}
577
598
}
578
599
// Short timeout to start CCA immediately.
579
- rf->cca_timer . attach ( rf_csma_ca_timer_signal, 1us );
600
+ ATMEL_RF_ATTACH ( rf->cca_timer , rf_csma_ca_timer_signal, ATMEL_RF_TIME_1US );
580
601
TEST_CSMA_STARTED
581
602
rf_unlock ();
582
603
return 0 ;
@@ -609,12 +630,16 @@ static void rf_handle_cca_ed_done(void)
609
630
if (cca_prepare_status == PHY_RESTART_CSMA) {
610
631
device_driver.phy_tx_done_cb (rf_radio_driver_id, mac_tx_handle, PHY_LINK_CCA_OK, 0 , 0 );
611
632
if (tx_time) {
633
+ #ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
612
634
std::chrono::microseconds backoff_time (tx_time - rf_get_timestamp ());
635
+ #else
636
+ uint32_t backoff_time = tx_time - rf_get_timestamp ();
637
+ #endif
613
638
// Max. time to TX can be 65ms, otherwise time has passed already -> send immediately
614
- if (backoff_time > 65ms ) {
615
- backoff_time = 1us ;
639
+ if (backoff_time > ATMEL_RF_TIME_65MS ) {
640
+ backoff_time = ATMEL_RF_TIME_1US ;
616
641
}
617
- rf->cca_timer . attach ( rf_csma_ca_timer_signal, backoff_time);
642
+ ATMEL_RF_ATTACH ( rf->cca_timer , rf_csma_ca_timer_signal, backoff_time);
618
643
TEST_CSMA_STARTED
619
644
}
620
645
return ;
@@ -996,7 +1021,11 @@ static uint32_t rf_backup_timer_start(uint16_t bytes, uint32_t time_us)
996
1021
time_us = (uint32_t )(8000000 / phy_current_config.datarate ) * bytes + PACKET_PROCESSING_TIME;
997
1022
}
998
1023
// Using cal_timer as backup timer
1024
+ #ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
999
1025
rf->cal_timer .attach (rf_backup_timer_signal, std::chrono::microseconds (time_us));
1026
+ #else
1027
+ rf->cal_timer .attach_us (rf_backup_timer_signal, time_us);
1028
+ #endif
1000
1029
1001
1030
return (rf_get_timestamp () + time_us);
1002
1031
}
0 commit comments