Skip to content

Commit b719e86

Browse files
committed
Merge branch '82-radio-in-rx-when-waiting-between-cca-2' into 'master'
Resolve "radio in rx when waiting between CCA" Closes Sub-IoT#82 See merge request aloxy/oss-7!47
2 parents 77e5672 + 661b975 commit b719e86

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

stack/framework/hal/chips/sx127x/sx127x.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@
134134
#error "Invalid configuration"
135135
#endif
136136

137+
static const uint16_t rx_bw_startup_time[21] = {63, 74, 85, 71, 84, 97, 119, 144, 169, 215, 264, 313,
138+
407, 504, 601, 791, 984, 1180, 1560, 1940, 2330};
139+
140+
static uint8_t rx_bw_number = 21;
141+
137142
typedef enum {
138143
OPMODE_SLEEP = 0,
139144
OPMODE_STANDBY = 1,
@@ -803,6 +808,7 @@ void hw_radio_set_rx_bw_hz(uint32_t bw_hz) {
803808
if(abs(computed_bw - bw_hz) < min_bw_dif) {
804809
min_bw_dif = abs(computed_bw - bw_hz);
805810
reg_bw = ((((bw_mant_count - 16) / 4) << 3) | bw_exp_count);
811+
rx_bw_number = (bw_exp_count - 1) * 3 + ((bw_mant_count - 16) >> 2);
806812
}
807813
}
808814
}
@@ -984,8 +990,8 @@ __attribute__((weak)) void hw_radio_io_deinit() {
984990
}
985991

986992
int16_t hw_radio_get_rssi() {
987-
hw_radio_set_opmode(HW_STATE_RX);
993+
hw_radio_set_opmode(HW_STATE_RX);
988994
hw_gpio_disable_interrupt(SX127x_DIO1_PIN);
989-
while(!(read_reg(REG_IRQFLAGS1) & 0x08));
995+
hw_busy_wait(rx_bw_startup_time[rx_bw_number]); //TODO: optimise this timing. Now it should wait for ~700µs but actually waits ~900µs (low rate)
990996
return (- read_reg(REG_RSSIVALUE) >> 1);
991997
}

stack/modules/d7ap/dll.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void start_background_scan()
294294

295295
phy_rx_config_t config = {
296296
.channel_id = current_channel_id,
297-
.rssi_thr = - E_CCA,
297+
.rssi_thr = E_CCA,
298298
};
299299
phy_start_background_scan(&config, &dll_signal_packet_received);
300300
}
@@ -416,6 +416,7 @@ static void cca_rssi_valid(int16_t cur_rssi)
416416
{
417417
if (dll_state == DLL_STATE_CCA1)
418418
{
419+
phy_switch_to_standby_mode();
419420
DPRINT("CCA1 RSSI: %d", cur_rssi);
420421
switch_state(DLL_STATE_CCA2);
421422

@@ -750,7 +751,7 @@ void dll_execute_scan_automation(void *arg)
750751
if (tx_nf_method == D7ADLL_FIXED_NOISE_FLOOR)
751752
{
752753
//Use the default channel CCA threshold
753-
E_CCA = current_access_profile.subbands[0].cca; // Eccao is set to 0 dB
754+
E_CCA = - current_access_profile.subbands[0].cca; // Eccao is set to 0 dB
754755
DPRINT("E_CCA %i", E_CCA);
755756
}
756757

@@ -966,7 +967,7 @@ void dll_tx_frame(packet_t* packet)
966967
if (tx_nf_method == D7ADLL_FIXED_NOISE_FLOOR)
967968
{
968969
//Use the default channel CCA threshold
969-
E_CCA = remote_access_profile.subbands[0].cca; // Eccao is set to 0 dB
970+
E_CCA = - remote_access_profile.subbands[0].cca; // Eccao is set to 0 dB
970971
DPRINT("E_CCA %i", E_CCA);
971972
}
972973
else

stack/modules/d7ap/phy.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ static void release_packet(hw_radio_packet_t* hw_radio_packet)
203203
packet_queue_free_packet(packet_queue_find_packet(hw_radio_packet));
204204
}
205205

206-
static void switch_to_standby_mode()
206+
void phy_switch_to_standby_mode()
207207
{
208208
hw_radio_set_opmode(HW_STATE_STANDBY);
209209
state = STATE_IDLE;
210210
}
211211

212-
static void switch_to_sleep_mode()
212+
void phy_switch_to_sleep_mode()
213213
{
214214
hw_radio_set_idle();
215215
state = STATE_IDLE;
@@ -222,7 +222,7 @@ static void packet_transmitted(timer_tick_t timestamp)
222222
current_packet->tx_meta.timestamp = timestamp;
223223
DPRINT("Transmitted packet @ %i with length = %i", current_packet->tx_meta.timestamp, current_packet->length);
224224

225-
switch_to_standby_mode();
225+
phy_switch_to_standby_mode();
226226

227227
transmitted_callback(packet_queue_find_packet(current_packet));
228228
}
@@ -270,7 +270,7 @@ static void packet_received(hw_radio_packet_t* hw_radio_packet)
270270
hw_radio_set_opmode(HW_STATE_RX);
271271
}
272272
else
273-
switch_to_standby_mode();
273+
phy_switch_to_standby_mode();
274274

