Task Switching

Discussion to talk about software related topics only.
Post Reply
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Task Switching

Post 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.
User avatar
dciliske
Posts: 623
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Task Switching

Post 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.
Dan Ciliske
Project Engineer
Netburner, Inc
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Task Switching

Post by SeeCwriter »

Usermain priority is set at powerup initialization with

Code: Select all

OSChangePrio(MAIN_PRIORITY);
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Task Switching

Post 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.
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Task Switching

Post 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.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Task Switching

Post by pbreed »

What does task scan show?

How are you allocating your task stacks?
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Task Switching

Post 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.
  }
Post Reply