Unable to write pointer from xQueueRecieve
Posted: Thu Dec 02, 2021 7:00 pm
The crux of my issue is that I am unable to increment a value on a pointer to a typedef struct that is acquired from xQueueRecieve. The setup is a very standard long running task that waits for xQueueReceive to be fed from the GPIO ISR. The entirety of the code can be found here and I will call out lines and provide snippets here to describe the flow.
Here's the problematic section. Starting here.
In this snippet lora->channel does increment but the next time the interrupt is called it's back to 0. Note this is a stripped down version of the task and all pointer reads seem to work fine.
One of my suspicions is the malloc at the start but I'm unable to think of another way to handle multiple devices with a single task. Another area of concern is the path the pointer takes. The setup start around line 583. Here the lora32_cfg_t is passed to the ISR handler, which simple passes it along with xQueueSend, doing nothing else.
Line 583
Line 449
Note: Changing this to xQueueSendFromISR does not fix the problem.
I'm pretty stumped by this one, when reading all the data seems fine and intact but writing back to the pointer clearly isn't working. Any insight would be appreciated and I'll keep updating this for clarification as I get back to hacking.
Here's the problematic section. Starting here.
Code: Select all
// allocate lora32_cfg_t to receive config from Queue
lora32_cfg_t *lora = malloc(sizeof(lora32_cfg_t));
while(1) {
// wait for event over Queue
if(xQueueReceive(dio_event_queue, (void*)lora, portMAX_DELAY) != pdPASS) continue;
lora32_set_frequency(lora, lora->frequency + (lora->channels[lora->channel] * bandwidths[lora->bandwidth]));
lora->channel++;
}
One of my suspicions is the malloc at the start but I'm unable to think of another way to handle multiple devices with a single task. Another area of concern is the path the pointer takes. The setup start around line 583. Here the lora32_cfg_t is passed to the ISR handler, which simple passes it along with xQueueSend, doing nothing else.
Line 583
Code: Select all
gpio_isr_handler_add(lora->dio0, lora32_on_dio, (void*)lora);
Code: Select all
static void IRAM_ATTR lora32_on_dio(void *arg) {
xQueueSend(dio_event_queue, arg, (TickType_t)0);
}
I'm pretty stumped by this one, when reading all the data seems fine and intact but writing back to the pointer clearly isn't working. Any insight would be appreciated and I'll keep updating this for clarification as I get back to hacking.