Moved LMiC to dedicated task with raised prio
This commit is contained in:
parent
31cd613555
commit
5dcb3b315e
@ -21,8 +21,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern QueueHandle_t LoraSendQueue;
|
extern QueueHandle_t LoraSendQueue;
|
||||||
|
extern TaskHandle_t lmicTask;
|
||||||
|
|
||||||
esp_err_t lora_stack_init();
|
esp_err_t lora_stack_init();
|
||||||
|
void lmictask(void *pvParameters);
|
||||||
void onEvent(ev_t ev);
|
void onEvent(ev_t ev);
|
||||||
void gen_lora_deveui(uint8_t *pdeveui);
|
void gen_lora_deveui(uint8_t *pdeveui);
|
||||||
void RevBytes(unsigned char *b, size_t c);
|
void RevBytes(unsigned char *b, size_t c);
|
||||||
|
@ -34,6 +34,10 @@ void doHousekeeping() {
|
|||||||
ESP_LOGD(TAG, "IRQhandler %d bytes left | Taskstate = %d",
|
ESP_LOGD(TAG, "IRQhandler %d bytes left | Taskstate = %d",
|
||||||
uxTaskGetStackHighWaterMark(irqHandlerTask),
|
uxTaskGetStackHighWaterMark(irqHandlerTask),
|
||||||
eTaskGetState(irqHandlerTask));
|
eTaskGetState(irqHandlerTask));
|
||||||
|
#if (HAS_LORA)
|
||||||
|
ESP_LOGD(TAG, "LMiCtask %d bytes left | Taskstate = %d",
|
||||||
|
uxTaskGetStackHighWaterMark(lmicTask), eTaskGetState(lmicTask));
|
||||||
|
#endif
|
||||||
#if (HAS_GPS)
|
#if (HAS_GPS)
|
||||||
ESP_LOGD(TAG, "Gpsloop %d bytes left | Taskstate = %d",
|
ESP_LOGD(TAG, "Gpsloop %d bytes left | Taskstate = %d",
|
||||||
uxTaskGetStackHighWaterMark(GpsTask), eTaskGetState(GpsTask));
|
uxTaskGetStackHighWaterMark(GpsTask), eTaskGetState(GpsTask));
|
||||||
|
@ -20,6 +20,7 @@ static const char TAG[] = "lora";
|
|||||||
|
|
||||||
osjob_t sendjob;
|
osjob_t sendjob;
|
||||||
QueueHandle_t LoraSendQueue;
|
QueueHandle_t LoraSendQueue;
|
||||||
|
TaskHandle_t lmicTask = NULL;
|
||||||
|
|
||||||
class MyHalConfig_t : public Arduino_LMIC::HalConfiguration_t {
|
class MyHalConfig_t : public Arduino_LMIC::HalConfiguration_t {
|
||||||
|
|
||||||
@ -423,28 +424,15 @@ esp_err_t lora_stack_init() {
|
|||||||
ESP_LOGI(TAG, "LORA send queue created, size %d Bytes",
|
ESP_LOGI(TAG, "LORA send queue created, size %d Bytes",
|
||||||
SEND_QUEUE_SIZE * sizeof(MessageBuffer_t));
|
SEND_QUEUE_SIZE * sizeof(MessageBuffer_t));
|
||||||
|
|
||||||
|
// starting lorawan stack
|
||||||
ESP_LOGI(TAG, "Starting LMIC...");
|
ESP_LOGI(TAG, "Starting LMIC...");
|
||||||
|
xTaskCreatePinnedToCore(lmictask, // task function
|
||||||
os_init(); // initialize lmic run-time environment on core 1
|
"lmictask", // name of task
|
||||||
LMIC_reset(); // initialize lmic MAC
|
4096, // stack size of task
|
||||||
LMIC_setLinkCheckMode(0);
|
(void *)1, // parameter of the task
|
||||||
// This tells LMIC to make the receive windows bigger, in case your clock is
|
2, // priority of the task
|
||||||
// faster or slower. This causes the transceiver to be earlier switched on,
|
&lmicTask, // task handle
|
||||||
// so consuming more power. You may sharpen (reduce) CLOCK_ERROR_PERCENTAGE
|
1); // CPU core
|
||||||
// in src/lmic_config.h if you are limited on battery.
|
|
||||||
LMIC_setClockError(MAX_CLOCK_ERROR * CLOCK_ERROR_PROCENTAGE / 100);
|
|
||||||
// Set the data rate to Spreading Factor 7. This is the fastest supported
|
|
||||||
// rate for 125 kHz channels, and it minimizes air time and battery power.
|
|
||||||
// Set the transmission power to 14 dBi (25 mW).
|
|
||||||
LMIC_setDrTxpow(DR_SF7, 14);
|
|
||||||
|
|
||||||
#if defined(CFG_US915) || defined(CFG_au921)
|
|
||||||
// in the US, with TTN, it saves join time if we start on subband 1
|
|
||||||
// (channels 8-15). This will get overridden after the join by parameters
|
|
||||||
// from the network. If working with other networks or in other regions,
|
|
||||||
// this will need to be changed.
|
|
||||||
LMIC_selectSubBand(1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!LMIC_startJoining()) { // start joining
|
if (!LMIC_startJoining()) { // start joining
|
||||||
ESP_LOGI(TAG, "Already joined");
|
ESP_LOGI(TAG, "Already joined");
|
||||||
@ -531,4 +519,35 @@ finish:
|
|||||||
} // user_request_network_time_callback
|
} // user_request_network_time_callback
|
||||||
#endif // TIME_SYNC_LORAWAN
|
#endif // TIME_SYNC_LORAWAN
|
||||||
|
|
||||||
|
// LMIC lorawan stack task
|
||||||
|
void lmictask(void *pvParameters) {
|
||||||
|
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
||||||
|
|
||||||
|
os_init(); // initialize lmic run-time environment on core 1
|
||||||
|
LMIC_reset(); // initialize lmic MAC
|
||||||
|
LMIC_setLinkCheckMode(0);
|
||||||
|
// This tells LMIC to make the receive windows bigger, in case your clock is
|
||||||
|
// faster or slower. This causes the transceiver to be earlier switched on,
|
||||||
|
// so consuming more power. You may sharpen (reduce) CLOCK_ERROR_PERCENTAGE
|
||||||
|
// in src/lmic_config.h if you are limited on battery.
|
||||||
|
LMIC_setClockError(MAX_CLOCK_ERROR * CLOCK_ERROR_PROCENTAGE / 100);
|
||||||
|
// Set the data rate to Spreading Factor 7. This is the fastest supported
|
||||||
|
// rate for 125 kHz channels, and it minimizes air time and battery power.
|
||||||
|
// Set the transmission power to 14 dBi (25 mW).
|
||||||
|
LMIC_setDrTxpow(DR_SF7, 14);
|
||||||
|
|
||||||
|
#if defined(CFG_US915) || defined(CFG_au921)
|
||||||
|
// in the US, with TTN, it saves join time if we start on subband 1
|
||||||
|
// (channels 8-15). This will get overridden after the join by parameters
|
||||||
|
// from the network. If working with other networks or in other regions,
|
||||||
|
// this will need to be changed.
|
||||||
|
LMIC_selectSubBand(1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
os_runloop_once(); // execute lmic scheduled jobs and events
|
||||||
|
delay(2); // yield to CPU
|
||||||
|
}
|
||||||
|
} // lmictask
|
||||||
|
|
||||||
#endif // HAS_LORA
|
#endif // HAS_LORA
|
||||||
|
@ -33,9 +33,10 @@ IDLE 0 0 ESP32 arduino scheduler -> runs wifi sniffer
|
|||||||
|
|
||||||
clockloop 1 4 generates realtime telegrams for external clock
|
clockloop 1 4 generates realtime telegrams for external clock
|
||||||
timesync_req 1 3 processes realtime time sync requests
|
timesync_req 1 3 processes realtime time sync requests
|
||||||
irqhandler 1 2 display, timesync, gps, etc. triggered by timers
|
lmictask 1 2 MCCI LMiC LORAWAN stack
|
||||||
gpsloop 1 2 reads data from GPS via serial or i2c
|
irqhandler 1 1 display, timesync, gps, etc. triggered by timers
|
||||||
looptask 1 1 runs the LMIC LoRa stack (arduino loop)
|
gpsloop 1 1 reads data from GPS via serial or i2c
|
||||||
|
looptask 1 1 arduino loop (unused)
|
||||||
IDLE 1 0 ESP32 arduino scheduler -> runs wifi channel rotator
|
IDLE 1 0 ESP32 arduino scheduler -> runs wifi channel rotator
|
||||||
|
|
||||||
Low priority numbers denote low priority tasks.
|
Low priority numbers denote low priority tasks.
|
||||||
@ -268,7 +269,7 @@ void setup() {
|
|||||||
"gpsloop", // name of task
|
"gpsloop", // name of task
|
||||||
2048, // stack size of task
|
2048, // stack size of task
|
||||||
(void *)1, // parameter of the task
|
(void *)1, // parameter of the task
|
||||||
2, // priority of the task
|
1, // priority of the task
|
||||||
&GpsTask, // task handle
|
&GpsTask, // task handle
|
||||||
1); // CPU core
|
1); // CPU core
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user