@@ -103,6 +103,7 @@ static int rf_set_fsk_symbol_rate_configuration(uint32_t symbol_rate, rf_modules
103103static int rf_configure_by_ofdm_bandwidth_option (uint8_t option, uint32_t data_rate, rf_modules_e module );
104104static void rf_calculate_symbol_rate (uint32_t baudrate, phy_modulation_e modulation);
105105static void rf_conf_set_cca_threshold (uint8_t percent);
106+ static bool rf_conf_set_tx_power (uint8_t percent);
106107// Defined register read/write functions
107108#define rf_read_bbc_register (x, y ) rf_read_rf_register(x, (rf_modules_e)(y + 2 ))
108109#define rf_read_common_register (x ) rf_read_rf_register(x, COMMON)
@@ -134,7 +135,10 @@ static uint8_t bbc0_irq_mask = 0;
134135static uint8_t bbc1_irq_mask = 0 ;
135136
136137static bool rf_update_config = false ;
138+ static bool rf_update_tx_power = false ;
137139static int8_t cca_threshold = -80 ;
140+ static uint8_t rf_tx_power = TXPWR_31;
141+ static bool data_whitening_enabled = true ;
138142static bool cca_enabled = true ;
139143static uint32_t rf_symbol_rate;
140144
@@ -303,9 +307,25 @@ static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_pt
303307 case PHY_EXTENSION_SET_CCA_THRESHOLD:
304308 rf_conf_set_cca_threshold (*data_ptr);
305309 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 ;
306319 case PHY_EXTENSION_SET_CHANNEL_CCA_THRESHOLD:
307320 cca_threshold = (int8_t ) *data_ptr; // *NOPAD*
308321 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 ;
309329 case PHY_EXTENSION_SET_802_15_4_MODE:
310330 mac_mode = (phy_802_15_4_mode_t ) *data_ptr; // *NOPAD*
311331 if (mac_mode == IEEE_802_15_4_2011) {
@@ -418,6 +438,12 @@ static void rf_init_registers(rf_modules_e module)
418438 rf_write_bbc_register_field (BBC_AFC0, module , AFEN0, 0 );
419439 // Enable FSK
420440 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+ }
421447 rf_write_bbc_register_field (BBC_PC, module , PT, BB_MRFSK);
422448 // Set bandwidth time product
423449 rf_write_bbc_register_field (BBC_FSKC0, module , BT, BT_20);
@@ -474,8 +500,10 @@ static void rf_init_registers(rf_modules_e module)
474500 // Enable external front end with configuration 3
475501 rf_write_rf_register_field (RF_PADFE, module , PADFE, RF_FEMODE3);
476502 // 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;
478504 }
505+ // Set TX output power
506+ rf_write_rf_register_field (RF_PAC, module , TXPWR, rf_tx_power);
479507 // Enable analog voltage regulator
480508 rf_write_rf_register_field (RF_AUXS, module , AVEN, AVEN);
481509 // Disable filtering FCS
@@ -695,7 +723,7 @@ static void rf_handle_rx_start(void)
695723
696724static void rf_receive (uint16_t rx_channel, rf_modules_e module )
697725{
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)) {
699727 return ;
700728 }
701729 TEST_RX_DONE
@@ -706,6 +734,12 @@ static void rf_receive(uint16_t rx_channel, rf_modules_e module)
706734 rf_init_registers (module );
707735 rf_change_state (RF_TXPREP, module );
708736 }
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+ }
709743 if (rx_channel != rf_rx_channel) {
710744 rf_change_state (RF_TXPREP, module );
711745 rf_set_channel (rx_channel, module );
@@ -1170,6 +1204,17 @@ static void rf_conf_set_cca_threshold(uint8_t percent)
11701204 cca_threshold = MIN_CCA_THRESHOLD + (step * percent) / 100 ;
11711205}
11721206
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+
11731218static void rf_calculate_symbol_rate (uint32_t baudrate, phy_modulation_e modulation)
11741219{
11751220 uint8_t bits_in_symbols = 4 ;
0 commit comments