Chat freely about anything...

User avatar
By bicli
#7874 Hello everyone, I've been trying to understand how the task mechanism works but couldn't figure it out.
Specifically, what happens if I create 3 tasks of the same priority? Which one gets the message, when I make a system_os_post call?

As an example, I created 3 tasks with the same priority.
Code: Select all  system_os_task(WIFI_Connection, WIFI_TASK_PRIO, wifi_procTaskQueue, WIFI_TASK_QUEUE_SIZE);
  system_os_task(WIFI_Connection1, WIFI_TASK_PRIO, wifi_procTaskQueue, WIFI_TASK_QUEUE_SIZE);
  system_os_task(WIFI_Connection2, WIFI_TASK_PRIO, wifi_procTaskQueue, WIFI_TASK_QUEUE_SIZE);


And then in a timer, make following calls:
Code: Select all    system_os_post(WIFI_TASK_PRIO, 0xAB, (os_param_t)0);
    system_os_post(WIFI_TASK_PRIO, 0xCD, (os_param_t)0);   
    system_os_post(WIFI_TASK_PRIO, 0xEF, (os_param_t)0);


And my tasks do nothing but the following:
Code: Select allvoid ICACHE_FLASH_ATTR WIFI_Connection(os_event_t *e)
{
  if(e->sig == 0xAB)
  {
    os_printf("WIFI_Connection 0xAB\r\n");
  }
}
void ICACHE_FLASH_ATTR WIFI_Connection1(os_event_t *e)
{
  if(e->sig == 0xCD)
  {
    os_printf("WIFI_Connection1 0xCD\r\n");
  }
}
void ICACHE_FLASH_ATTR WIFI_Connection2(os_event_t *e)
{
  if(e->sig == 0xEF)
  {
    os_printf("WIFI_Connection2 0xEF\r\n");
  }
}


What happens is, only the last "created" task gets the post. The others are not invoked at all.
Can somebody help me understand this?
What is the purpose of having a "sig" parameter in
Code: Select allsystem_os_post(uint8 prio, os_signal_t sig, os_param_t par);
User avatar
By kadamski
#9190 I think you answered part of your question yourself - you said that if you register several tasks with the same priority then only the last one of them is executed.

As for the second part - check the argument the task function gets - it's a pointer to os_event_t, which is defined like this in SDK:

Code: Select all#define os_event_t ETSEvent
typedef struct ETSEventTag ETSEvent;


So it's actually a struct ETSEventTag that you get:
Code: Select allstruct ETSEventTag {
    ETSSignal sig;
    ETSParam  par;
};


And here you can see that the structure you get pointer to has two fields - sig and par which is exactly what you specify on system_os_post call. So if you post your task like this:

Code: Select allsystem_os_post(WIFI_TASK_PRIO, 10, 11);


You will get 10 in e->sig and 11 in e->par inside of your task function.
User avatar
By kolban
#22471 If we look in the SDK API guide for system_os_task(), we see that it contains:

Code: Select alluint8 prio : task priority. 3 priorities are supported: 0/1/2;
0 is the lowest priority. This means only 3 tasks is allowed to set up.


This seems to confirm what the thread has said and that one can only register one task function per priority.