From 5a04a97444157f62a54aec3569baff79ee1db3e9 Mon Sep 17 00:00:00 2001 From: Pawel Jalocha Date: Mon, 2 Nov 2020 13:28:15 +0000 Subject: [PATCH] Fix again an RF timing issue --- main/rf.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/main/rf.cpp b/main/rf.cpp index 96179aa..4a5daaa 100644 --- a/main/rf.cpp +++ b/main/rf.cpp @@ -270,18 +270,23 @@ extern "C" // RF_Print(); // #endif + // xSemaphoreTake(CONS_Mutex, portMAX_DELAY); + // Format_UnsDec(CONS_UART_Write, xTaskGetTickCount(), 4, 3); + // Format_String(CONS_UART_Write, " => RF-slot\n"); + // xSemaphoreGive(CONS_Mutex); + #ifdef WITH_LORAWAN bool WANrx=0; int WAN_RespLeft = WAN_RespTick-xTaskGetTickCount(); // [tick] how much time left before expected response if(WANdev.State==1 || WANdev.State==3) // if State indicates we are waiting for the response { if(WAN_RespLeft<=5) WANdev.State--; // if time below 5 ticks we have not enough time else if(WAN_RespLeft<200) { WANrx=1; } // if more than 200ms then we can't wait this long now - xSemaphoreTake(CONS_Mutex, portMAX_DELAY); - Format_UnsDec(CONS_UART_Write, xTaskGetTickCount(), 4, 3); - Format_String(CONS_UART_Write, "s LoRaWAN Rx: "); - Format_SignDec(CONS_UART_Write, WAN_RespLeft); - Format_String(CONS_UART_Write, "ms\n"); - xSemaphoreGive(CONS_Mutex); + // xSemaphoreTake(CONS_Mutex, portMAX_DELAY); + // Format_UnsDec(CONS_UART_Write, xTaskGetTickCount(), 4, 3); + // Format_String(CONS_UART_Write, "s LoRaWAN Rx: "); + // Format_SignDec(CONS_UART_Write, WAN_RespLeft); + // Format_String(CONS_UART_Write, "ms\n"); + // xSemaphoreGive(CONS_Mutex); } if(WANrx) // if reception expected from WAN @@ -468,15 +473,15 @@ extern "C" TxTime = (RX_Random&0x3F)+1; TxTime*=6; // [ms] (1..64)*6 = 6..384ms #ifdef WITH_LORAWAN bool WANtx = 0; - uint16_t SlotEnd = 1250; + uint16_t SlotEnd = 1240; if(WAN_BackOff) WAN_BackOff--; else // decide to transmit in this slot - { if(WANdev.State==0 || WANdev.State==2) - { XorShift32(RX_Random); if((RX_Random&0x1F)==0x10) WANtx=1; SlotEnd=1200; } // random decision 1/32 + { if(WANdev.State==0 || WANdev.State==2) // + { XorShift32(RX_Random); if((RX_Random&0x1F)==0x10) { WANtx=1; SlotEnd=1200; } } // random decision 1/32 } TimeSlot(TxChan, SlotEnd-TimeSync_msTime(), TxPktData1, TRX.averRSSI, 0, TxTime); #else - TimeSlot(TxChan, 1250-TimeSync_msTime(), TxPktData1, TRX.averRSSI, 0, TxTime); + TimeSlot(TxChan, 1240-TimeSync_msTime(), TxPktData1, TRX.averRSSI, 0, TxTime); #endif #ifdef WITH_LORAWAN