]> git.tnoah.ca Git - lora-radio.git/commitdiff
Revert to ISR handling packets and cap SX1280 data rate
authorjacob.eva <x00010@disroot.org>
Wed, 11 Sep 2024 19:18:43 +0000 (20:18 +0100)
committerjacob.eva <x00010@disroot.org>
Wed, 11 Sep 2024 19:18:43 +0000 (20:18 +0100)
Config.h
RNode_Firmware_CE.ino
Radio.cpp

index acc6a8194f2e8dfe8deb441604fb16526dd86e7b..7f4c505a546900fc07fdda0d6ebc3957a73da094 100644 (file)
--- a/Config.h
+++ b/Config.h
@@ -78,6 +78,7 @@
        bool pmu_ready     = false;
        bool promisc       = false;
        bool implicit      = false;
+    volatile bool packet_ready  = false;
        uint8_t implicit_l = 0;
 
        uint8_t op_mode   = MODE_HOST;
index 6492bb41199d239a376e80b4f8d97daa020dc433..2ead632a077bea70629354179fbba87dc545064a 100644 (file)
@@ -320,6 +320,7 @@ inline void kiss_write_packet(int index) {
   }
   serial_write(FEND);
   read_len = 0;
+  packet_ready = false;
 }
 
 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);
 
       seq = SEQ_UNSET;
-      ready = true;
+      packet_ready = true;
 
     } else if (isSplitPacket(header) && seq != sequence) {
       // 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);
-      ready = true;
+      packet_ready = true;
     }
   } else {
     // In promiscuous mode, raw packets are
@@ -391,26 +392,9 @@ void receive_callback(uint8_t index, int packet_size) {
     read_len = 0;
 
     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();
 }
 
@@ -1168,7 +1152,23 @@ void validate_status() {
 }
 
 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;
     for (int i = 0; i < INTERFACE_COUNT; i++) {
@@ -1313,25 +1313,6 @@ void poll_buffers() {
     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;
 void serial_poll() {
   serial_polling = true;
index c7dd01245875d178035c61d4465394704b44ef4c..e0df26456d4eae75e31d58c64b3ee8b0e37ff10f 100644 (file)
--- a/Radio.cpp
+++ b/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
 // signal the correct interface to the main loop 
 void ISR_VECT onDio0Rise() {
+    BaseType_t int_status = taskENTER_CRITICAL_FROM_ISR();
     for (int i = 0; i < INTERFACE_COUNT; i++) {
         if (digitalRead(interface_pins[i][5]) == HIGH) {
             if (interface_obj[i]->getPacketValidity()) {
-                fifo_push(&packet_rdy_interfaces, i);
+                interface_obj[i]->handleDio0Rise();
             }
             if (interfaces[i] == SX128X) {
                 // 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) :
@@ -2622,11 +2624,11 @@ void sx128x::updateBitrate() {
         _csma_slot_ms = 10;
 
         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;
-        } else {
-            target_preamble_symbols = (LORA_PREAMBLE_FAST_TARGET_MS/_lora_symbol_time_ms)-LORA_PREAMBLE_SYMBOLS_HW;
-        }
+        //} else {
+            /*target_preamble_symbols = (LORA_PREAMBLE_FAST_TARGET_MS/_lora_symbol_time_ms)-LORA_PREAMBLE_SYMBOLS_HW;
+        }*/
         if (target_preamble_symbols < LORA_PREAMBLE_SYMBOLS_MIN) {
             target_preamble_symbols = LORA_PREAMBLE_SYMBOLS_MIN;
         } else {