Threads

Discussion to talk about software related topics only.
ckoehler
Posts: 81
Joined: Sat Mar 13, 2010 9:04 pm

Threads

Post by ckoehler »

Hello,

Just getting started with a Netburner board and wondering how to write threaded applications. Couldn't find anything on the forums about that.

Thanks!

Christoph
User avatar
yevgenit
Posts: 84
Joined: Fri Apr 25, 2008 12:47 am
Contact:

Re: Threads

Post by yevgenit »

Start to learn threaded applications from the NB examples.
ckoehler wrote: Just getting started with a Netburner board and wondering how to write threaded applications. Couldn't find anything on the forums about that.
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: Threads

Post by v8dave »

Netburner doesn't have threads as such.

What you have is UCOS tasks. Check in the examples directory under UCOS ofr OSMultiTaskUserInput as this shows how it is done.

Be careful with your priorities with UCOS. Lower priority tasks will not run unless higher priority tasks yield (I use OSTimeDly() calls to do this) or block with semaphores, flags etc.

Dave...
User avatar
Forrest
Posts: 286
Joined: Wed Apr 23, 2008 10:05 am

Re: Threads

Post by Forrest »

v8dave wrote: Be careful with your priorities with UCOS. Lower priority tasks will not run unless higher priority tasks yield (I use OSTimeDly() calls to do this) or block with semaphores, flags etc.
Also remember that priority numbering is reversed. (ie priority 10 is higher then priority 50)
Forrest Stanley
Project Engineer
NetBurner, Inc

NetBurner Learn Articles: http://www.netburner.com/learn
ckoehler
Posts: 81
Joined: Sat Mar 13, 2010 9:04 pm

Re: Threads

Post by ckoehler »

Thanks guys, that makes sense.

Appreciate it!

Christoph
User avatar
lgitlitz
Posts: 331
Joined: Wed Apr 23, 2008 11:43 am
Location: San Diego, CA
Contact:

Re: Threads

Post by lgitlitz »

You should probably take a look at the ucos chapter in the programmers guide:
C:\nburn\docs\NetworkProgrammersGuide\NNDKProgMan.pdf
ckoehler
Posts: 81
Joined: Sat Mar 13, 2010 9:04 pm

Re: Threads

Post by ckoehler »

Yeah I found that. Looks pretty powerful. Will be playing around with it soon.

From what I've read so far, I have to give it a function. I guess that means it can't be an object method, right? It has to be either a proper function or a static class method?

Thanks again!

Christoph
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Threads

Post by tod »

NO! That's not true, it can be a member method. See the wiki article on how to use a member method in an ucOS call.
ckoehler
Posts: 81
Joined: Sat Mar 13, 2010 9:04 pm

Re: Threads

Post by ckoehler »

Good to know, thanks!
ckoehler
Posts: 81
Joined: Sat Mar 13, 2010 9:04 pm

Re: Threads

Post by ckoehler »

Hm I tried the Wiki trick and can't get it to work. I get:
"argument of type 'void (DataController::)(void*)' does not match 'void(*)(void*)'"
on the OSTaskCreate line.

Any ideas?

Code: Select all

#include "DataController.h"

// Make sure they're 4 byte aligned to keep the Coldfire happy
asm( " .align 4 " );
DWORD TaskStack[256] __attribute__( ( aligned( 4 ) ) );

//Call this Class member function instead of directly calling OSTaskCreate
void DataController::startup()
{
   const BYTE os_err = OSTaskCreate(initialize_wrapper, this, (void*) &TaskStack[256], (void*) TaskStack, MAIN_PRIO+1);
   //check os_err for OS_NO_ERR or OS_PRIO_EXIST or whatever level of error handling you want here
}

//Wrap what would have been your old static or C function in this method
void DataController::initialize_wrapper(void* const pTaskObject)
{
    static_cast<DataController*> (pTaskObject)->initialize(0);
}

//This is the method that was originally passed directly when
//it was a C function or a static method.
void DataController::initialize(const void * const pd)
{
//In here you do all the things you want this task to do.
	iprintf("Hello World!");
}
and:

Code: Select all

class DataController {
public:
	void startup();

private:
	void initialize_wrapper(void* const pTaskObject);
	void initialize(const void * const pd);
};
Thanks!

Christoph
Post Reply