starting thread with parameters...

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
jscott
Posts: 129
Joined: Tue Jul 03, 2012 3:50 pm

starting thread with parameters...

Post by jscott »

I am getting ADC data from three ADC channels and doing some processing in the ADC callback. When my data buffer is ready, I switch buffers and need to send the full buffers to another thread for processing while the second set of buffers fill.

I have not been able to figure out how to start a thread with parameters.

Anybody got any ideas?

Thanks
-John Scott
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: starting thread with parameters...

Post by Giovanni »

Hi,

The last parameter of thread create functions is a parameter that is passed to the created thread, if you need more than a parameter then you may use it to pass a pointer to a structure.

Giovanni
colin
Posts: 149
Joined: Thu Dec 22, 2011 7:44 pm

Re: starting thread with parameters...

Post by colin »

Also, do you really want to start the other thread or just send it a message when the ADC conv is done? It it's happening constantly it would maybe make more sense to have the processing thread wait and receive via a mailbox or some other synchronization construct.
jscott
Posts: 129
Joined: Tue Jul 03, 2012 3:50 pm

Re: starting thread with parameters...

Post by jscott »

Colin,

Yea, I think just passing a message might be better.
That would solve the problem I have with defining
a thread in one module and creating the thread.

Giovanni,

How would I go about having one module named processing.c that contains a thread defined in the usual way. Then call the create process function from another module, for example main.c?

Normally I would just create prototypes in a header file, but don't know how to deal with the process working area.

In the past, I have just called a stub in the module with the thread, then started the thread locally.

-john Scott
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: starting thread with parameters...

Post by Giovanni »

Creating a separate module for the thread is a clean approach, no problems with that. In the header file put the thread function prototype and the re-declaration of the working area preceded by "extern".

The result, depending on the port, is something like:

extern stkalign_t myWA[1024];

Giovanni
Post Reply