EmbeddedRelated.com
Forums
Memfault State of IoT Report

Restarting a task in freeRTOS

Started by Nishant Agrawal June 25, 2012
Dear Bastian,

Yes there are such functions, but requirements are such that restarting the
task seems the only logical solution. That's why I thought that Richard
could help me out with some hidden function to get it done.

On Tue, Jun 26, 2012 at 10:50 AM, 42Bastian wrote:

> **
> Am 26.06.2012 06:29, schrieb Nishant Agrawal:
>
> > Dear Bastian,
> >
> > This seriously is not me. This guy is from India, I am from Nepal.
>
> Great.
> --
> 42Bastian
> +
> | http://www.sciopta.com
> | Fastest direct message passing kernel.
> | IEC61508 certified.
> +
>
>
>

--
With Regards,
Nishant Agrawal,
Design Engineer,
Real Time Solutions Pvt. Ltd.
Ph: +977-1-4253717
Mobile: +977-9841259267
www.rts.com.np


An Engineer's Guide to the LPC2100 Series

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for microcontrollers. More than 7000 downloads per month.

+ http://www.FreeRTOS.org/trace
15 interconnected trace views. An indispensable productivity tool.

On 26/06/2012 04:46, Nishant Agrawal wrote:
> Dear Richard,
>
> Here is the task routine
>
> static void
> _output_control(void *pv_parameters) {
> while(1) {
> oi.frequency = 0;
> vTaskSuspend(NULL);
> while(oi.frequency--) {
> OUTPUT_ON();
> vTaskDelay(oi.on_duration);
> OUTPUT_OFF();
> vTaskDelay(oi.off_duration);
> }
> }
> }
>
> Now what I want to do is reset the state of this task. So as you said of
> deleting and creating the task again, I did that, but with the call to the
> process of deleting and creating the task, I also need to make the call to
> resume the task, but the task has not been called yet and is not in suspend
> state, so the resume call is just lost. Do you have any suggestions on how
> I can do that or even make a call to the task after recreating it and
> before changing the state to Resume.

Sorry - I don't understand what it is you are trying to do. You have a
very simple loop that does the same thing over and over again.
Presumably oi.frequency is set while the task is suspended? Otherwise
the task would not do anything. What is it you want to reset? What is
the task supposed to do?
> And Chris, thanks for letting me know about such a hidden feature in the
> OS. You changed my world my friend.

Are you talking about suspend resume? If so - in what way is that
hidden? (the API is on the web site and in the reference manual, and
you are already using it in your code snippet above?)

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for microcontrollers. More than 7000 downloads per month.

+ http://www.FreeRTOS.org/trace
15 interconnected trace views. An indispensable productivity tool.

> On Tue, Jun 26, 2012 at 7:01 AM, Chris wrote:
>
>> **
>>> Is there a way to restart a task in freeRTOS?
>>>> Restart it in what sense? You can always delete it an then re-create it.
>>
>> I wonder if he is aware of "Suspend/Resume".
>>
>> Chris.
>>
>>
>

On 26/06/2012 05:15, Nishant Agrawal wrote:
> Dear Bastian,
>
> Yes the task is very simple. But there could be conditions that while the
> task is stuck in vTaskDelay routine, new set of information is received
> which needs to executed thus the need to restart the task. The line
> oi.frequency = 0 was only an attempt to make it work by recreating the task
> so will be removed if I find a way to accomplish my requirement.
>

Your task does not show any information being received anywhere - maybe
if I understood how this information was received I could help you.

As a guess, have you considered blocking on a queue rather than blocking
in a vTaskDelay()? The queue can receive a message to unblock the task,
and the message can either come from a software timer when the delay
period is finished (to act just like the vTaskDelay()), or from
"something else" telling the task to "reset" (go back to the
beginning?). The data received on the queue will tell the receiving
task what to do.
Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for microcontrollers. More than 7000 downloads per month.

+ http://www.FreeRTOS.org/trace
15 interconnected trace views. An indispensable productivity tool.

