diff --git a/platformio.ini b/platformio.ini index 936d5fa7..5fd9ef9e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.5.9 +release_version = 1.5.13 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose debug_level = 0 diff --git a/src/button.cpp b/src/button.cpp index 42f4180f..37ae91fe 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -6,6 +6,8 @@ // Local logging tag static const char TAG[] = "main"; +portMUX_TYPE mutexButton = portMUX_INITIALIZER_UNLOCKED; + void IRAM_ATTR ButtonIRQ() { portENTER_CRITICAL(&mutexButton); ButtonPressedIRQ++; diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 0e49726a..1e864ba5 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -9,6 +9,8 @@ // Local logging tag static const char TAG[] = "main"; +portMUX_TYPE mutexHomeCycle = portMUX_INITIALIZER_UNLOCKED; + // do all housekeeping void doHousekeeping() { diff --git a/src/display.cpp b/src/display.cpp index 9e2ffcb2..773dbf94 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -15,6 +15,8 @@ const char lora_datarate[] = {"100908078CNA121110090807"}; uint8_t volatile DisplayState = 0; +portMUX_TYPE mutexDisplay = portMUX_INITIALIZER_UNLOCKED; + // helper function, prints a hex key on display void DisplayKey(const uint8_t *key, uint8_t len, bool lsb) { const uint8_t *p; diff --git a/src/globals.h b/src/globals.h index a4fffd4d..739512f1 100644 --- a/src/globals.h +++ b/src/globals.h @@ -46,7 +46,6 @@ extern uint16_t volatile macs_total, macs_wifi, macs_ble, batt_voltage; // display values extern std::set macs; // temp storage for MACs extern hw_timer_t *channelSwitch, *sendCycle; -extern portMUX_TYPE mutexButton, mutexDisplay, mutexHomeCycle, mutexSendCycle; extern volatile uint8_t SendCycleTimerIRQ, HomeCycleIRQ, DisplayTimerIRQ, ChannelTimerIRQ, ButtonPressedIRQ; diff --git a/src/hal/lopy4.h b/src/hal/lopy4.h index 5a4fffa0..fc0be422 100644 --- a/src/hal/lopy4.h +++ b/src/hal/lopy4.h @@ -3,7 +3,7 @@ #define HAS_LORA 1 // comment out if device shall not send data via LoRa #define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 -#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED +//#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED #define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0 #define BOARD_HAS_PSRAM // use extra 4MB extern RAM diff --git a/src/hal/ttgov21old.h b/src/hal/ttgov21old.h index ce92a8a4..25271b80 100644 --- a/src/hal/ttgov21old.h +++ b/src/hal/ttgov21old.h @@ -7,6 +7,7 @@ #define HAS_SPI 1 // comment out if device shall not send data via SPI #define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define HAS_LED NOT_A_PIN // no usable LED on board +#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C //#define DISPLAY_FLIP 1 // rotated display diff --git a/src/main.cpp b/src/main.cpp index d150928a..f758a795 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,7 @@ Task Core Prio Purpose IDLE 0 0 ESP32 arduino scheduler -> runs wifi sniffer task gpsloop 0 2 read data from GPS over serial or i2c IDLE 1 0 Arduino loop() -> used for LED switching -loraloop 1 3 runs the LMIC stack +loraloop 1 2 runs the LMIC stack statemachine 1 1 switches application process logic wifiloop 0 4 rotates wifi channels @@ -77,12 +77,6 @@ QueueHandle_t SPISendQueue; TaskHandle_t GpsTask = NULL; #endif -// sync main loop and ISR when modifying IRQ handler shared variables -portMUX_TYPE mutexButton = portMUX_INITIALIZER_UNLOCKED; -portMUX_TYPE mutexDisplay = portMUX_INITIALIZER_UNLOCKED; -portMUX_TYPE mutexHomeCycle = portMUX_INITIALIZER_UNLOCKED; -portMUX_TYPE mutexSendCycle = portMUX_INITIALIZER_UNLOCKED; - std::set macs; // container holding unique MAC adress hashes // initialize payload encoder @@ -312,9 +306,9 @@ void setup() { ESP_LOGI(TAG, "Starting Lora..."); xTaskCreatePinnedToCore(lorawan_loop, /* task function */ "loraloop", /* name of task */ - 2560, /* stack size of task */ + 3048, /* stack size of task */ (void *)1, /* parameter of the task */ - 3, /* priority of the task */ + 2, /* priority of the task */ &LoraTask, /* task handle*/ 1); /* CPU core */ #endif @@ -352,7 +346,7 @@ void setup() { // start wifi channel rotation task xTaskCreatePinnedToCore(switchWifiChannel, /* task function */ "wifiloop", /* name of task */ - 1536, /* stack size of task */ + 2048, /* stack size of task */ NULL, /* parameter of the task */ 4, /* priority of the task */ &wifiSwitchTask, /* task handle*/ diff --git a/src/senddata.cpp b/src/senddata.cpp index 616df8fb..d4f89d62 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -1,6 +1,8 @@ // Basic Config #include "globals.h" +portMUX_TYPE mutexSendCycle = portMUX_INITIALIZER_UNLOCKED; + // put data to send in RTos Queues used for transmit over channels Lora and SPI void SendData(uint8_t port) { diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index 621c8494..4e2500b6 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -33,9 +33,6 @@ void wifi_sniffer_init(void) { // .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames .filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames - // esp_event_loop_init(NULL, NULL); - // ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL)); - ESP_ERROR_CHECK(esp_wifi_init(&cfg)); // configure Wifi with cfg ESP_ERROR_CHECK( esp_wifi_set_country(&wifi_country)); // set locales for RF and channels @@ -50,7 +47,7 @@ void wifi_sniffer_init(void) { } // IRQ Handler -void ChannelSwitchIRQ() { +void IRAM_ATTR ChannelSwitchIRQ() { BaseType_t xHigherPriorityTaskWoken = pdFALSE; // unblock wifi channel rotation task xSemaphoreGiveFromISR(xWifiChannelSwitchSemaphore, &xHigherPriorityTaskWoken); diff --git a/src/wifiscan.h b/src/wifiscan.h index ea507cd7..48c218a1 100644 --- a/src/wifiscan.h +++ b/src/wifiscan.h @@ -27,7 +27,7 @@ typedef struct { void wifi_sniffer_init(void); void IRAM_ATTR wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); -void ChannelSwitchIRQ(void); +void IRAM_ATTR ChannelSwitchIRQ(void); void switchWifiChannel(void * parameter); #endif \ No newline at end of file