Skip to content

Commit 45d1c68

Browse files
author
Jarkko Paso
committed
S2-LP: Sync with development repository
1 parent 421ad37 commit 45d1c68

File tree

4 files changed

+48
-139
lines changed

4 files changed

+48
-139
lines changed

components/802.15.4_RF/stm-s2lp-rf-driver/source/NanostackRfPhys2lp.cpp

Lines changed: 36 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ RFPins::RFPins(PinName spi_sdi, PinName spi_sdo,
172172
static uint8_t rf_read_register(uint8_t addr);
173173
static s2lp_states_e rf_read_state(void);
174174
static void rf_write_register(uint8_t addr, uint8_t data);
175-
static void rf_print_registers(void);
176175
static void rf_interrupt_handler(void);
177176
static void rf_receive(uint8_t rx_channel);
178177
static void rf_cca_timer_stop(void);
@@ -211,6 +210,8 @@ static bool rf_update_config = false;
211210
static uint16_t cur_packet_len = 0xffff;
212211
static uint32_t receiver_ready_timestamp;
213212

213+
static int16_t rssi_threshold = RSSI_THRESHOLD;
214+
214215
/* Channel configurations for sub-GHz */
215216
static phy_rf_channel_configuration_s phy_subghz = {
216217
.channel_0_center_frequency = 868300000U,
@@ -501,6 +502,10 @@ static uint32_t read_irq_status(void)
501502

502503
static void rf_set_channel_configuration_registers(void)
503504
{
505+
// Set RSSI threshold
506+
uint8_t rssi_th;
507+
rf_conf_calculate_rssi_threshold_registers(rssi_threshold, &rssi_th);
508+
rf_write_register(RSSI_TH, rssi_th);
504509
// Set deviation
505510
uint32_t deviation = rf_conf_calculate_deviation(phy_subghz.modulation_index, phy_subghz.datarate);
506511
if (!deviation) {
@@ -557,10 +562,6 @@ static void rf_init_registers(void)
557562
rf_write_register_field(QI, SQI_EN_FIELD, SQI_EN);
558563
rf_write_register(SYNC0, SFD0);
559564
rf_write_register(SYNC1, SFD1);
560-
// Set RSSI threshold
561-
uint8_t rssi_th;
562-
rf_conf_calculate_rssi_threshold_registers(RSSI_THRESHOLD, &rssi_th);
563-
rf_write_register(RSSI_TH, rssi_th);
564565
rf_set_channel_configuration_registers();
565566
}
566567

@@ -666,6 +667,16 @@ static int8_t rf_extension(phy_extension_type_e extension_type, uint8_t *data_pt
666667
rf_receive(rf_rx_channel);
667668
}
668669
break;
670+
case PHY_EXTENSION_SET_TX_POWER:
671+
// TODO: Set TX output power
672+
break;
673+
case PHY_EXTENSION_SET_CCA_THRESHOLD:
674+
rssi_threshold = rf_conf_cca_threshold_percent_to_rssi(*data_ptr);
675+
rf_update_config = true;
676+
if (rf_state == RF_IDLE) {
677+
rf_receive(rf_rx_channel);
678+
}
679+
break;
669680
default:
670681
break;
671682
}
@@ -683,6 +694,14 @@ static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_
683694
break;
684695
/*Disable PHY Interface driver*/
685696
case PHY_INTERFACE_DOWN:
697+
rf_lock();
698+
rf_send_command(S2LP_CMD_SABORT);
699+
rf_disable_all_interrupts();
700+
rf_poll_state_change(S2LP_STATE_READY);
701+
rf_flush_rx_fifo();
702+
rf_flush_tx_fifo();
703+
rf_state = RF_IDLE;
704+
rf_unlock();
686705
break;
687706
/*Enable PHY Interface driver*/
688707
case PHY_INTERFACE_UP:
@@ -810,6 +829,15 @@ static void rf_cca_timer_start(uint32_t slots)
810829
static void rf_backup_timer_interrupt(void)
811830
{
812831
tx_finnish_time = rf_get_timestamp();
832+
if (rf_state == RF_RX_STARTED) {
833+
if (device_driver.phy_rf_statistics) {
834+
device_driver.phy_rf_statistics->rx_timeouts++;
835+
}
836+
} else {
837+
if (device_driver.phy_rf_statistics) {
838+
device_driver.phy_rf_statistics->tx_timeouts++;
839+
}
840+
}
813841
if (rf_state == RF_TX_STARTED) {
814842
if (device_driver.phy_tx_done_cb) {
815843
device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, PHY_LINK_TX_SUCCESS, 0, 0);
@@ -1054,6 +1082,9 @@ static void rf_irq_task_process_irq(void)
10541082
rf_state = RF_IDLE;
10551083
// In case the channel change was called during reception, driver is responsible to change the channel if CRC failed.
10561084
rf_receive(rf_new_channel);
1085+
if (device_driver.phy_rf_statistics) {
1086+
device_driver.phy_rf_statistics->crc_fails++;
1087+
}
10571088
}
10581089
}
10591090
if ((irq_status & (1 << RX_FIFO_ALMOST_FULL)) && (enabled_interrupts & (1 << RX_FIFO_ALMOST_FULL))) {
@@ -1103,7 +1134,6 @@ static void rf_init(void)
11031134
rf_enable_gpio_interrupt();
11041135
rf_calculate_symbol_rate(phy_subghz.datarate, phy_subghz.modulation);
11051136
rf->tx_timer.start();
1106-
rf_print_registers();
11071137
}
11081138

11091139
static int8_t rf_device_register(const uint8_t *mac_addr)
@@ -1199,7 +1229,6 @@ int8_t NanostackRfPhys2lp::rf_register()
11991229
s2lp_MAC[0] &= ~1; //Clear multicast bit
12001230
#endif
12011231
set_mac_address(s2lp_MAC);
1202-
tr_info("MAC address: %s", trace_array(_mac_addr, 8));
12031232
}
12041233

12051234
rf = _rf;
@@ -1349,137 +1378,6 @@ static bool rf_rx_filter(uint8_t *mac_header, uint8_t *mac_64bit_addr, uint8_t *
13491378
return true;
13501379
}
13511380

1352-
static void rf_print_registers(void)
1353-
{
1354-
tr_debug("GPIO0_CONF: %x", rf_read_register(GPIO0_CONF));
1355-
tr_debug("GPIO1_CONF: %x", rf_read_register(GPIO1_CONF));
1356-
tr_debug("GPIO2_CONF: %x", rf_read_register(GPIO2_CONF));
1357-
tr_debug("GPIO3_CONF: %x", rf_read_register(GPIO3_CONF));
1358-
tr_debug("SYNT3: %x", rf_read_register(SYNT3));
1359-
tr_debug("SYNT2: %x", rf_read_register(SYNT2));
1360-
tr_debug("SYNT1: %x", rf_read_register(SYNT1));
1361-
tr_debug("SYNT0: %x", rf_read_register(SYNT0));
1362-
tr_debug("IF_OFFSET_ANA: %x", rf_read_register(IF_OFFSET_ANA));
1363-
tr_debug("IF_OFFSET_DIG: %x", rf_read_register(IF_OFFSET_DIG));
1364-
tr_debug("CHSPACE: %x", rf_read_register(CHSPACE));
1365-
tr_debug("CHNUM: %x", rf_read_register(CHNUM));
1366-
tr_debug("MOD4: %x", rf_read_register(MOD4));
1367-
tr_debug("MOD3: %x", rf_read_register(MOD3));
1368-
tr_debug("MOD2: %x", rf_read_register(MOD2));
1369-
tr_debug("MOD1: %x", rf_read_register(MOD1));
1370-
tr_debug("MOD0: %x", rf_read_register(MOD0));
1371-
tr_debug("CHFLT: %x", rf_read_register(CHFLT));
1372-
tr_debug("AFC2: %x", rf_read_register(AFC2));
1373-
tr_debug("AFC1: %x", rf_read_register(AFC1));
1374-
tr_debug("AFC0: %x", rf_read_register(AFC0));
1375-
tr_debug("RSSI_FLT: %x", rf_read_register(RSSI_FLT));
1376-
tr_debug("RSSI_TH: %x", rf_read_register(RSSI_TH));
1377-
tr_debug("AGCCTRL4: %x", rf_read_register(AGCCTRL4));
1378-
tr_debug("AGCCTRL3: %x", rf_read_register(AGCCTRL3));
1379-
tr_debug("AGCCTRL2: %x", rf_read_register(AGCCTRL2));
1380-
tr_debug("AGCCTRL1: %x", rf_read_register(AGCCTRL1));
1381-
tr_debug("AGCCTRL0: %x", rf_read_register(AGCCTRL0));
1382-
tr_debug("ANT_SELECT_CONF: %x", rf_read_register(ANT_SELECT_CONF));
1383-
tr_debug("CLOCKREC2: %x", rf_read_register(CLOCKREC2));
1384-
tr_debug("CLOCKREC1: %x", rf_read_register(CLOCKREC1));
1385-
tr_debug("PCKTCTRL6: %x", rf_read_register(PCKTCTRL6));
1386-
tr_debug("PCKTCTRL5: %x", rf_read_register(PCKTCTRL5));
1387-
tr_debug("PCKTCTRL4: %x", rf_read_register(PCKTCTRL4));
1388-
tr_debug("PCKTCTRL3: %x", rf_read_register(PCKTCTRL3));
1389-
tr_debug("PCKTCTRL2: %x", rf_read_register(PCKTCTRL2));
1390-
tr_debug("PCKTCTRL1: %x", rf_read_register(PCKTCTRL1));
1391-
tr_debug("PCKTLEN1: %x", rf_read_register(PCKTLEN1));
1392-
tr_debug("PCKTLEN0: %x", rf_read_register(PCKTLEN0));
1393-
tr_debug("SYNC3: %x", rf_read_register(SYNC3));
1394-
tr_debug("SYNC2: %x", rf_read_register(SYNC2));
1395-
tr_debug("SYNC1: %x", rf_read_register(SYNC1));
1396-
tr_debug("SYNC0: %x", rf_read_register(SYNC0));
1397-
tr_debug("QI: %x", rf_read_register(QI));
1398-
tr_debug("PCKT_PSTMBL: %x", rf_read_register(PCKT_PSTMBL));
1399-
tr_debug("PROTOCOL2: %x", rf_read_register(PROTOCOL2));
1400-
tr_debug("PROTOCOL1: %x", rf_read_register(PROTOCOL1));
1401-
tr_debug("PROTOCOL0: %x", rf_read_register(PROTOCOL0));
1402-
tr_debug("FIFO_CONFIG3: %x", rf_read_register(FIFO_CONFIG3));
1403-
tr_debug("FIFO_CONFIG2: %x", rf_read_register(FIFO_CONFIG2));
1404-
tr_debug("FIFO_CONFIG1: %x", rf_read_register(FIFO_CONFIG1));
1405-
tr_debug("FIFO_CONFIG0: %x", rf_read_register(FIFO_CONFIG0));
1406-
tr_debug("PCKT_FLT_OPTIONS: %x", rf_read_register(PCKT_FLT_OPTIONS));
1407-
tr_debug("PCKT_FLT_GOALS4: %x", rf_read_register(PCKT_FLT_GOALS4));
1408-
tr_debug("PCKT_FLT_GOALS3: %x", rf_read_register(PCKT_FLT_GOALS3));
1409-
tr_debug("PCKT_FLT_GOALS2: %x", rf_read_register(PCKT_FLT_GOALS2));
1410-
tr_debug("PCKT_FLT_GOALS1: %x", rf_read_register(PCKT_FLT_GOALS1));
1411-
tr_debug("PCKT_FLT_GOALS0: %x", rf_read_register(PCKT_FLT_GOALS0));
1412-
tr_debug("TIMERS5: %x", rf_read_register(TIMERS5));
1413-
tr_debug("TIMERS4: %x", rf_read_register(TIMERS4));
1414-
tr_debug("TIMERS3: %x", rf_read_register(TIMERS3));
1415-
tr_debug("TIMERS2: %x", rf_read_register(TIMERS2));
1416-
tr_debug("TIMERS1: %x", rf_read_register(TIMERS1));
1417-
tr_debug("TIMERS0: %x", rf_read_register(TIMERS0));
1418-
tr_debug("CSMA_CONF3: %x", rf_read_register(CSMA_CONF3));
1419-
tr_debug("CSMA_CONF2: %x", rf_read_register(CSMA_CONF2));
1420-
tr_debug("CSMA_CONF1: %x", rf_read_register(CSMA_CONF1));
1421-
tr_debug("CSMA_CONF0: %x", rf_read_register(CSMA_CONF0));
1422-
tr_debug("IRQ_MASK3: %x", rf_read_register(IRQ_MASK3));
1423-
tr_debug("IRQ_MASK2: %x", rf_read_register(IRQ_MASK2));
1424-
tr_debug("IRQ_MASK1: %x", rf_read_register(IRQ_MASK1));
1425-
tr_debug("IRQ_MASK0: %x", rf_read_register(IRQ_MASK0));
1426-
tr_debug("FAST_RX_TIMER: %x", rf_read_register(FAST_RX_TIMER));
1427-
tr_debug("PA_POWER8: %x", rf_read_register(PA_POWER8));
1428-
tr_debug("PA_POWER7: %x", rf_read_register(PA_POWER7));
1429-
tr_debug("PA_POWER6: %x", rf_read_register(PA_POWER6));
1430-
tr_debug("PA_POWER5: %x", rf_read_register(PA_POWER5));
1431-
tr_debug("PA_POWER4: %x", rf_read_register(PA_POWER4));
1432-
tr_debug("PA_POWER3: %x", rf_read_register(PA_POWER3));
1433-
tr_debug("PA_POWER2: %x", rf_read_register(PA_POWER2));
1434-
tr_debug("PA_POWER1: %x", rf_read_register(PA_POWER1));
1435-
tr_debug("PA_POWER0: %x", rf_read_register(PA_POWER0));
1436-
tr_debug("PA_CONFIG1: %x", rf_read_register(PA_CONFIG1));
1437-
tr_debug("PA_CONFIG0: %x", rf_read_register(PA_CONFIG0));
1438-
tr_debug("SYNTH_CONFIG2: %x", rf_read_register(SYNTH_CONFIG2));
1439-
tr_debug("VCO_CONFIG: %x", rf_read_register(VCO_CONFIG));
1440-
tr_debug("VCO_CALIBR_IN2: %x", rf_read_register(VCO_CALIBR_IN2));
1441-
tr_debug("VCO_CALIBR_IN1: %x", rf_read_register(VCO_CALIBR_IN1));
1442-
tr_debug("VCO_CALIBR_IN0: %x", rf_read_register(VCO_CALIBR_IN0));
1443-
tr_debug("XO_RCO_CONF1: %x", rf_read_register(XO_RCO_CONF1));
1444-
tr_debug("XO_RCO_CONF0: %x", rf_read_register(XO_RCO_CONF0));
1445-
tr_debug("RCO_CALIBR_CONF3: %x", rf_read_register(RCO_CALIBR_CONF3));
1446-
tr_debug("RCO_CALIBR_CONF2: %x", rf_read_register(RCO_CALIBR_CONF2));
1447-
tr_debug("PM_CONF4: %x", rf_read_register(PM_CONF4));
1448-
tr_debug("PM_CONF3: %x", rf_read_register(PM_CONF3));
1449-
tr_debug("PM_CONF2: %x", rf_read_register(PM_CONF2));
1450-
tr_debug("PM_CONF1: %x", rf_read_register(PM_CONF1));
1451-
tr_debug("PM_CONF0: %x", rf_read_register(PM_CONF0));
1452-
tr_debug("MC_STATE1: %x", rf_read_register(MC_STATE1));
1453-
tr_debug("MC_STATE0: %x", rf_read_register(MC_STATE0));
1454-
tr_debug("TX_FIFO_STATUS: %x", rf_read_register(TX_FIFO_STATUS));
1455-
tr_debug("RX_FIFO_STATUS: %x", rf_read_register(RX_FIFO_STATUS));
1456-
tr_debug("RCO_CALIBR_OUT4: %x", rf_read_register(RCO_CALIBR_OUT4));
1457-
tr_debug("RCO_CALIBR_OUT3: %x", rf_read_register(RCO_CALIBR_OUT3));
1458-
tr_debug("VCO_CALIBR_OUT1: %x", rf_read_register(VCO_CALIBR_OUT1));
1459-
tr_debug("VCO_CALIBR_OUT0: %x", rf_read_register(VCO_CALIBR_OUT0));
1460-
tr_debug("TX_PCKT_INFO: %x", rf_read_register(TX_PCKT_INFO));
1461-
tr_debug("RX_PCKT_INFO: %x", rf_read_register(RX_PCKT_INFO));
1462-
tr_debug("AFC_CORR: %x", rf_read_register(AFC_CORR));
1463-
tr_debug("LINK_QUALIF2: %x", rf_read_register(LINK_QUALIF2));
1464-
tr_debug("LINK_QUALIF1: %x", rf_read_register(LINK_QUALIF1));
1465-
tr_debug("RSSI_LEVEL: %x", rf_read_register(RSSI_LEVEL));
1466-
tr_debug("RX_PCKT_LEN1: %x", rf_read_register(RX_PCKT_LEN1));
1467-
tr_debug("RX_PCKT_LEN0: %x", rf_read_register(RX_PCKT_LEN0));
1468-
tr_debug("CRC_FIELD3: %x", rf_read_register(CRC_FIELD3));
1469-
tr_debug("CRC_FIELD2: %x", rf_read_register(CRC_FIELD2));
1470-
tr_debug("CRC_FIELD1: %x", rf_read_register(CRC_FIELD1));
1471-
tr_debug("CRC_FIELD0: %x", rf_read_register(CRC_FIELD0));
1472-
tr_debug("RX_ADDRE_FIELD1: %x", rf_read_register(RX_ADDRE_FIELD1));
1473-
tr_debug("RX_ADDRE_FIELD0: %x", rf_read_register(RX_ADDRE_FIELD0));
1474-
tr_debug("RSSI_LEVEL_RUN: %x", rf_read_register(RSSI_LEVEL_RUN));
1475-
tr_debug("DEVICE_INFO1: %x", rf_read_register(DEVICE_INFO1));
1476-
tr_debug("DEVICE_INFO0: %x", rf_read_register(DEVICE_INFO0));
1477-
tr_debug("IRQ_STATUS3: %x", rf_read_register(IRQ_STATUS3));
1478-
tr_debug("IRQ_STATUS2: %x", rf_read_register(IRQ_STATUS2));
1479-
tr_debug("IRQ_STATUS1: %x", rf_read_register(IRQ_STATUS1));
1480-
tr_debug("IRQ_STATUS0: %x", rf_read_register(IRQ_STATUS0));
1481-
}
1482-
14831381
#if MBED_CONF_S2LP_PROVIDE_DEFAULT
14841382
NanostackRfPhy &NanostackRfPhy::get_default_instance()
14851383
{

components/802.15.4_RF/stm-s2lp-rf-driver/source/rf_configuration.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
// Use multiplier for better resolution
3636
#define RESOLUTION_MULTIPLIER 1000000
3737

38+
// RSSI_TH is a 8-bit register which can be converted to dBm using formula RSSI_TH-146
39+
#define MIN_RSSI_THRESHOLD -146
40+
#define MAX_RSSI_THRESHOLD 109
41+
3842
void rf_conf_calculate_datarate_registers(uint32_t datarate, uint16_t *datarate_mantissa, uint8_t *datarate_exponent)
3943
{
4044
uint64_t datarate_m = (uint64_t)datarate * DEF_2EXP33;
@@ -151,6 +155,12 @@ void rf_conf_calculate_rx_filter_bandwidth_registers(uint32_t rx_bandwidth, uint
151155
*chflt_e = chflt_e_tmp;
152156
}
153157

158+
int16_t rf_conf_cca_threshold_percent_to_rssi(uint8_t percent)
159+
{
160+
uint8_t step = (MAX_RSSI_THRESHOLD-MIN_RSSI_THRESHOLD);
161+
return MIN_RSSI_THRESHOLD + (step * percent) / 100;
162+
}
163+
154164
void rf_conf_calculate_rssi_threshold_registers(int16_t rssi_threshold, uint8_t *rssi_th)
155165
{
156166
*rssi_th = rssi_threshold + RSSI_OFFSET;

components/802.15.4_RF/stm-s2lp-rf-driver/source/rf_configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int rf_conf_calculate_channel_spacing_registers(uint32_t channel_spacing, uint8_
3232
void rf_conf_calculate_rx_filter_bandwidth_registers(uint32_t rx_bandwidth, uint8_t *chflt_m, uint8_t *chflt_e);
3333
void rf_conf_calculate_rssi_threshold_registers(int16_t rssi_threshold, uint8_t *rssi_th);
3434
uint32_t rf_conf_calculate_deviation(phy_modulation_index_e modulation_index, uint32_t datarate);
35+
int16_t rf_conf_cca_threshold_percent_to_rssi(uint8_t percent);
3536

3637
#ifdef __cplusplus
3738
}

components/802.15.4_RF/stm-s2lp-rf-driver/source/s2lpReg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ extern "C" {
229229

230230
#define DEFAULT_DEVIATION 125000
231231
#define RX_FILTER_BANDWIDTH 540000
232-
#define RSSI_THRESHOLD -60
232+
#define RSSI_THRESHOLD -85
233233

234234
// PCKTCTRL6
235235
#define PCKT_SYNCLEN_FIELD 0xFC

0 commit comments

Comments
 (0)