RES: RES: passing parameters to task

Luca Cinquepalmi cinquepalmi at planetek.it
Mon Sep 17 13:59:33 UTC 2012


Thank you Wendell! You solved all my doubt!:-)
Great!

     Luca


Il 17/09/2012 15.54, Wendell Pereira da Silva ha scritto:
>
> Oh.. .sorry..
>
> 1)Change to (*struct* complex_task_parameters *)
>
> 2)Use it as a member of structure dynamically allocated (by means of 
> -> operator). Example:
>
> printk(“foo = %s\n, p->foo);
>
> --Wendell.
>
> *De:*Luca Cinquepalmi [mailto:cinquepalmi at planetek.it]
> *Enviada em:* segunda-feira, 17 de setembro de 2012 10:18
> *Para:* Wendell Pereira da Silva
> *Cc:* Mathew Benson; rtems-users at rtems.org
> *Assunto:* Re: RES: passing parameters to task
>
> Thank you Wendell, that's exactly what I mean. I have two question for 
> you.
> *
> 1)* In
>
> *rtems_task mytask(rtems_task_argument arg)*
>
> *{*
>
> *struct complex_task_parameters* p;*
>
> **
>
> *p = (complex_task_parameters *)arg;*
>
> **
>
> *while(true)*
>
> *{*
>
> *//use parameters in p*
>
> *//....*
>
> *}*
>
> *}*
>
> I have a type error in *p = (complex_task_parameters *)arg;
> *Is complex_task_parameters type correct?
>
> *2)* How can I use parameters in while cycle? How can I refer to "foo" 
> for example?
>
>      Thanks a lot again!
>
>     Luca
>
>
> Il 17/09/2012 14.35, Wendell Pereira da Silva ha scritto:
>
>     Hi Luca,
>
>     Mathew, please, may I post an example?
>
>     :-)
>
>     rtems_task mytask(rtems_task_argument arg);
>
>     (…)
>
>     struct complex_task_parameters
>
>     {
>
>     uint32_t ui;  // first parameter...
>
>     uint16_t usi; // second parameter...
>
>     const char* foo;  // another parameter...
>
>     }
>
>     rtems_task Init(rtems_task_argument arg)
>
>     {
>
>     rtems_id tid;
>
>     struct complex_task_parameters* p_task_param;
>
>        // allocate and initialize parameters
>
>     p_task_param = calloc(1, sizeof(*p_task_param));
>
>     p_task_param->ui = 1;
>
>     p_task_param->usi = 0x1000;
>
>     p_task_param->foo = "test...";
>
>        // create the task as usual
>
>     rtems_task_create(..., &tid);
>
>        // now pass the parameter to the task;
>
>        // use typecast to make the compiler happy.
>
>     rtems_task_start(tid, mytask, (rtems_task_argument)p_task_param);
>
>     }
>
>     rtems_task mytask(rtems_task_argument arg)
>
>     {
>
>     struct complex_task_parameters* p;
>
>        p = (complex_task_parameters *)arg;
>
>     while(true)
>
>        {
>
>     //use parameters in p
>
>     //....
>
>        }
>
>     }
>
>     Hope it helps.
>
>     --Wendell.
>
>     *De:*rtems-users-bounces at rtems.org
>     <mailto:rtems-users-bounces at rtems.org>
>     [mailto:rtems-users-bounces at rtems.org] *Em nome de *Luca Cinquepalmi
>     *Enviada em:* segunda-feira, 17 de setembro de 2012 07:20
>     *Para:* Mathew Benson
>     *Cc:* rtems-users at rtems.org <mailto:rtems-users at rtems.org>
>     *Assunto:* Re: passing parameters to task
>
>     I understand your suggestion... is there any example I could view?
>
>         Luca
>
>     Il 17/09/2012 12.18, Mathew Benson ha scritto:
>
>         The same way you would with a POSIX pthread create call.  Just
>         malloc a struct with your multiple parameters, set your
>         parameters, and pass the reference of your struct to the
>         function.  In your task entry point, cast the argument to a
>         pointer to your struct and pull your parameters out.
>
>         Sent from my Amiga 1000
>
>
>         On Sep 17, 2012, at 4:35 AM, Luca Cinquepalmi
>         <cinquepalmi at planetek.it <mailto:cinquepalmi at planetek.it>> wrote:
>
>             Hi all,
>             I would like to know if is it possible to pass more than
>             one argument to a single task...
>             At the moment I only use this syntax when I define a task
>
>             *rtems_task Test_task(rtems_task_argument unused)*
>
>             How can I declare and define a more parameters dependent task?
>             Thanks a lot.
>
>                 Luca
>
>
>
>             _______________________________________________
>             rtems-users mailing list
>             rtems-users at rtems.org <mailto:rtems-users at rtems.org>
>             http://www.rtems.org/mailman/listinfo/rtems-users
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20120917/96f86978/attachment-0001.html>


More information about the users mailing list