mirror of
https://github.com/manuelbl/ttn-esp32.git
synced 2025-07-28 03:52:52 +02:00
Add shutdown function
This commit is contained in:
@ -97,6 +97,7 @@ void ttn_provisioning_task_caller(void* pvParameter)
|
||||
{
|
||||
TTNProvisioning* provisioning = (TTNProvisioning*)pvParameter;
|
||||
provisioning->provisioningTask();
|
||||
vTaskDelete(nullptr);
|
||||
}
|
||||
|
||||
void TTNProvisioning::provisioningTask()
|
||||
@ -132,7 +133,6 @@ void TTNProvisioning::provisioningTask()
|
||||
|
||||
free(line_buf);
|
||||
uart_driver_delete(UART_NUM);
|
||||
vTaskDelete(nullptr);
|
||||
}
|
||||
|
||||
void TTNProvisioning::addLineData(int numBytes)
|
||||
|
@ -111,10 +111,23 @@ void TheThingsNetwork::reset()
|
||||
ttn_hal.enterCriticalSection();
|
||||
LMIC_reset();
|
||||
waitingReason = eWaitingNone;
|
||||
if (lmicEventQueue != nullptr)
|
||||
{
|
||||
xQueueReset(lmicEventQueue);
|
||||
}
|
||||
ttn_hal.leaveCriticalSection();
|
||||
}
|
||||
|
||||
void TheThingsNetwork::shutdown()
|
||||
{
|
||||
ttn_hal.enterCriticalSection();
|
||||
LMIC_shutdown();
|
||||
ttn_hal.stopLMICTask();
|
||||
waitingReason = eWaitingNone;
|
||||
ttn_hal.leaveCriticalSection();
|
||||
}
|
||||
|
||||
void TheThingsNetwork::startup()
|
||||
{
|
||||
ttn_hal.enterCriticalSection();
|
||||
LMIC_reset();
|
||||
ttn_hal.startLMICTask();
|
||||
ttn_hal.leaveCriticalSection();
|
||||
}
|
||||
|
||||
@ -194,6 +207,7 @@ bool TheThingsNetwork::joinCore()
|
||||
}
|
||||
|
||||
ttn_hal.enterCriticalSection();
|
||||
xQueueReset(lmicEventQueue);
|
||||
waitingReason = eWaitingForJoin;
|
||||
LMIC_startJoining();
|
||||
ttn_hal.wakeUp();
|
||||
|
@ -25,6 +25,7 @@
|
||||
#define NOTIFY_BIT_DIO 1
|
||||
#define NOTIFY_BIT_TIMER 2
|
||||
#define NOTIFY_BIT_WAKEUP 4
|
||||
#define NOTIFY_BIT_STOP 8
|
||||
|
||||
|
||||
static const char* const TAG = "ttn_hal";
|
||||
@ -305,6 +306,9 @@ bool HAL_ESP32::wait(WaitKind waitKind)
|
||||
if (bits == 0)
|
||||
return false;
|
||||
|
||||
if ((bits & NOTIFY_BIT_STOP) != 0)
|
||||
return false;
|
||||
|
||||
if ((bits & NOTIFY_BIT_WAKEUP) != 0)
|
||||
{
|
||||
if (waitKind != WAIT_FOR_TIMER)
|
||||
@ -449,8 +453,12 @@ void HAL_ESP32::leaveCriticalSection()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void HAL_ESP32::lmicBackgroundTask(void* pvParameter) {
|
||||
os_runloop();
|
||||
void HAL_ESP32::lmicBackgroundTask(void* pvParameter)
|
||||
{
|
||||
HAL_ESP32* instance = (HAL_ESP32*)pvParameter;
|
||||
while (instance->runBackgroundTask)
|
||||
os_runloop_once();
|
||||
vTaskDelete(nullptr);
|
||||
}
|
||||
|
||||
void hal_init_ex(const void *pContext)
|
||||
@ -468,14 +476,25 @@ void HAL_ESP32::init()
|
||||
timerInit();
|
||||
}
|
||||
|
||||
void HAL_ESP32::startLMICTask() {
|
||||
xTaskCreate(lmicBackgroundTask, "ttn_lmic", 1024 * 4, nullptr, CONFIG_TTN_BG_TASK_PRIO, &lmicTask);
|
||||
void HAL_ESP32::startLMICTask()
|
||||
{
|
||||
runBackgroundTask = true;
|
||||
xTaskCreate(lmicBackgroundTask, "ttn_lmic", 1024 * 4, this, CONFIG_TTN_BG_TASK_PRIO, &lmicTask);
|
||||
|
||||
// enable interrupts
|
||||
gpio_isr_handler_add(pinDIO0, dioIrqHandler, (void *)0);
|
||||
gpio_isr_handler_add(pinDIO1, dioIrqHandler, (void *)1);
|
||||
}
|
||||
|
||||
void HAL_ESP32::stopLMICTask()
|
||||
{
|
||||
runBackgroundTask = false;
|
||||
gpio_isr_handler_remove(pinDIO0);
|
||||
gpio_isr_handler_remove(pinDIO1);
|
||||
disarmTimer();
|
||||
xTaskNotify(lmicTask, NOTIFY_BIT_STOP, eSetBits);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Fatal failure
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
void configurePins(spi_host_device_t spi_host, uint8_t nss, uint8_t rxtx, uint8_t rst, uint8_t dio0, uint8_t dio1);
|
||||
void init();
|
||||
void startLMICTask();
|
||||
void stopLMICTask();
|
||||
|
||||
void wakeUp();
|
||||
void initCriticalSection();
|
||||
@ -84,6 +85,7 @@ private:
|
||||
SemaphoreHandle_t mutex;
|
||||
esp_timer_handle_t timer;
|
||||
int64_t nextAlarm;
|
||||
volatile bool runBackgroundTask;
|
||||
};
|
||||
|
||||
extern HAL_ESP32 ttn_hal;
|
||||
|
Reference in New Issue
Block a user