diff --git a/src/main.cpp b/src/main.cpp index 9a85115e..2d0ea2fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -291,8 +291,7 @@ void setup() { Task Core Prio Purpose ==================================================================== IDLE 0 0 ESP32 arduino scheduler - wifiloop 0 1 switches Wifi channels - gpsloop 0 2 reasd data from GPS over serial or i2c + gpsloop 0 2 read data from GPS over serial or i2c IDLE 1 0 Arduino loop() -> unused loraloop 1 1 runs the LMIC stack statemachine 1 3 switches process logic @@ -338,8 +337,6 @@ void setup() { // arduino-esp32 core. Note: do this *after* wifi has started, since // function gets it's seed from RF noise reset_salt(); // get new 16bit for salting hashes - xTaskCreatePinnedToCore(wifi_channel_loop, "wifiloop", 2048, (void *)1, 1, - &WifiLoopTask, 0); // start state machine ESP_LOGI(TAG, "Starting Statemachine..."); @@ -366,12 +363,15 @@ void stateMachine(void *pvParameters) { updateDisplay(); #endif - // check housekeeping cycle and if expired do the work + // check wifi scan cycle and if due rotate channel + if (ChannelTimerIRQ) + switchWifiChannel(channel); + // check housekeeping cycle and if due do the work if (HomeCycleIRQ) doHousekeeping(); // check send queue and process it - processSendBuffer(); - // check send cycle and enqueue payload if cycle is expired + enqueuePayload(); + // check send cycle and if due enqueue payload to send if (SendCycleTimerIRQ) sendPayload(); // yield to CPU diff --git a/src/senddata.cpp b/src/senddata.cpp index 73eca826..ad647233 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -74,7 +74,7 @@ void IRAM_ATTR SendCycleIRQ() { } // interrupt triggered function to eat data from RTos send queues and transmit it -void processSendBuffer() { +void enqueuePayload() { MessageBuffer_t SendBuffer; #ifdef HAS_LORA @@ -98,7 +98,7 @@ void processSendBuffer() { } #endif -} // processSendBuffer +} // enqueuePayload void flushQueues() { #ifdef HAS_LORA diff --git a/src/senddata.h b/src/senddata.h index 806899d6..eba9d8bd 100644 --- a/src/senddata.h +++ b/src/senddata.h @@ -4,7 +4,7 @@ void SendData(uint8_t port); void sendPayload(void); void SendCycleIRQ(void); -void processSendBuffer(void); +void enqueuePayload(void); void flushQueues(); #endif // _SENDDATA_H_ \ No newline at end of file diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index 4c240738..55c690ff 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -43,28 +43,17 @@ void wifi_sniffer_init(void) { ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); // now switch on monitor mode } -// Wifi channel rotation task -void wifi_channel_loop(void *pvParameters) { - - configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check - - while (1) { - - if (ChannelTimerIRQ) { +// Wifi channel rotation +void switchWifiChannel(uint8_t &ch) { portENTER_CRITICAL(&timerMux); ChannelTimerIRQ = 0; portEXIT_CRITICAL(&timerMux); // rotates variable channel 1..WIFI_CHANNEL_MAX - channel = (channel % WIFI_CHANNEL_MAX) + 1; - esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE); - ESP_LOGD(TAG, "Wifi set channel %d", channel); + ch = (ch % WIFI_CHANNEL_MAX) + 1; + esp_wifi_set_channel(ch, WIFI_SECOND_CHAN_NONE); + ESP_LOGD(TAG, "Wifi set channel %d", &ch); } - vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU - - } // end of infinite wifi channel rotation loop -} - // IRQ handler void IRAM_ATTR ChannelSwitchIRQ() { portENTER_CRITICAL(&timerMux); diff --git a/src/wifiscan.h b/src/wifiscan.h index afd5700e..5e8aae9a 100644 --- a/src/wifiscan.h +++ b/src/wifiscan.h @@ -28,6 +28,6 @@ typedef struct { void wifi_sniffer_init(void); void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); void ChannelSwitchIRQ(void); -void wifi_channel_loop(void *pvParameters); +void switchWifiChannel(uint8_t &ch); #endif \ No newline at end of file