@@ -103,6 +103,7 @@ static int rf_set_fsk_symbol_rate_configuration(uint32_t symbol_rate, rf_modules
103
103
static int rf_configure_by_ofdm_bandwidth_option (uint8_t option, uint32_t data_rate, rf_modules_e module );
104
104
static void rf_calculate_symbol_rate (uint32_t baudrate, phy_modulation_e modulation);
105
105
static void rf_conf_set_cca_threshold (uint8_t percent);
106
+ static bool rf_conf_set_tx_power (uint8_t percent);
106
107
// Defined register read/write functions
107
108
#define rf_read_bbc_register (x, y ) rf_read_rf_register(x, (rf_modules_e)(y + 2 ))
108
109
#define rf_read_common_register (x ) rf_read_rf_register(x, COMMON)
@@ -134,7 +135,10 @@ static uint8_t bbc0_irq_mask = 0;
134
135
static uint8_t bbc1_irq_mask = 0 ;
135
136
136
137
static bool rf_update_config = false ;
138
+ static bool rf_update_tx_power = false ;
137
139
static int8_t cca_threshold = -80 ;
140
+ static uint8_t rf_tx_power = TXPWR_31;
141
+ static bool data_whitening_enabled = true ;
138
142
static bool cca_enabled = true ;
139
143
static uint32_t rf_symbol_rate;
140
144
@@ -303,9 +307,25 @@ static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_pt
303
307
case PHY_EXTENSION_SET_CCA_THRESHOLD:
304
308
rf_conf_set_cca_threshold (*data_ptr);
305
309
break ;
310
+ case PHY_EXTENSION_SET_TX_POWER:
311
+ if (*data_ptr > 100 ) {
312
+ return -1 ;
313
+ }
314
+ rf_update_tx_power = rf_conf_set_tx_power (*data_ptr);
315
+ if (rf_update_tx_power && (rf_state == RF_IDLE)) {
316
+ rf_receive (rf_rx_channel, rf_module);
317
+ }
318
+ break ;
306
319
case PHY_EXTENSION_SET_CHANNEL_CCA_THRESHOLD:
307
320
cca_threshold = (int8_t ) *data_ptr; // *NOPAD*
308
321
break ;
322
+ case PHY_EXTENSION_SET_DATA_WHITENING:
323
+ data_whitening_enabled = (bool ) *data_ptr; // *NOPAD*
324
+ rf_update_config = true ;
325
+ if (rf_state == RF_IDLE) {
326
+ rf_receive (rf_rx_channel, rf_module);
327
+ }
328
+ break ;
309
329
case PHY_EXTENSION_SET_802_15_4_MODE:
310
330
mac_mode = (phy_802_15_4_mode_t ) *data_ptr; // *NOPAD*
311
331
if (mac_mode == IEEE_802_15_4_2011) {
@@ -418,6 +438,12 @@ static void rf_init_registers(rf_modules_e module)
418
438
rf_write_bbc_register_field (BBC_AFC0, module , AFEN0, 0 );
419
439
// Enable FSK
420
440
if (phy_current_config.modulation == M_2FSK) {
441
+ // Enable or disable data whitening
442
+ if (data_whitening_enabled) {
443
+ rf_write_bbc_register_field (BBC_FSKPHRTX, module , DW, DW);
444
+ } else {
445
+ rf_write_bbc_register_field (BBC_FSKPHRTX, module , DW, 0 );
446
+ }
421
447
rf_write_bbc_register_field (BBC_PC, module , PT, BB_MRFSK);
422
448
// Set bandwidth time product
423
449
rf_write_bbc_register_field (BBC_FSKC0, module , BT, BT_20);
@@ -474,8 +500,10 @@ static void rf_init_registers(rf_modules_e module)
474
500
// Enable external front end with configuration 3
475
501
rf_write_rf_register_field (RF_PADFE, module , PADFE, RF_FEMODE3);
476
502
// Output power at 900MHz: 0 dBm with FSK/QPSK, less than -5 dBm with OFDM
477
- rf_write_rf_register_field (RF_PAC, module , TXPWR, TXPWR_11) ;
503
+ rf_tx_power = TXPWR_11;
478
504
}
505
+ // Set TX output power
506
+ rf_write_rf_register_field (RF_PAC, module , TXPWR, rf_tx_power);
479
507
// Enable analog voltage regulator
480
508
rf_write_rf_register_field (RF_AUXS, module , AVEN, AVEN);
481
509
// Disable filtering FCS
@@ -695,7 +723,7 @@ static void rf_handle_rx_start(void)
695
723
696
724
static void rf_receive (uint16_t rx_channel, rf_modules_e module )
697
725
{
698
- if ((receiver_enabled == true ) && (rf_update_config == false ) && (rx_channel == rf_rx_channel)) {
726
+ if ((receiver_enabled == true ) && (rf_update_config == false ) && (rf_update_tx_power == false ) && ( rx_channel == rf_rx_channel)) {
699
727
return ;
700
728
}
701
729
TEST_RX_DONE
@@ -706,6 +734,12 @@ static void rf_receive(uint16_t rx_channel, rf_modules_e module)
706
734
rf_init_registers (module );
707
735
rf_change_state (RF_TXPREP, module );
708
736
}
737
+ if (rf_update_tx_power == true ) {
738
+ rf_update_tx_power = false ;
739
+ rf_change_state (RF_TRX_OFF, module );
740
+ rf_write_rf_register_field (RF_PAC, module , TXPWR, rf_tx_power);
741
+ rf_change_state (RF_TXPREP, module );
742
+ }
709
743
if (rx_channel != rf_rx_channel) {
710
744
rf_change_state (RF_TXPREP, module );
711
745
rf_set_channel (rx_channel, module );
@@ -1170,6 +1204,17 @@ static void rf_conf_set_cca_threshold(uint8_t percent)
1170
1204
cca_threshold = MIN_CCA_THRESHOLD + (step * percent) / 100 ;
1171
1205
}
1172
1206
1207
+ static bool rf_conf_set_tx_power (uint8_t percent)
1208
+ {
1209
+ uint8_t step = (TXPWR_31 - TXPWR_0);
1210
+ uint8_t new_value = TXPWR_0 + (step * percent) / 100 ;
1211
+ if (rf_tx_power != new_value) {
1212
+ rf_tx_power = new_value;
1213
+ return true ;
1214
+ }
1215
+ return false ;
1216
+ }
1217
+
1173
1218
static void rf_calculate_symbol_rate (uint32_t baudrate, phy_modulation_e modulation)
1174
1219
{
1175
1220
uint8_t bits_in_symbols = 4 ;
0 commit comments