move lmic os sendjob to new lora_send task

This commit is contained in:
Verkehrsrot 2019-08-29 10:13:47 +02:00
parent 9e42de67bd
commit 258e830470
3 changed files with 30 additions and 24 deletions

View File

@ -34,7 +34,7 @@ void os_getArtEui(u1_t *buf);
void os_getDevEui(u1_t *buf);
void showLoraKeys(void);
void switch_lora(uint8_t sf, uint8_t tx);
void lora_send(osjob_t *job);
void lora_send(void *pvParameters);
void lora_enqueuedata(MessageBuffer_t *message);
void lora_queuereset(void);
#if (TIME_SYNC_LORAWAN)

View File

@ -18,9 +18,8 @@ static const char TAG[] = "lora";
#endif
#endif
osjob_t sendjob;
QueueHandle_t LoraSendQueue;
TaskHandle_t lmicTask = NULL;
TaskHandle_t lmicTask = NULL, lorasendTask = NULL;
class MyHalConfig_t : public Arduino_LMIC::HalConfiguration_t {
@ -218,8 +217,6 @@ void onEvent(ev_t ev) {
// Set data rate and transmit power (note: txpower seems to be ignored by
// the library)
switch_lora(cfg.lorasf, cfg.txpower);
// kickoff first send job
os_setCallback(&sendjob, lora_send);
// show effective LoRa parameters after join
ESP_LOGI(TAG, "DEVaddr=%08X", LMIC.devaddr);
break;
@ -248,11 +245,6 @@ void onEvent(ev_t ev) {
: PSTR("TX COMPLETE"));
sprintf(display_line6, " "); // clear previous lmic status
// schedule next transmission with some random delay to prevent systematic
// collisions
os_setTimedCallback(&sendjob, os_getTime() + ms2osticks(random(500)),
lora_send);
if (LMIC.dataLen) { // did we receive payload data -> display info
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d",
LMIC.dataLen, LMIC.rssi, LMIC.snr / 4);
@ -394,23 +386,27 @@ void switch_lora(uint8_t sf, uint8_t tx) {
}
}
void lora_send(osjob_t *job) {
// LMIC send task
void lora_send(void *pvParameters) {
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
MessageBuffer_t SendBuffer;
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
ESP_LOGE(TAG, "LMIC busy, data not sent and lost");
return;
}
while (1) {
// fetch next / wait for payload to send from queue
if (xQueueReceive(LoraSendQueue, &SendBuffer, portMAX_DELAY) == pdTRUE) {
// fetch next payload to send from queue or wait until new payload shows up in
// queue
if (xQueueReceive(LoraSendQueue, &SendBuffer, portMAX_DELAY) == pdTRUE) {
if (LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
SendBuffer.MessageSize, (cfg.countermode & 0x02)) == 0)
ESP_LOGI(TAG, "%d byte(s) delivered to LMIC", SendBuffer.MessageSize);
else
lora_enqueuedata(&SendBuffer); // re-enqueue unsent message
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND)
lora_enqueuedata(&SendBuffer); // LMIC stack busy
else if (LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
SendBuffer.MessageSize,
(cfg.countermode & 0x02)) == 0)
ESP_LOGI(TAG, "%d byte(s) delivered to LMIC", SendBuffer.MessageSize);
else
lora_enqueuedata(&SendBuffer); // LMIC stack denied tx
}
delay(2); // yield to CPU
}
}
@ -434,6 +430,15 @@ esp_err_t lora_stack_init() {
&lmicTask, // task handle
1); // CPU core
// starting lmic send task
xTaskCreatePinnedToCore(lora_send, // task function
"lorasendtask", // name of task
2048, // stack size of task
(void *)1, // parameter of the task
2, // priority of the task
&lorasendTask, // task handle
1); // CPU core
if (!LMIC_startJoining()) { // start joining
ESP_LOGI(TAG, "Already joined");
}

View File

@ -36,6 +36,7 @@ timesync_req 1 3 processes realtime time sync requests
lmictask 1 2 MCCI LMiC LORAWAN stack
irqhandler 1 1 display, timesync, gps, etc. triggered by timers
gpsloop 1 1 reads data from GPS via serial or i2c
lorasendtask 1 1 feed data from lora sendqueue to lmcic
IDLE 1 0 ESP32 arduino scheduler -> runs wifi channel rotator
Low priority numbers denote low priority tasks.