xQueueReceive() won't get correct payload from xQueueSendToBack()
xQueueReceive() won't get correct payload from xQueueSendToBack()
Hi ESP-IDF,
The titel of the question is not precise. The geniue one is:
Why the initialization order / nested relationship of tasks can cause the same task definitions have / don't have correct intertask communications implementated with Queue?
I have a bunch of Tasks that need intertask communications between them. Since I'd prefer to start them in a sequncial way. I may wanna nest some of them into others, or change the order of their initialization. But I did figured out, that I won
t got compiling time issue (Compiler get compiled correctely), but when I log some problematical queues' content, I can not find correct payload in there.
Perhaps the xQueueReceive() would get called before xQueueSendToBack(), or the queue is filled up before the task that consum the payload in the queue get inited. Should these issues be seen as problem? Or should be something else?
Thanks!
Gfast2
The titel of the question is not precise. The geniue one is:
Why the initialization order / nested relationship of tasks can cause the same task definitions have / don't have correct intertask communications implementated with Queue?
I have a bunch of Tasks that need intertask communications between them. Since I'd prefer to start them in a sequncial way. I may wanna nest some of them into others, or change the order of their initialization. But I did figured out, that I won
t got compiling time issue (Compiler get compiled correctely), but when I log some problematical queues' content, I can not find correct payload in there.
Perhaps the xQueueReceive() would get called before xQueueSendToBack(), or the queue is filled up before the task that consum the payload in the queue get inited. Should these issues be seen as problem? Or should be something else?
Thanks!
Gfast2
Re: xQueueReceive() won't get correct payload from xQueueSendToBack()
Hi my friend, I read the post a couple of times but I'm afraid I'm not following it. It might just be me ... but just in case, maybe try some alternate words or phrases ... maybe some additional descriptions of the puzzle?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: xQueueReceive() won't get correct payload from xQueueSendToBack()
Hi Kolban,kolban wrote:Hi my friend, I read the post a couple of times but I'm afraid I'm not following it. It might just be me ... but just in case, maybe try some alternate words or phrases ... maybe some additional descriptions of the puzzle?
Thanks for telling me that I don't make my question clear. I'm a chinese, when I'm at work, I speaking Germany. If I wanna post something in the forum, I figured out I'm really not sure if the grammtic is still somehow to correct one for english.
Say I have taskA and taskB. taskA will send message to taskB through xQueue. Basically there are three possible way to init them:
Possible way One
Code: Select all
main_app(){
xTaskCreatePinnedToCore(taskA, "taskA", 2048, NULL, 10, NULL, 0);
xTaskCreatePinnedToCore(taskB, "taskB", 2048, NULL, 10, NULL, 0);
}
Init the taskA firstly
Code: Select all
main_app(){
xTaskCreatePinnedToCore(taskA, "taskA", 2048, NULL, 10, NULL, 0);
}
Code: Select all
void taskA(void *pvParameters) {
// Till everything finished, then create taskB
xTaskCreatePinnedToCore(taskB, "taskB", 2048, NULL, 10, NULL, 0);
while(1){
// From here I will send information to taskB if there is any.
vTaskDelay(5/portTICK_RATE_MS);
}
}
Init the taskB firstly
Code: Select all
main_app(){
xTaskCreatePinnedToCore(taskB, "taskB", 2048, NULL, 10, NULL, 0);
}
Code: Select all
void taskA(void *pvParameters) {
// Till everything finished, then create taskB
xTaskCreatePinnedToCore(taskA, "taskA", 2048, NULL, 10, NULL, 0);
while(1){
// From here I will receive information to taskA if there is any.
vTaskDelay(5/portTICK_RATE_MS);
}
}
Say, Is that OK, After I define the queue with xQueueCreate() the init the receiver before I init sender for the queue?
Thanks
Gfast2
Re: xQueueReceive() won't get correct payload from xQueueSendToBack()
Howdy,
In your post, you show different techniques for starting tasks. Ok ... I see that ... but I'm missing the problem. You can start Task A and then Task B or you can start Task B and the Task A ... or you can start Task A and at the end of Task A start Task B ... or you can start Task B and at the end of Task B start Task A ... but I'm not seeing the core of the question. What is the puzzle that you are trying to solve? I'm not seeing anything to attempt to answer yet.
In your post, you show different techniques for starting tasks. Ok ... I see that ... but I'm missing the problem. You can start Task A and then Task B or you can start Task B and the Task A ... or you can start Task A and at the end of Task A start Task B ... or you can start Task B and at the end of Task B start Task A ... but I'm not seeing the core of the question. What is the puzzle that you are trying to solve? I'm not seeing anything to attempt to answer yet.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: xQueueReceive() won't get correct payload from xQueueSendToBack()
Hi Kolban,kolban wrote:Howdy,
In your post, you show different techniques for starting tasks. Ok ... I see that ... but I'm missing the problem. You can start Task A and then Task B or you can start Task B and the Task A ... or you can start Task A and at the end of Task A start Task B ... or you can start Task B and at the end of Task B start Task A ... but I'm not seeing the core of the question. What is the puzzle that you are trying to solve? I'm not seeing anything to attempt to answer yet.
I really preciate your help here!
Task A will send Task B messages, but in my observation, I found the messages in the queue is changing, but only rubishes.
But later I changed the initiation order of these Tasks, the queue that hold the messages work as they should again...
So I'd wanna know if some one experienced the samething before.
Re: xQueueReceive() won't get correct payload from xQueueSendToBack()
Aha!! Ok ... gotcha now. So you have two tasks, A and B and you wish task A to "publish" a message and task "B" to receive the message.
My thinking on high level pseudo code would be:
My thinking on high level pseudo code would be:
Code: Select all
static QueueHandle_t queueHandle;
void init() {
queueHandle = xQueueCreate(maxNumberOfQueueItems, sizeof(queueItem));
createTaskA(taskA);
createTaskB(taskB);
}
void taskA() {
// do something
xQueueSendToBack(queueHandle, &item, 0);
}
void taskB() {
xQueueReceive(queueHandle, &item);
// process item here
}
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: xQueueReceive() won't get correct payload from xQueueSendToBack()
Hi Kolban,kolban wrote:Aha!! Ok ... gotcha now. So you have two tasks, A and B and you wish task A to "publish" a message and task "B" to receive the message.
My thinking on high level pseudo code would be:
Code: Select all
static QueueHandle_t queueHandle; void init() { queueHandle = xQueueCreate(maxNumberOfQueueItems, sizeof(queueItem)); createTaskA(taskA); createTaskB(taskB); } void taskA() { // do something xQueueSendToBack(queueHandle, &item, 0); } void taskB() { xQueueReceive(queueHandle, &item); // process item here }
Thanks again for your declaration!!! Really appreciate your help!
You have a very clear pseudo code for me. But I think the problem I experienced is something caused by "Round Robin Scheduling". If I create taskes using "xTaskCreatePinnedToCore(tsk_callback, “APP_CPU Task”, 1000, NULL, 10, NULL, coreID)" , according to the description in that doc. I might have something wrong in my implementation. Becasue
So I believe I have two options to work around: Always define tasks with different priorities, or always use tskNO_AFFINITY as the argument coreID, in order to let the code run as I expected.the ESP-IDF FreeRTOS scheduler may skip tasks when Round Robin scheduling multiple Ready state tasks of the same priority.
The following pic is somehow show to possible problem that I hat:
Cheers
Gfast2
Re: xQueueReceive() won't get correct payload from xQueueSendToBack()
Howdy,
I think I'm confused again I had understood the puzzle was having two tasks run and the ability to pass data from one to the other?
In your story about round robin scheduling and priorities, that area talks about "when a task will run" and doesn't talk to the notion of passing data from one to the other.
Assuming you have created a queue and assuming you have created tasks A and B and task A places a message in the queue, I would assume Task B would be able to read it. Unless you have some special needs that I'm not seeing, I would create tasks A and B with equal priority and with no CPU core affinity. To the best of my knowledge, queues are able to be read and written by a task on the same core or on different cores.
Maybe if you create the absolute minimum sample application and post a link to the source on PasteBin containing a detailed description of the error and a second PasteBin of the console logs showing the error ... it might help.
I think I'm confused again I had understood the puzzle was having two tasks run and the ability to pass data from one to the other?
In your story about round robin scheduling and priorities, that area talks about "when a task will run" and doesn't talk to the notion of passing data from one to the other.
Assuming you have created a queue and assuming you have created tasks A and B and task A places a message in the queue, I would assume Task B would be able to read it. Unless you have some special needs that I'm not seeing, I would create tasks A and B with equal priority and with no CPU core affinity. To the best of my knowledge, queues are able to be read and written by a task on the same core or on different cores.
Maybe if you create the absolute minimum sample application and post a link to the source on PasteBin containing a detailed description of the error and a second PasteBin of the console logs showing the error ... it might help.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: xQueueReceive() won't get correct payload from xQueueSendToBack()
Hi Kolban,
Thanks a lot for your patient and Reply again!
I just forgot to commit my change when I had this problem. If I found the same issue in the up comming development, I will do share the code here! Thanks again!
Thanks a lot for your patient and Reply again!
I just forgot to commit my change when I had this problem. If I found the same issue in the up comming development, I will do share the code here! Thanks again!
Who is online
Users browsing this forum: No registered users and 108 guests