--- In l..., FreeRTOS Info wrote:
> Regards,
> Richard.
>
> + http://www.FreeRTOS.org
> Designed for microcontrollers. More than 7000 downloads per month.
>
> + http://www.FreeRTOS.org/trace
> 15 interconnected trace views. An indispensable productivity tool.
>
> On 26/06/2012 04:46, Nishant Agrawal wrote:
> > Dear Richard,
> >
> > Here is the task routine
> >
> > static void
> > _output_control(void *pv_parameters) {
> > while(1) {
> > oi.frequency = 0;
> > vTaskSuspend(NULL);
> > while(oi.frequency--) {
> > OUTPUT_ON();
> > vTaskDelay(oi.on_duration);
> > OUTPUT_OFF();
> > vTaskDelay(oi.off_duration);
> > }
> > }
> > }
> >
> > Now what I want to do is reset the state of this task. So as you said of
> > deleting and creating the task again, I did that, but with the call to the
> > process of deleting and creating the task, I also need to make the call to
> > resume the task, but the task has not been called yet and is not in suspend
> > state, so the resume call is just lost. Do you have any suggestions on how
> > I can do that or even make a call to the task after recreating it and
> > before changing the state to Resume.
>
> Sorry - I don't understand what it is you are trying to do. You have a
> very simple loop that does the same thing over and over again.
> Presumably oi.frequency is set while the task is suspended? Otherwise
> the task would not do anything. What is it you want to reset? What is
> the task supposed to do?
> > And Chris, thanks for letting me know about such a hidden feature in the
> > OS. You changed my world my friend.
>
> Are you talking about suspend resume? If so - in what way is that
> hidden? (the API is on the web site and in the reference manual, and
> you are already using it in your code snippet above?)
>
> Regards,
> Richard.
>
> + http://www.FreeRTOS.org
> Designed for microcontrollers. More than 7000 downloads per month.
>
> + http://www.FreeRTOS.org/trace
> 15 interconnected trace views. An indispensable productivity tool.
>
> >
> >
> > On Tue, Jun 26, 2012 at 7:01 AM, Chris wrote:
> >
> >> **
> >>
> >>
> >>> Is there a way to restart a task in freeRTOS?
> >>>> Restart it in what sense? You can always delete it an then re-create it.
> >>
> >> I wonder if he is aware of "Suspend/Resume".
> >>

Is suspend/resume safe from suspending a thread while it owns a mutex, eg. for malloc()? If it's anything like Windows, suspend/resume control of threads should never be used - it's just too dangerous, (and plenty of other synchro methods are available, as others have posted).

Actually, creating(except at startup)/terminating/deleting thread objects falls into a similar category 'Try very, very hard to not do this and, if instructed to do it by your boss, update your CV now and get out before the job turns into ****'.

Rgds,
Martin

Dear Richard,

Thanks for the idea of the queue. This can help me overcome the problem
without the need to restart the task. I will try it out and let you know if
I get blocked somewhere.

On Wed, Jun 27, 2012 at 3:09 AM, mjames_doveridge <
m...@googlemail.com> wrote:

> **
> --- In l..., FreeRTOS Info wrote:
> >
> >
> >
> >
> > Regards,
> > Richard.
> >
> > + http://www.FreeRTOS.org
> > Designed for microcontrollers. More than 7000 downloads per month.
> >
> > + http://www.FreeRTOS.org/trace
> > 15 interconnected trace views. An indispensable productivity tool.
> >
> >
> >
> > On 26/06/2012 04:46, Nishant Agrawal wrote:
> > > Dear Richard,
> > >
> > > Here is the task routine
> > >
> > > static void
> > > _output_control(void *pv_parameters) {
> > > while(1) {
> > > oi.frequency = 0;
> > > vTaskSuspend(NULL);
> > > while(oi.frequency--) {
> > > OUTPUT_ON();
> > > vTaskDelay(oi.on_duration);
> > > OUTPUT_OFF();
> > > vTaskDelay(oi.off_duration);
> > > }
> > > }
> > > }
> > >
> > > Now what I want to do is reset the state of this task. So as you said
> of
> > > deleting and creating the task again, I did that, but with the call to
> the
> > > process of deleting and creating the task, I also need to make the
> call to
> > > resume the task, but the task has not been called yet and is not in
> suspend
> > > state, so the resume call is just lost. Do you have any suggestions on
> how
> > > I can do that or even make a call to the task after recreating it and
> > > before changing the state to Resume.
> >
> > Sorry - I don't understand what it is you are trying to do. You have a
> > very simple loop that does the same thing over and over again.
> > Presumably oi.frequency is set while the task is suspended? Otherwise
> > the task would not do anything. What is it you want to reset? What is
> > the task supposed to do?
> >
> >
> > > And Chris, thanks for letting me know about such a hidden feature in
> the
> > > OS. You changed my world my friend.
> >
> > Are you talking about suspend resume? If so - in what way is that
> > hidden? (the API is on the web site and in the reference manual, and
> > you are already using it in your code snippet above?)
> >
> > Regards,
> > Richard.
> >
> > + http://www.FreeRTOS.org
> > Designed for microcontrollers. More than 7000 downloads per month.
> >
> > + http://www.FreeRTOS.org/trace
> > 15 interconnected trace views. An indispensable productivity tool.
> >
> >
> >
> > >
> > >
> > > On Tue, Jun 26, 2012 at 7:01 AM, Chris wrote:
> > >
> > >> **
> > >>
> > >>
> > >>> Is there a way to restart a task in freeRTOS?
> > >>>> Restart it in what sense? You can always delete it an then
> re-create it.
> > >>
> > >> I wonder if he is aware of "Suspend/Resume".
> > >> Is suspend/resume safe from suspending a thread while it owns a mutex, eg.
> for malloc()? If it's anything like Windows, suspend/resume control of
> threads should never be used - it's just too dangerous, (and plenty of
> other synchro methods are available, as others have posted).
>
> Actually, creating(except at startup)/terminating/deleting thread objects
> falls into a similar category 'Try very, very hard to not do this and, if
> instructed to do it by your boss, update your CV now and get out before the
> job turns into ****'.
>
> Rgds,
> Martin
>
>
>

