reset.cpp lora code sanitization

This commit is contained in:
cyberman54 2022-11-20 17:17:07 +01:00
parent cbdad346ca
commit 3df387a207
3 changed files with 16 additions and 11 deletions

View File

@ -37,6 +37,7 @@ void os_getDevEui(u1_t *buf);
void lora_send(void *pvParameters); void lora_send(void *pvParameters);
void lora_enqueuedata(MessageBuffer_t *message); void lora_enqueuedata(MessageBuffer_t *message);
void lora_queuereset(void); void lora_queuereset(void);
void lora_waitforidle(uint16_t timeout_sec);
uint32_t lora_queuewaiting(void); uint32_t lora_queuewaiting(void);
void myEventCallback(void *pUserData, ev_t ev); void myEventCallback(void *pUserData, ev_t ev);
void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg, void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,

View File

@ -334,6 +334,18 @@ uint32_t lora_queuewaiting(void) {
return uxQueueMessagesWaiting(LoraSendQueue); return uxQueueMessagesWaiting(LoraSendQueue);
} }
// blocking wait until LMIC is idle
void lora_waitforidle(uint16_t timeout_sec) {
ESP_LOGI(TAG, "Waiting until LMIC is idle...");
for (int i = timeout_sec; i > 0; i--) {
if ((LMIC.opmode & (OP_JOINING | OP_TXDATA | OP_POLL | OP_TXRXPEND)) ||
os_queryTimeCriticalJobs(sec2osticks(timeout_sec)))
vTaskDelay(pdMS_TO_TICKS(1000));
else
break;
}
}
// LMIC loop task // LMIC loop task
void lmictask(void *pvParameters) { void lmictask(void *pvParameters) {
_ASSERT((uint32_t)pvParameters == 1); _ASSERT((uint32_t)pvParameters == 1);

View File

@ -88,7 +88,6 @@ void enter_deepsleep(const uint32_t wakeup_sec, gpio_num_t wakeup_gpio) {
ESP_LOGI(TAG, "Preparing to sleep..."); ESP_LOGI(TAG, "Preparing to sleep...");
RTC_runmode = RUNMODE_SLEEP; RTC_runmode = RUNMODE_SLEEP;
int i;
// validate wake up pin, if we have // validate wake up pin, if we have
if (!GPIO_IS_VALID_GPIO(wakeup_gpio)) if (!GPIO_IS_VALID_GPIO(wakeup_gpio))
@ -108,22 +107,15 @@ void enter_deepsleep(const uint32_t wakeup_sec, gpio_num_t wakeup_gpio) {
// wait a while (max 100 sec) to clear send queues // wait a while (max 100 sec) to clear send queues
ESP_LOGI(TAG, "Waiting until send queues are empty..."); ESP_LOGI(TAG, "Waiting until send queues are empty...");
for (i = 100; i > 0; i--) { for (int i = 100; i > 0; i--) {
if (allQueuesEmtpy()) if (allQueuesEmtpy())
break; break;
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
} }
/// wait until LMIC is idle // wait up to 100secs until LMIC is idle
#if (HAS_LORA) #if (HAS_LORA)
ESP_LOGI(TAG, "Waiting until LMIC is idle..."); lora_waitforidle(100);
for (i = 100; i > 0; i--) {
if ((LMIC.opmode & (OP_JOINING | OP_TXDATA | OP_POLL | OP_TXRXPEND)) ||
os_queryTimeCriticalJobs(sec2osticks(wakeup_sec)))
vTaskDelay(pdMS_TO_TICKS(1000));
else
break;
}
#endif // (HAS_LORA) #endif // (HAS_LORA)
// shutdown MQTT safely // shutdown MQTT safely