Revert to ISR handling packets and cap SX1280 data rate
This commit is contained in:
parent
c3b5a6f47f
commit
51afd310a5
1
Config.h
1
Config.h
@ -78,6 +78,7 @@
|
|||||||
bool pmu_ready = false;
|
bool pmu_ready = false;
|
||||||
bool promisc = false;
|
bool promisc = false;
|
||||||
bool implicit = false;
|
bool implicit = false;
|
||||||
|
volatile bool packet_ready = false;
|
||||||
uint8_t implicit_l = 0;
|
uint8_t implicit_l = 0;
|
||||||
|
|
||||||
uint8_t op_mode = MODE_HOST;
|
uint8_t op_mode = MODE_HOST;
|
||||||
|
@ -320,6 +320,7 @@ inline void kiss_write_packet(int index) {
|
|||||||
}
|
}
|
||||||
serial_write(FEND);
|
serial_write(FEND);
|
||||||
read_len = 0;
|
read_len = 0;
|
||||||
|
packet_ready = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void getPacketData(RadioInterface* radio, uint16_t len) {
|
inline void getPacketData(RadioInterface* radio, uint16_t len) {
|
||||||
@ -358,7 +359,7 @@ void receive_callback(uint8_t index, int packet_size) {
|
|||||||
getPacketData(selected_radio, packet_size);
|
getPacketData(selected_radio, packet_size);
|
||||||
|
|
||||||
seq = SEQ_UNSET;
|
seq = SEQ_UNSET;
|
||||||
ready = true;
|
packet_ready = true;
|
||||||
|
|
||||||
} else if (isSplitPacket(header) && seq != sequence) {
|
} else if (isSplitPacket(header) && seq != sequence) {
|
||||||
// This split packet does not carry the
|
// This split packet does not carry the
|
||||||
@ -383,7 +384,7 @@ void receive_callback(uint8_t index, int packet_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPacketData(selected_radio, packet_size);
|
getPacketData(selected_radio, packet_size);
|
||||||
ready = true;
|
packet_ready = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// In promiscuous mode, raw packets are
|
// In promiscuous mode, raw packets are
|
||||||
@ -391,26 +392,9 @@ void receive_callback(uint8_t index, int packet_size) {
|
|||||||
read_len = 0;
|
read_len = 0;
|
||||||
|
|
||||||
getPacketData(selected_radio, packet_size);
|
getPacketData(selected_radio, packet_size);
|
||||||
ready = true;
|
packet_ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ready) {
|
|
||||||
#if MCU_VARIANT == MCU_ESP32
|
|
||||||
portENTER_CRITICAL(&update_lock);
|
|
||||||
#elif MCU_VARIANT == MCU_NRF52
|
|
||||||
portENTER_CRITICAL();
|
|
||||||
#endif
|
|
||||||
last_rssi = selected_radio->packetRssi();
|
|
||||||
last_snr_raw = selected_radio->packetSnrRaw();
|
|
||||||
#if MCU_VARIANT == MCU_ESP32
|
|
||||||
portEXIT_CRITICAL(&update_lock);
|
|
||||||
#elif MCU_VARIANT == MCU_NRF52
|
|
||||||
portEXIT_CRITICAL();
|
|
||||||
#endif
|
|
||||||
kiss_indicate_stat_rssi();
|
|
||||||
kiss_indicate_stat_snr();
|
|
||||||
kiss_write_packet(index);
|
|
||||||
}
|
|
||||||
last_rx = millis();
|
last_rx = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1168,7 +1152,23 @@ void validate_status() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
packet_poll();
|
if (packet_ready) {
|
||||||
|
#if MCU_VARIANT == MCU_ESP32
|
||||||
|
portENTER_CRITICAL(&update_lock);
|
||||||
|
#elif MCU_VARIANT == MCU_NRF52
|
||||||
|
portENTER_CRITICAL();
|
||||||
|
#endif
|
||||||
|
last_rssi = selected_radio->packetRssi();
|
||||||
|
last_snr_raw = selected_radio->packetSnrRaw();
|
||||||
|
#if MCU_VARIANT == MCU_ESP32
|
||||||
|
portEXIT_CRITICAL(&update_lock);
|
||||||
|
#elif MCU_VARIANT == MCU_NRF52
|
||||||
|
portEXIT_CRITICAL();
|
||||||
|
#endif
|
||||||
|
kiss_indicate_stat_rssi();
|
||||||
|
kiss_indicate_stat_snr();
|
||||||
|
kiss_write_packet(1);
|
||||||
|
}
|
||||||
|
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
for (int i = 0; i < INTERFACE_COUNT; i++) {
|
for (int i = 0; i < INTERFACE_COUNT; i++) {
|
||||||
@ -1313,25 +1313,6 @@ void poll_buffers() {
|
|||||||
process_serial();
|
process_serial();
|
||||||
}
|
}
|
||||||
|
|
||||||
void packet_poll() {
|
|
||||||
// If we have received a packet on an interface which needs to be processed
|
|
||||||
while (!fifo_isempty(&packet_rdy_interfaces)) {
|
|
||||||
#if MCU_VARIANT == MCU_ESP32
|
|
||||||
portENTER_CRITICAL(&update_lock);
|
|
||||||
#elif MCU_VARIANT == MCU_NRF52
|
|
||||||
portENTER_CRITICAL();
|
|
||||||
#endif
|
|
||||||
uint8_t packet_int = fifo_pop(&packet_rdy_interfaces);
|
|
||||||
#if MCU_VARIANT == MCU_ESP32
|
|
||||||
portEXIT_CRITICAL(&update_lock);
|
|
||||||
#elif MCU_VARIANT == MCU_NRF52
|
|
||||||
portEXIT_CRITICAL();
|
|
||||||
#endif
|
|
||||||
selected_radio = interface_obj[packet_int];
|
|
||||||
selected_radio->handleDio0Rise();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
volatile bool serial_polling = false;
|
volatile bool serial_polling = false;
|
||||||
void serial_poll() {
|
void serial_poll() {
|
||||||
serial_polling = true;
|
serial_polling = true;
|
||||||
|
12
Radio.cpp
12
Radio.cpp
@ -96,10 +96,11 @@ extern RadioInterface* interface_obj[];
|
|||||||
// which one is high. We can then use the index of this pin in the 2D array to
|
// which one is high. We can then use the index of this pin in the 2D array to
|
||||||
// signal the correct interface to the main loop
|
// signal the correct interface to the main loop
|
||||||
void ISR_VECT onDio0Rise() {
|
void ISR_VECT onDio0Rise() {
|
||||||
|
BaseType_t int_status = taskENTER_CRITICAL_FROM_ISR();
|
||||||
for (int i = 0; i < INTERFACE_COUNT; i++) {
|
for (int i = 0; i < INTERFACE_COUNT; i++) {
|
||||||
if (digitalRead(interface_pins[i][5]) == HIGH) {
|
if (digitalRead(interface_pins[i][5]) == HIGH) {
|
||||||
if (interface_obj[i]->getPacketValidity()) {
|
if (interface_obj[i]->getPacketValidity()) {
|
||||||
fifo_push(&packet_rdy_interfaces, i);
|
interface_obj[i]->handleDio0Rise();
|
||||||
}
|
}
|
||||||
if (interfaces[i] == SX128X) {
|
if (interfaces[i] == SX128X) {
|
||||||
// On the SX1280, there is a bug which can cause the busy line
|
// On the SX1280, there is a bug which can cause the busy line
|
||||||
@ -111,6 +112,7 @@ void ISR_VECT onDio0Rise() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
taskEXIT_CRITICAL_FROM_ISR(int_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
sx126x::sx126x(uint8_t index, SPIClass* spi, bool tcxo, bool dio2_as_rf_switch, int ss, int sclk, int mosi, int miso, int reset, int dio0, int busy, int rxen) :
|
sx126x::sx126x(uint8_t index, SPIClass* spi, bool tcxo, bool dio2_as_rf_switch, int ss, int sclk, int mosi, int miso, int reset, int dio0, int busy, int rxen) :
|
||||||
@ -2622,11 +2624,11 @@ void sx128x::updateBitrate() {
|
|||||||
_csma_slot_ms = 10;
|
_csma_slot_ms = 10;
|
||||||
|
|
||||||
float target_preamble_symbols;
|
float target_preamble_symbols;
|
||||||
if (_bitrate <= LORA_FAST_BITRATE_THRESHOLD) {
|
//if (_bitrate <= LORA_FAST_BITRATE_THRESHOLD) {
|
||||||
target_preamble_symbols = (LORA_PREAMBLE_TARGET_MS/_lora_symbol_time_ms)-LORA_PREAMBLE_SYMBOLS_HW;
|
target_preamble_symbols = (LORA_PREAMBLE_TARGET_MS/_lora_symbol_time_ms)-LORA_PREAMBLE_SYMBOLS_HW;
|
||||||
} else {
|
//} else {
|
||||||
target_preamble_symbols = (LORA_PREAMBLE_FAST_TARGET_MS/_lora_symbol_time_ms)-LORA_PREAMBLE_SYMBOLS_HW;
|
/*target_preamble_symbols = (LORA_PREAMBLE_FAST_TARGET_MS/_lora_symbol_time_ms)-LORA_PREAMBLE_SYMBOLS_HW;
|
||||||
}
|
}*/
|
||||||
if (target_preamble_symbols < LORA_PREAMBLE_SYMBOLS_MIN) {
|
if (target_preamble_symbols < LORA_PREAMBLE_SYMBOLS_MIN) {
|
||||||
target_preamble_symbols = LORA_PREAMBLE_SYMBOLS_MIN;
|
target_preamble_symbols = LORA_PREAMBLE_SYMBOLS_MIN;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user