new _ASSERT function
This commit is contained in:
parent
7330419f5e
commit
5bbe4bee02
@ -1,5 +1,6 @@
|
|||||||
#ifndef _GLOBALS_H
|
#ifndef _GLOBALS_H
|
||||||
#define _GLOBALS_H
|
#define _GLOBALS_H
|
||||||
|
#endif
|
||||||
|
|
||||||
// The mother of all embedded development...
|
// The mother of all embedded development...
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
@ -49,6 +50,16 @@
|
|||||||
(xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(DISPLAYREFRESH_MS)) == pdTRUE)
|
(xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(DISPLAYREFRESH_MS)) == pdTRUE)
|
||||||
#define I2C_MUTEX_UNLOCK() (xSemaphoreGive(I2Caccess))
|
#define I2C_MUTEX_UNLOCK() (xSemaphoreGive(I2Caccess))
|
||||||
|
|
||||||
|
// pseudo system halt function, useful to prevent writeloops to NVRAM
|
||||||
|
#ifndef _ASSERT
|
||||||
|
#define _ASSERT(cond) \
|
||||||
|
if ((cond) == 0) { \
|
||||||
|
ESP_LOGE(TAG, "FAILURE in %s:%d", __FILE__, __LINE__); \
|
||||||
|
mask_user_IRQ(); \
|
||||||
|
for (;;) \
|
||||||
|
; \
|
||||||
|
}
|
||||||
|
|
||||||
enum sendprio_t { prio_low, prio_normal, prio_high };
|
enum sendprio_t { prio_low, prio_normal, prio_high };
|
||||||
enum timesource_t { _gps, _rtc, _lora, _unsynced };
|
enum timesource_t { _gps, _rtc, _lora, _unsynced };
|
||||||
|
|
||||||
|
@ -21,4 +21,4 @@
|
|||||||
#include "timekeeper.h"
|
#include "timekeeper.h"
|
||||||
#include "corona.h"
|
#include "corona.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -67,7 +67,7 @@ void dp_setup(int contrast) {
|
|||||||
MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA,
|
MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA,
|
||||||
MY_DISPLAY_SCL, MY_DISPLAY_RST,
|
MY_DISPLAY_SCL, MY_DISPLAY_RST,
|
||||||
OLED_FREQUENCY); // use standard I2C bus at 400Khz
|
OLED_FREQUENCY); // use standard I2C bus at 400Khz
|
||||||
assert(rc != OLED_NOT_FOUND);
|
_ASSERT (rc != OLED_NOT_FOUND);
|
||||||
|
|
||||||
// set display buffer
|
// set display buffer
|
||||||
obdSetBackBuffer(&ssoled, displaybuf);
|
obdSetBackBuffer(&ssoled, displaybuf);
|
||||||
@ -265,10 +265,10 @@ void dp_drawPage(time_t t, bool nextpage) {
|
|||||||
else
|
else
|
||||||
dp_printf("WIFI:off");
|
dp_printf("WIFI:off");
|
||||||
if (cfg.blescan)
|
if (cfg.blescan)
|
||||||
if (!cfg.enscount)
|
if (!cfg.enscount)
|
||||||
dp_printf("BLTH:%-5d", macs_ble);
|
dp_printf("BLTH:%-5d", macs_ble);
|
||||||
else
|
else
|
||||||
dp_printf(" CWA:%-5d", cwa_report());
|
dp_printf(" CWA:%-5d", cwa_report());
|
||||||
else
|
else
|
||||||
dp_printf(" BLTH:off");
|
dp_printf(" BLTH:off");
|
||||||
#elif ((WIFICOUNTER) && (!BLECOUNTER))
|
#elif ((WIFICOUNTER) && (!BLECOUNTER))
|
||||||
@ -279,10 +279,9 @@ void dp_drawPage(time_t t, bool nextpage) {
|
|||||||
#elif ((!WIFICOUNTER) && (BLECOUNTER))
|
#elif ((!WIFICOUNTER) && (BLECOUNTER))
|
||||||
if (cfg.blescan) {
|
if (cfg.blescan) {
|
||||||
dp_printf("BLTH:%-5d", macs_ble);
|
dp_printf("BLTH:%-5d", macs_ble);
|
||||||
if (cfg.enscount)
|
if (cfg.enscount)
|
||||||
dp_printf("(CWA:%d)", cwa_report());
|
dp_printf("(CWA:%d)", cwa_report());
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
dp_printf("BLTH:off");
|
dp_printf("BLTH:off");
|
||||||
#else
|
#else
|
||||||
dp_printf("Sniffer disabled");
|
dp_printf("Sniffer disabled");
|
||||||
|
@ -150,7 +150,7 @@ time_t get_gpstime(void) {
|
|||||||
// GPS serial feed FreeRTos Task
|
// GPS serial feed FreeRTos Task
|
||||||
void gps_loop(void *pvParameters) {
|
void gps_loop(void *pvParameters) {
|
||||||
|
|
||||||
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
_ASSERT((uint32_t)pvParameters == 1); // FreeRTOS check
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ static const char TAG[] = __FILE__;
|
|||||||
// irq handler task, handles all our application level interrupts
|
// irq handler task, handles all our application level interrupts
|
||||||
void irqHandler(void *pvParameters) {
|
void irqHandler(void *pvParameters) {
|
||||||
|
|
||||||
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
_ASSERT((uint32_t)pvParameters == 1); // FreeRTOS check
|
||||||
|
|
||||||
uint32_t InterruptStatus;
|
uint32_t InterruptStatus;
|
||||||
|
|
||||||
|
@ -22,9 +22,8 @@
|
|||||||
#define LMIC_USE_INTERRUPTS 1
|
#define LMIC_USE_INTERRUPTS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// avoid lmic warning if we don't configure radio because we don't have one
|
// avoid lmic warning if we don't configure radio in case we haven't one
|
||||||
#define CFG_sx1276_radio 1
|
#if !(defined(CFG_sx1272_radio) || defined(CFG_sx1276_radio))
|
||||||
#if ! (defined(CFG_sx1272_radio) || defined(CFG_sx1276_radio))
|
|
||||||
#define CFG_sx1276_radio 1
|
#define CFG_sx1276_radio 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ void showLoraKeys(void) {
|
|||||||
|
|
||||||
// LMIC send task
|
// LMIC send task
|
||||||
void lora_send(void *pvParameters) {
|
void lora_send(void *pvParameters) {
|
||||||
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
_ASSERT((uint32_t)pvParameters == 1); // FreeRTOS check
|
||||||
|
|
||||||
MessageBuffer_t SendBuffer;
|
MessageBuffer_t SendBuffer;
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ void lora_stack_reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t lora_stack_init(bool do_join) {
|
esp_err_t lora_stack_init(bool do_join) {
|
||||||
assert(SEND_QUEUE_SIZE);
|
_ASSERT(SEND_QUEUE_SIZE > 0);
|
||||||
LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
|
LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
|
||||||
if (LoraSendQueue == 0) {
|
if (LoraSendQueue == 0) {
|
||||||
ESP_LOGE(TAG, "Could not create LORA send queue. Aborting.");
|
ESP_LOGE(TAG, "Could not create LORA send queue. Aborting.");
|
||||||
@ -382,7 +382,7 @@ void lora_queuereset(void) { xQueueReset(LoraSendQueue); }
|
|||||||
|
|
||||||
// LMIC lorawan stack task
|
// LMIC lorawan stack task
|
||||||
void lmictask(void *pvParameters) {
|
void lmictask(void *pvParameters) {
|
||||||
configASSERT(((uint32_t)pvParameters) == 1);
|
_ASSERT((uint32_t)pvParameters == 1);
|
||||||
|
|
||||||
// setup LMIC stack
|
// setup LMIC stack
|
||||||
os_init_ex(&myPinmap); // initialize lmic run-time environment
|
os_init_ex(&myPinmap); // initialize lmic run-time environment
|
||||||
|
28
src/main.cpp
28
src/main.cpp
@ -65,8 +65,8 @@ PMUIRQ -> PMU chip gpio
|
|||||||
fired by software (Ticker.h)
|
fired by software (Ticker.h)
|
||||||
TIMESYNC_IRQ -> setTimeSyncIRQ()
|
TIMESYNC_IRQ -> setTimeSyncIRQ()
|
||||||
CYCLIC_IRQ -> setCyclicIRQ()
|
CYCLIC_IRQ -> setCyclicIRQ()
|
||||||
SENDCYCLE_IRQ -> setSendIRQ()
|
SENDCYCLE_IRQ -> setSendIRQ()
|
||||||
BME_IRQ -> setBMEIRQ()
|
BME_IRQ -> setBMEIRQ()
|
||||||
MQTT_IRQ -> setMqttIRQ()
|
MQTT_IRQ -> setMqttIRQ()
|
||||||
|
|
||||||
ClockTask (Core 1), see timekeeper.cpp
|
ClockTask (Core 1), see timekeeper.cpp
|
||||||
@ -118,7 +118,7 @@ void setup() {
|
|||||||
|
|
||||||
// create some semaphores for syncing / mutexing tasks
|
// create some semaphores for syncing / mutexing tasks
|
||||||
I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus
|
I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus
|
||||||
assert(I2Caccess != NULL);
|
_ASSERT(I2Caccess != NULL);
|
||||||
I2C_MUTEX_UNLOCK();
|
I2C_MUTEX_UNLOCK();
|
||||||
|
|
||||||
// disable brownout detection
|
// disable brownout detection
|
||||||
@ -203,7 +203,7 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// read (and initialize on first run) runtime settings from NVRAM
|
// read (and initialize on first run) runtime settings from NVRAM
|
||||||
assert(loadConfig()); // includes initialize if necessary
|
_ASSERT(loadConfig()); // includes initialize if necessary
|
||||||
|
|
||||||
// now that we are powered, we scan i2c bus for devices
|
// now that we are powered, we scan i2c bus for devices
|
||||||
i2c_scan();
|
i2c_scan();
|
||||||
@ -217,7 +217,7 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BOARD_HAS_PSRAM
|
#ifdef BOARD_HAS_PSRAM
|
||||||
assert(psramFound());
|
_ASSERT(psramFound());
|
||||||
ESP_LOGI(TAG, "PSRAM found and initialized");
|
ESP_LOGI(TAG, "PSRAM found and initialized");
|
||||||
strcat_P(features, " PSRAM");
|
strcat_P(features, " PSRAM");
|
||||||
#endif
|
#endif
|
||||||
@ -343,20 +343,20 @@ void setup() {
|
|||||||
#if (HAS_LORA)
|
#if (HAS_LORA)
|
||||||
strcat_P(features, " LORA");
|
strcat_P(features, " LORA");
|
||||||
// kick off join, except we come from sleep
|
// kick off join, except we come from sleep
|
||||||
assert(lora_stack_init(RTC_runmode == RUNMODE_WAKEUP ? false : true) ==
|
_ASSERT(lora_stack_init(RTC_runmode == RUNMODE_WAKEUP ? false : true) ==
|
||||||
ESP_OK);
|
ESP_OK);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize SPI
|
// initialize SPI
|
||||||
#ifdef HAS_SPI
|
#ifdef HAS_SPI
|
||||||
strcat_P(features, " SPI");
|
strcat_P(features, " SPI");
|
||||||
assert(spi_init() == ESP_OK);
|
_ASSERT(spi_init() == ESP_OK);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize MQTT
|
// initialize MQTT
|
||||||
#ifdef HAS_MQTT
|
#ifdef HAS_MQTT
|
||||||
strcat_P(features, " MQTT");
|
strcat_P(features, " MQTT");
|
||||||
assert(mqtt_init() == ESP_OK);
|
_ASSERT(mqtt_init() == ESP_OK);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (HAS_SDCARD)
|
#if (HAS_SDCARD)
|
||||||
@ -395,7 +395,7 @@ void setup() {
|
|||||||
// initialize RTC
|
// initialize RTC
|
||||||
#ifdef HAS_RTC
|
#ifdef HAS_RTC
|
||||||
strcat_P(features, " RTC");
|
strcat_P(features, " RTC");
|
||||||
assert(rtc_init());
|
_ASSERT(rtc_init());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined HAS_DCF77
|
#if defined HAS_DCF77
|
||||||
@ -446,11 +446,13 @@ void setup() {
|
|||||||
strcat_P(features, " BMP180");
|
strcat_P(features, " BMP180");
|
||||||
#endif
|
#endif
|
||||||
if (bme_init())
|
if (bme_init())
|
||||||
ESP_LOGI(TAG, "Starting BME sensor...");
|
ESP_LOGI(TAG, "BME sensor initialized");
|
||||||
|
else
|
||||||
|
ESP_LOGE(TAG, "BME sensor could not be initialized");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// starting timers and interrupts
|
// starting timers and interrupts
|
||||||
assert(irqHandlerTask != NULL); // has interrupt handler task started?
|
_ASSERT(irqHandlerTask != NULL); // has interrupt handler task started?
|
||||||
ESP_LOGI(TAG, "Starting Timers...");
|
ESP_LOGI(TAG, "Starting Timers...");
|
||||||
|
|
||||||
// display interrupt
|
// display interrupt
|
||||||
@ -505,7 +507,7 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Starting Timekeeper...");
|
ESP_LOGI(TAG, "Starting Timekeeper...");
|
||||||
assert(timepulse_init()); // setup pps timepulse
|
_ASSERT(timepulse_init()); // setup pps timepulse
|
||||||
timepulse_start(); // starts pps and cyclic time sync
|
timepulse_start(); // starts pps and cyclic time sync
|
||||||
|
|
||||||
#endif // TIME_SYNC_INTERVAL
|
#endif // TIME_SYNC_INTERVAL
|
||||||
@ -520,4 +522,4 @@ void setup() {
|
|||||||
|
|
||||||
} // setup()
|
} // setup()
|
||||||
|
|
||||||
void loop() { vTaskDelete(NULL); }
|
void loop() { vTaskDelete(NULL); }
|
@ -23,7 +23,7 @@ esp_err_t mqtt_init(void) {
|
|||||||
mqttClient.begin(MQTT_SERVER, MQTT_PORT, netClient);
|
mqttClient.begin(MQTT_SERVER, MQTT_PORT, netClient);
|
||||||
mqttClient.onMessageAdvanced(mqtt_callback);
|
mqttClient.onMessageAdvanced(mqtt_callback);
|
||||||
|
|
||||||
assert(SEND_QUEUE_SIZE);
|
_ASSERT(SEND_QUEUE_SIZE > 0);
|
||||||
MQTTSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
|
MQTTSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
|
||||||
if (MQTTSendQueue == 0) {
|
if (MQTTSendQueue == 0) {
|
||||||
ESP_LOGE(TAG, "Could not create MQTT send queue. Aborting.");
|
ESP_LOGE(TAG, "Could not create MQTT send queue. Aborting.");
|
||||||
|
@ -104,7 +104,7 @@ void spi_slave_task(void *param) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t spi_init() {
|
esp_err_t spi_init() {
|
||||||
assert(SEND_QUEUE_SIZE);
|
_ASSERT(SEND_QUEUE_SIZE > 0);
|
||||||
SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
|
SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
|
||||||
if (SPISendQueue == 0) {
|
if (SPISendQueue == 0) {
|
||||||
ESP_LOGE(TAG, "Could not create SPI send queue. Aborting.");
|
ESP_LOGE(TAG, "Could not create SPI send queue. Aborting.");
|
||||||
|
@ -245,7 +245,7 @@ void clock_init(void) {
|
|||||||
&ClockTask, // task handle
|
&ClockTask, // task handle
|
||||||
1); // CPU core
|
1); // CPU core
|
||||||
|
|
||||||
assert(ClockTask); // has clock task started?
|
_ASSERT(ClockTask != NULL); // has clock task started?
|
||||||
} // clock_init
|
} // clock_init
|
||||||
|
|
||||||
void clock_loop(void *taskparameter) { // ClockTask
|
void clock_loop(void *taskparameter) { // ClockTask
|
||||||
|
@ -45,7 +45,7 @@ IRAM_ATTR void wifi_sniffer_packet_handler(void *buff,
|
|||||||
|
|
||||||
// Software-timer driven Wifi channel rotation callback function
|
// Software-timer driven Wifi channel rotation callback function
|
||||||
void switchWifiChannel(TimerHandle_t xTimer) {
|
void switchWifiChannel(TimerHandle_t xTimer) {
|
||||||
configASSERT(xTimer);
|
_ASSERT(xTimer != NULL);
|
||||||
channel =
|
channel =
|
||||||
(channel % WIFI_CHANNEL_MAX) + 1; // rotate channel 1..WIFI_CHANNEL_MAX
|
(channel % WIFI_CHANNEL_MAX) + 1; // rotate channel 1..WIFI_CHANNEL_MAX
|
||||||
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
|
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
|
||||||
@ -82,7 +82,7 @@ void wifi_sniffer_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void switch_wifi_sniffer(uint8_t state) {
|
void switch_wifi_sniffer(uint8_t state) {
|
||||||
assert(WifiChanTimer);
|
_ASSERT(WifiChanTimer != NULL);
|
||||||
if (state) {
|
if (state) {
|
||||||
// switch wifi sniffer on
|
// switch wifi sniffer on
|
||||||
ESP_ERROR_CHECK(esp_wifi_start());
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
|
Loading…
Reference in New Issue
Block a user