Page 1 of 2

Threads

Posted: Sat Mar 13, 2010 9:08 pm
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

Re: Threads

Posted: Sun Mar 14, 2010 11:36 pm
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.

Re: Threads

Posted: Mon Mar 15, 2010 1:47 am
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...

Re: Threads

Posted: Tue Mar 16, 2010 9:38 am
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)

Re: Threads

Posted: Tue Mar 16, 2010 10:10 am
by ckoehler
Thanks guys, that makes sense.

Appreciate it!

Christoph

Re: Threads

Posted: Tue Mar 16, 2010 1:49 pm
by lgitlitz
You should probably take a look at the ucos chapter in the programmers guide:
C:\nburn\docs\NetworkProgrammersGuide\NNDKProgMan.pdf

Re: Threads

Posted: Wed Mar 24, 2010 8:42 am
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

Re: Threads

Posted: Wed Mar 24, 2010 12:58 pm
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.

Re: Threads

Posted: Wed Mar 24, 2010 4:31 pm
by ckoehler
Good to know, thanks!

Re: Threads

Posted: Mon Mar 29, 2010 11:27 am
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