@@ -99,6 +99,7 @@ static int rf_set_channel(uint16_t channel, rf_modules_e module);
9999static int rf_set_ch0_frequency (uint32_t frequency, rf_modules_e module );
100100static int rf_set_channel_spacing (uint32_t channel_spacing, rf_modules_e module );
101101static int rf_set_fsk_symbol_rate_configuration (uint32_t symbol_rate, rf_modules_e module );
102+ static int rf_configure_by_ofdm_bandwidth_option (uint8_t option, uint32_t data_rate, rf_modules_e module );
102103static void rf_calculate_symbol_rate (uint32_t baudrate, phy_modulation_e modulation);
103104static void rf_conf_set_cca_threshold (uint8_t percent);
104105// Defined register read/write functions
@@ -300,6 +301,9 @@ static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_pt
300301 case PHY_EXTENSION_SET_CCA_THRESHOLD:
301302 rf_conf_set_cca_threshold (*data_ptr);
302303 break ;
304+ case PHY_EXTENSION_SET_CHANNEL_CCA_THRESHOLD:
305+ cca_threshold = (int8_t ) *data_ptr; // *NOPAD*
306+ break ;
303307 case PHY_EXTENSION_SET_802_15_4_MODE:
304308 mac_mode = (phy_802_15_4_mode_t ) *data_ptr; // *NOPAD*
305309 if (mac_mode == IEEE_802_15_4_2011) {
@@ -378,7 +382,8 @@ static void rf_init(void)
378382static void rf_init_registers (rf_modules_e module )
379383{
380384 // O-QPSK configuration using IEEE Std 802.15.4-2011
381- // FSK configuration using IEEE Std 802.15.4g-2012
385+ // FSK/OFDM configuration using IEEE Std 802.15.4g-2012
386+ // OFDM configuration is experimental only
382387 if (mac_mode == IEEE_802_15_4_2011) {
383388 device_driver.link_type = PHY_LINK_15_4_2_4GHZ_TYPE;
384389 // 16-bit FCS
@@ -405,40 +410,59 @@ static void rf_init_registers(rf_modules_e module)
405410 rf_write_bbc_register_field (BBC_AFFTM, module , TYPE_2, TYPE_2);
406411 } else if (mac_mode == IEEE_802_15_4G_2012) {
407412 device_driver.link_type = PHY_LINK_15_4_SUBGHZ_TYPE;
408- // Enable FSK
409- rf_write_bbc_register_field (BBC_PC, module , PT, BB_MRFSK);
410413 // Disable auto ack
411414 rf_write_bbc_register_field (BBC_AMCS, module , AACK, 0 );
412415 // Disable address filter unit 0
413416 rf_write_bbc_register_field (BBC_AFC0, module , AFEN0, 0 );
414- // Set bandwidth time product
415- rf_write_bbc_register_field (BBC_FSKC0, module , BT, BT_20);
416- // Disable interleaving
417- rf_write_bbc_register_field (BBC_FSKC2, module , FECIE, 0 );
418- // Disable receiver override
419- rf_write_bbc_register_field (BBC_FSKC2, module , RXO, RXO_DIS);
420- // Set modulation index
421- if (phy_current_config.modulation_index == MODULATION_INDEX_0_5) {
422- rf_write_bbc_register_field (BBC_FSKC0, module , MIDX, MIDX_05);
423- rf_write_rf_register_field (RF_TXDFE, module , RCUT, RCUT_0);
424- } else {
425- rf_write_bbc_register_field (BBC_FSKC0, module , MIDX, MIDX_10);
426- rf_write_rf_register_field (RF_TXDFE, module , RCUT, RCUT_4);
427- }
428- // Set Gain control settings
429- rf_write_rf_register_field (RF_AGCC, module , AVGS, AVGS_8_SAMPLES);
430- rf_write_rf_register_field (RF_AGCS, module , TGT, TGT_1);
431- // Set symbol rate and related configurations
432- rf_set_fsk_symbol_rate_configuration (phy_current_config.datarate , module );
433- // Set preamble length
434- uint8_t preamble_len = 24 ;
435- if (phy_current_config.datarate < 150000 ) {
436- preamble_len = 8 ;
437- } else if (phy_current_config.datarate < 300000 ) {
438- preamble_len = 12 ;
417+ // Enable FSK
418+ if (phy_current_config.modulation == M_2FSK) {
419+ rf_write_bbc_register_field (BBC_PC, module , PT, BB_MRFSK);
420+ // Set bandwidth time product
421+ rf_write_bbc_register_field (BBC_FSKC0, module , BT, BT_20);
422+ // Disable interleaving
423+ rf_write_bbc_register_field (BBC_FSKC2, module , FECIE, 0 );
424+ // Disable receiver override
425+ rf_write_bbc_register_field (BBC_FSKC2, module , RXO, RXO_DIS);
426+ // Set modulation index
427+ if (phy_current_config.modulation_index == MODULATION_INDEX_0_5) {
428+ rf_write_bbc_register_field (BBC_FSKC0, module , MIDX, MIDX_05);
429+ rf_write_rf_register_field (RF_TXDFE, module , RCUT, RCUT_0);
430+ } else {
431+ rf_write_bbc_register_field (BBC_FSKC0, module , MIDX, MIDX_10);
432+ rf_write_rf_register_field (RF_TXDFE, module , RCUT, RCUT_4);
433+ }
434+ // Set Gain control settings
435+ rf_write_rf_register_field (RF_AGCC, module , AVGS, AVGS_8_SAMPLES);
436+ rf_write_rf_register_field (RF_AGCS, module , TGT, TGT_1);
437+ // Set symbol rate and related configurations
438+ rf_set_fsk_symbol_rate_configuration (phy_current_config.datarate , module );
439+ // Set preamble length
440+ uint8_t preamble_len = 24 ;
441+ if (phy_current_config.datarate < 150000 ) {
442+ preamble_len = 8 ;
443+ } else if (phy_current_config.datarate < 300000 ) {
444+ preamble_len = 12 ;
445+ }
446+ rf_write_bbc_register (BBC_FSKPLL, module , preamble_len);
447+ // Set preamble detector threshold
448+ rf_write_bbc_register_field (BBC_FSKC3, module , PDT, PDT_6);
449+ } else if (phy_current_config.modulation == M_OFDM) {
450+ rf_write_bbc_register_field (BBC_PC, module , PT, BB_MROFDM);
451+ // Set TX scrambler seed
452+ rf_write_bbc_register_field (BBC_OFDMC, module , SSTX, SSTX_0);
453+ // Set RX scrambler seed
454+ rf_write_bbc_register_field (BBC_OFDMC, module , SSRX, SSRX_0);
455+ // Set phyOFDMInterleaving
456+ rf_write_bbc_register_field (BBC_OFDMC, module , POI, 0 );
457+ // Set low frequency offset bit
458+ rf_write_bbc_register_field (BBC_OFDMC, module , LFO, 0 );
459+ // Configure using bandwidth option
460+ rf_configure_by_ofdm_bandwidth_option (4 , 300000 , module );
461+ // Set Gain control settings
462+ rf_write_rf_register_field (RF_AGCC, module , AVGS, AVGS_8_SAMPLES);
463+ rf_write_rf_register_field (RF_AGCC, module , AGCI, 0 );
464+ rf_write_rf_register_field (RF_AGCS, module , TGT, TGT_3);
439465 }
440- rf_write_bbc_register (BBC_FSKPLL, module , preamble_len);
441- rf_write_bbc_register_field (BBC_FSKC3, module , PDT, PDT_6);
442466 }
443467 // Disable filtering FCS
444468 rf_write_bbc_register_field (BBC_PC, module , FCSFE, 0 );
@@ -488,9 +512,10 @@ static int8_t rf_start_csma_ca(uint8_t *data_ptr, uint16_t data_length, uint8_t
488512 tx_sequence = *(data_ptr + 2 );
489513 }
490514 rf_write_tx_buffer (data_ptr, data_length, rf_module);
491- if (phy_current_config.modulation == M_OQPSK) {
515+ // Add CRC bytes
516+ if (mac_mode == IEEE_802_15_4_2011) {
492517 data_length += 2 ;
493- } else if (phy_current_config. modulation == M_2FSK) {
518+ } else {
494519 data_length += 4 ;
495520 }
496521 rf_write_tx_packet_length (data_length, rf_module);
@@ -614,9 +639,10 @@ static void rf_handle_rx_done(void)
614639 rf_handle_ack (rx_buffer[2 ], rx_buffer[0 ] & MAC_DATA_PENDING);
615640 } else {
616641 int8_t rssi = (int8_t ) rf_read_rf_register (RF_EDV, rf_module);
617- if (phy_current_config.modulation == M_OQPSK) {
642+ // Cut CRC bytes
643+ if (mac_mode == IEEE_802_15_4_2011) {
618644 cur_rx_packet_len -= 2 ;
619- } else if (phy_current_config. modulation == M_2FSK) {
645+ } else {
620646 cur_rx_packet_len -= 4 ;
621647 }
622648 device_driver.phy_rx_cb (rx_buffer, cur_rx_packet_len, 0xf0 , rssi, rf_radio_driver_id);
@@ -1055,6 +1081,75 @@ static int rf_set_fsk_symbol_rate_configuration(uint32_t symbol_rate, rf_modules
10551081 return 0 ;
10561082}
10571083
1084+ static int rf_configure_by_ofdm_bandwidth_option (uint8_t option, uint32_t data_rate, rf_modules_e module )
1085+ {
1086+ if (!option || option > 4 ) {
1087+ return -1 ;
1088+ }
1089+ uint32_t datarate_tmp = 100000 >> (option - 1 );
1090+
1091+ // Set modulation and coding scheme
1092+ if (data_rate == datarate_tmp) {
1093+ rf_write_bbc_register_field (BBC_OFDMPHRTX, module , MCS, MCS_0);
1094+ } else if (data_rate == datarate_tmp * 2 ) {
1095+ rf_write_bbc_register_field (BBC_OFDMPHRTX, module , MCS, MCS_1);
1096+ } else if (data_rate == datarate_tmp * 4 ) {
1097+ rf_write_bbc_register_field (BBC_OFDMPHRTX, module , MCS, MCS_2);
1098+ } else if (data_rate == datarate_tmp * 8 ) {
1099+ rf_write_bbc_register_field (BBC_OFDMPHRTX, module , MCS, MCS_3);
1100+ } else if (data_rate == datarate_tmp * 12 ) {
1101+ rf_write_bbc_register_field (BBC_OFDMPHRTX, module , MCS, MCS_4);
1102+ } else if (data_rate == datarate_tmp * 16 ) {
1103+ rf_write_bbc_register_field (BBC_OFDMPHRTX, module , MCS, MCS_5);
1104+ } else if (data_rate == datarate_tmp * 24 ) {
1105+ rf_write_bbc_register_field (BBC_OFDMPHRTX, module , MCS, MCS_6);
1106+ } else {
1107+ return -1 ;
1108+ }
1109+ if (option == 1 ) {
1110+ rf_write_bbc_register_field (BBC_OFDMC, module , OPT, OPT_1);
1111+ rf_write_rf_register_field (RF_TXDFE, module , SR, SR_3);
1112+ rf_write_rf_register_field (RF_RXDFE, module , SR, SR_3);
1113+ rf_write_rf_register_field (RF_TXDFE, module , RCUT, RCUT_4);
1114+ rf_write_rf_register_field (RF_RXDFE, module , RCUT, RCUT_4);
1115+ rf_write_rf_register_field (RF_TXCUTC, module , LPFCUT, RF_FLC800KHZ);
1116+ rf_write_rf_register_field (RF_RXBWC, module , BW, RF_BW1250KHZ_IF2000KHZ);
1117+ rf_write_rf_register_field (RF_RXBWC, module , IFS, IFS);
1118+ rf_write_bbc_register_field (BBC_OFDMSW, module , OFDM_PDT, OFDM_PDT_5);
1119+ } else if (option == 2 ) {
1120+ rf_write_bbc_register_field (BBC_OFDMC, module , OPT, OPT_2);
1121+ rf_write_rf_register_field (RF_TXDFE, module , SR, SR_3);
1122+ rf_write_rf_register_field (RF_RXDFE, module , SR, SR_3);
1123+ rf_write_rf_register_field (RF_TXDFE, module , RCUT, RCUT_3);
1124+ rf_write_rf_register_field (RF_RXDFE, module , RCUT, RCUT_2);
1125+ rf_write_rf_register_field (RF_TXCUTC, module , LPFCUT, RF_FLC500KHZ);
1126+ rf_write_rf_register_field (RF_RXBWC, module , BW, RF_BW800KHZ_IF1000KHZ);
1127+ rf_write_rf_register_field (RF_RXBWC, module , IFS, IFS);
1128+ rf_write_bbc_register_field (BBC_OFDMSW, module , OFDM_PDT, OFDM_PDT_5);
1129+ } else if (option == 3 ) {
1130+ rf_write_bbc_register_field (BBC_OFDMC, module , OPT, OPT_3);
1131+ rf_write_rf_register_field (RF_TXDFE, module , SR, SR_6);
1132+ rf_write_rf_register_field (RF_RXDFE, module , SR, SR_6);
1133+ rf_write_rf_register_field (RF_TXDFE, module , RCUT, RCUT_3);
1134+ rf_write_rf_register_field (RF_RXDFE, module , RCUT, RCUT_2);
1135+ rf_write_rf_register_field (RF_TXCUTC, module , LPFCUT, RF_FLC250KHZ);
1136+ rf_write_rf_register_field (RF_RXBWC, module , BW, RF_BW400KHZ_IF500KHZ);
1137+ rf_write_rf_register_field (RF_RXBWC, module , IFS, 0 );
1138+ rf_write_bbc_register_field (BBC_OFDMSW, module , OFDM_PDT, OFDM_PDT_4);
1139+ } else if (option == 4 ) {
1140+ rf_write_bbc_register_field (BBC_OFDMC, module , OPT, OPT_4);
1141+ rf_write_rf_register_field (RF_TXDFE, module , SR, SR_6);
1142+ rf_write_rf_register_field (RF_RXDFE, module , SR, SR_6);
1143+ rf_write_rf_register_field (RF_TXDFE, module , RCUT, RCUT_2);
1144+ rf_write_rf_register_field (RF_RXDFE, module , RCUT, RCUT_1);
1145+ rf_write_rf_register_field (RF_TXCUTC, module , LPFCUT, RF_FLC160KHZ);
1146+ rf_write_rf_register_field (RF_RXBWC, module , BW, RF_BW250KHZ_IF250KHZ);
1147+ rf_write_rf_register_field (RF_RXBWC, module , IFS, 1 );
1148+ rf_write_bbc_register_field (BBC_OFDMSW, module , OFDM_PDT, OFDM_PDT_3);
1149+ }
1150+ return 0 ;
1151+ }
1152+
10581153static void rf_conf_set_cca_threshold (uint8_t percent)
10591154{
10601155 uint8_t step = (MAX_CCA_THRESHOLD - MIN_CCA_THRESHOLD);
0 commit comments