Page 1 of 1

Task Switching

Posted: Wed Mar 25, 2020 12:03 pm
by SeeCwriter
writing a new project using a MOD5441X and v2.9.2. of the tools.

Setting task priorities as

Code: Select all

#define MAIN_PRIORITY         56
#define FTP_PRIO              (MAIN_PRIORITY-1)
#define OLED1_TASK_PRIO       (MAIN_PRIORITY-2)
#define OLED2_TASK_PRIO       (MAIN_PRIORITY-3)
#define UDP_TASK_PRIO         (MAIN_PRIORITY-4)
#endif
the UDP Task doesn't run unless OSTimeDly(0) is put in the main loop of Usermain. If Usermain is set to 50 instead of 56,
OSTimeDly() is not needed.
What is going on? A few more tasks are needed and starting at priority 50 doesn't leave enough task priorities to use.

Re: Task Switching

Posted: Wed Mar 25, 2020 12:16 pm
by dciliske
Where are you defining your priorities?

The system Task Priorities are set in 'include/constants.h'. Additionally, UserMain which runs at the MAIN_PRIO which is 50 by default. So, by your defines, that puts UDP_TASK_PRIO at 52, which is lower priority than UserMain.

Re: Task Switching

Posted: Wed Mar 25, 2020 12:22 pm
by SeeCwriter
Usermain priority is set at powerup initialization with

Code: Select all

OSChangePrio(MAIN_PRIORITY);

Re: Task Switching

Posted: Wed Mar 25, 2020 12:24 pm
by TomNB
A second item would be are you using OSSimpleTaskCreatewName() or the standard OSTaskeCreate() ? If simple, I would switch to the standard call and make sure to test the return value for success or failure. If a task already exists at that level the create call will fail.

Re: Task Switching

Posted: Thu Mar 26, 2020 1:07 pm
by SeeCwriter
No errors are returned from OSTaskCreate() when setting the priority to 56 or 55. Just that the other task doesn't run unless OSTimeDly() is present in Usermain's main loop. Priority 54 works though. Go figure.

Re: Task Switching

Posted: Thu Mar 26, 2020 2:12 pm
by pbreed
What does task scan show?

How are you allocating your task stacks?

Re: Task Switching

Posted: Tue Mar 31, 2020 6:58 am
by SeeCwriter
I haven't found task scan to be helpful. Using the default task stack. Tried using OSDumpTasks(), but got lots of compile errors rebuilding the system library for debug. Tried to restore to a non-debug, now my application compiles but I get many link errors. And each time a rebuild there are a different number of errors. First 31 link errors, then 12 file not found errors, etc.
Removed the installation, and restored the tools from a backup. Everything compiles and links again. But priority 54 no longer works. Since the reason for this was to be able to use threads beyond the small sandbox of 46-50, the following function was written. It's used after all Netburner tasks are created. So far, it seems to work.

Code: Select all

BYTE CreateTask(void (* task)(void *taskfunc), void *data, void *stacktop, void *stackbot)
  {
  for (BYTE priority=MAIN_PRIORITY-1; priority>1; priority--)
     if (OSTaskCreate(task, data, stacktop, stackbot, priority) == OS_NO_ERR)
        return priority;
  return 64;  // Legal priorities are 1-63.
  }