Page 1 of 2

OSTaskCreate Return Values

Posted: Mon Mar 04, 2019 8:16 am
by tpannone
I'm in the process of updating some MOD5282 code from Dev C++ 1.13 to NBE R2.7.7. The OSTaskCreate() function in one of four NB applications has started generating an error at runtime, returning the value of 70.

From the definition of OSTaskCreate in the uCOSLibrary, the return value is either 0 (Successful) or 40 (Priority already exists). In all of my NB applications, I set the my main loop priority to 23. I've looked at nburn\include\constants.h, and 23 does not interfere with any given system task priorities.

What could a OSTaskCreate return value of 70 mean?

Re: OSTaskCreate Return Values

Posted: Mon Mar 04, 2019 10:57 am
by TomNB
Hello,

All the return codes are in \nburn\include\ucos.h. 70 means you are out of task control blocks, so you may be creating more tasks than the system default limit of 20 (changable in predef.h)

Running your main priority at 23 is very dangerous, but I guess if you have it working somehow your architecture must be ok with it. The reason it is dangerous is that it puts main at a higher priority than all other system tasks such as TCP, IP, HTTP, etc, so your main task will preempt everything in the system. If you have something that is really important to do, the recommended way is to leave main at 50, and spawn a task that does just that one specific thing at such a high priority. But again, you are updating code from DevCpp (which must be 15 years old?), so if it is working for you, you might not want to change it.

Re: OSTaskCreate Return Values

Posted: Mon Mar 04, 2019 11:05 am
by tpannone
Thanks Tom. I'll go back and look at the task control blocks.

This particular application would not need the priority so high, but our control algorithms still need to be higher than those system tasks you mentioned.

Re: OSTaskCreate Return Values

Posted: Mon Mar 04, 2019 11:34 am
by tpannone
Interesting. I only call OSTaskCreate three times in my application. One for the Transmit UDP task, one for the Receive UDP task, and one for the main program loop. The other three create functions (OSTaskCreatewName, OSSimpleTaskCreate, and OSSimpleTaskCreatewName) are not called.

Are you sure predef.h is where the system default task limit is set to 20? There's not much in mine, and no #define statements setting anything to 20.

Re: OSTaskCreate Return Values

Posted: Mon Mar 04, 2019 4:30 pm
by TomNB
If you are running into that problem with creating only 3 tasks, then the number of tasks in prefef is not the problem. My guess is that maybe you made some low level modifications to get your critical code to run faster. Maybe you are doing something with onchip sram? fast vars in sram, etc. Anyway, creating a few tasks on a standard configuration would definitely not create the issue you are seeing.

Re: OSTaskCreate Return Values

Posted: Tue Mar 05, 2019 6:36 am
by tpannone
Thanks again Tom. I'll look at the sram. I am seeing an issue reading back some data from flash at startup. I didn't think the two issues were related, but maybe they are.

Re: OSTaskCreate Return Values

Posted: Fri Mar 08, 2019 5:50 am
by tpannone
Hi Tom,

I made a stupid mistake saying that this application has only 3 tasks created. It's more like 15. Most of those Transmit UDP and Receive UDP task creates were in a for loop.

Anyway, you said that the default limit for tasks is set to 20 in predef.h. I must be missing something because I do not see it in my copy of predef.h. I'm attaching my copy hoping you can point out where it is.

Re: OSTaskCreate Return Values

Posted: Fri Mar 08, 2019 7:20 am
by ephogy
I think it might be in constants.h:

#define OS_MAX_TASKS 20 /* Max number of system tasks */

Re: OSTaskCreate Return Values

Posted: Fri Mar 08, 2019 7:29 am
by tpannone
Yep... there it is. Thanks.

Re: OSTaskCreate Return Values

Posted: Fri Mar 08, 2019 8:01 am
by tpannone
Interesting. Now that I know where OS_MAX_TASKS is defined, I checked it in my old Dev C++ 1.13. There it is set to 25.

I'll bump it up to 25 in NBE 2.7.7 and see if it works.