--
With Regards,
Nishant Agrawal,
Design Engineer,
Real Time Solutions Pvt. Ltd.
Ph: +977-1-4253717
Mobile: +977-9841259267
www.rts.com.np


Dear Martin,

Thanks for the suggestion. I am just starting of with freeRTOS and a lot to
learn about the dos and donts for an OS. It was just my idea on trying to
deal with a worst case scenario with the system. But as Richard's has
suggested, using a queue might be a better idea.

On Wed, Jun 27, 2012 at 9:32 AM, Nishant Agrawal wrote:

> Dear Richard,
>
> Thanks for the idea of the queue. This can help me overcome the problem
> without the need to restart the task. I will try it out and let you know if
> I get blocked somewhere.
> On Wed, Jun 27, 2012 at 3:09 AM, mjames_doveridge <
> m...@googlemail.com> wrote:
>
>> **
>> --- In l..., FreeRTOS Info wrote:
>> >
>> >
>> >
>> >
>> > Regards,
>> > Richard.
>> >
>> > + http://www.FreeRTOS.org
>> > Designed for microcontrollers. More than 7000 downloads per month.
>> >
>> > + http://www.FreeRTOS.org/trace
>> > 15 interconnected trace views. An indispensable productivity tool.
>> >
>> >
>> >
>> > On 26/06/2012 04:46, Nishant Agrawal wrote:
>> > > Dear Richard,
>> > >
>> > > Here is the task routine
>> > >
>> > > static void
>> > > _output_control(void *pv_parameters) {
>> > > while(1) {
>> > > oi.frequency = 0;
>> > > vTaskSuspend(NULL);
>> > > while(oi.frequency--) {
>> > > OUTPUT_ON();
>> > > vTaskDelay(oi.on_duration);
>> > > OUTPUT_OFF();
>> > > vTaskDelay(oi.off_duration);
>> > > }
>> > > }
>> > > }
>> > >
>> > > Now what I want to do is reset the state of this task. So as you said
>> of
>> > > deleting and creating the task again, I did that, but with the call
>> to the
>> > > process of deleting and creating the task, I also need to make the
>> call to
>> > > resume the task, but the task has not been called yet and is not in
>> suspend
>> > > state, so the resume call is just lost. Do you have any suggestions
>> on how
>> > > I can do that or even make a call to the task after recreating it and
>> > > before changing the state to Resume.
>> >
>> > Sorry - I don't understand what it is you are trying to do. You have a
>> > very simple loop that does the same thing over and over again.
>> > Presumably oi.frequency is set while the task is suspended? Otherwise
>> > the task would not do anything. What is it you want to reset? What is
>> > the task supposed to do?
>> >
>> >
>> > > And Chris, thanks for letting me know about such a hidden feature in
>> the
>> > > OS. You changed my world my friend.
>> >
>> > Are you talking about suspend resume? If so - in what way is that
>> > hidden? (the API is on the web site and in the reference manual, and
>> > you are already using it in your code snippet above?)
>> >
>> > Regards,
>> > Richard.
>> >
>> > + http://www.FreeRTOS.org
>> > Designed for microcontrollers. More than 7000 downloads per month.
>> >
>> > + http://www.FreeRTOS.org/trace
>> > 15 interconnected trace views. An indispensable productivity tool.
>> >
>> >
>> >
>> > >
>> > >
>> > > On Tue, Jun 26, 2012 at 7:01 AM, Chris wrote:
>> > >
>> > >> **
>> > >>
>> > >>
>> > >>> Is there a way to restart a task in freeRTOS?
>> > >>>> Restart it in what sense? You can always delete it an then
>> re-create it.
>> > >>
>> > >> I wonder if he is aware of "Suspend/Resume".
>> > >> Is suspend/resume safe from suspending a thread while it owns a mutex,
>> eg. for malloc()? If it's anything like Windows, suspend/resume control of
>> threads should never be used - it's just too dangerous, (and plenty of
>> other synchro methods are available, as others have posted).
>>
>> Actually, creating(except at startup)/terminating/deleting thread objects
>> falls into a similar category 'Try very, very hard to not do this and, if
>> instructed to do it by your boss, update your CV now and get out before the
>> job turns into ****'.
>>
>> Rgds,
>> Martin
>>
>>
>> --
> With Regards,
> Nishant Agrawal,
> Design Engineer,
> Real Time Solutions Pvt. Ltd.
> Ph: +977-1-4253717
> Mobile: +977-9841259267
> www.rts.com.np
>

--
With Regards,
Nishant Agrawal



Memfault State of IoT Report