275275
received_callback(packet);
276276
}
@@ -533,7 +533,7 @@ error_t phy_start_energy_scan(channel_id_t* channel, rssi_valid_callback_t rssi_
533533

534534
error_t phy_stop_rx(){
535535

536-
switch_to_sleep_mode();
536+
phy_switch_to_sleep_mode();
537537
return SUCCESS;
538538
}
539539

@@ -573,7 +573,7 @@ error_t phy_send_packet(hw_radio_packet_t* packet, phy_tx_config_t* config, tx_p
573573
pending_rx_cfg.channel_id = current_channel_id;
574574
pending_rx_cfg.syncword_class = current_syncword_class;
575575
should_rx_after_tx_completed = true;
576-
switch_to_standby_mode();
576+
phy_switch_to_standby_mode();
577577
}
578578

579579
configure_channel(&config->channel_id);
@@ -828,9 +828,9 @@ error_t phy_start_background_scan(phy_rx_config_t* config, rx_packet_callback_t
828828
if (rssi <= config->rssi_thr)
829829
{
830830
DPRINT("FAST RX termination RSSI %i below limit %i\n", rssi, config->rssi_thr);
831-
switch_to_sleep_mode();
831+
phy_switch_to_sleep_mode();
832832
// TODO choose standby mode to allow rapid channel cycling
833-
//switch_to_standby_mode();
833+
//phy_switch_to_standby_mode();
834834
DEBUG_RX_END();
835835
return FAIL;
836836
}
@@ -854,7 +854,7 @@ void phy_continuous_tx(phy_tx_config_t const* tx_cfg, uint8_t time_period, tx_pa
854854
pending_rx_cfg.channel_id = current_channel_id;
855855
pending_rx_cfg.syncword_class = current_syncword_class;
856856
should_rx_after_tx_completed = true;
857-
switch_to_standby_mode();
857+
phy_switch_to_standby_mode();
858858
}
859859

860860
configure_channel(&tx_cfg->channel_id);

stack/modules/d7ap/phy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ error_t phy_start_rx(channel_id_t *channel, syncword_class_t syncword_class, rx_
270270
*/
271271
error_t phy_start_energy_scan(channel_id_t *channel, rssi_valid_callback_t rssi_cb, int16_t scan_duration);
272272

273+
void phy_switch_to_sleep_mode(void);
274+
void phy_switch_to_standby_mode(void);
273275

274276
#endif //__HW_RADIO_H_
275277

0 commit comments

Comments
 (0)