Forums

variable corruption, tasks and software com ports

Started by mr_sallen November 30, 2004

I'm trying to run a simple program that has a main idle loop and two
tasks. One task reads from com3, stores some variables and
Debug.prints the results. The other just lights some leds
periodically. However, running the com3 reading loop in a separate
task seems to lead to corruption of variables, lockups on either the
task or the entire chip or the resetting of the chip. Running the
com3 loop in the main loop fixes this (mostly).

Is there something special about tasks that prevents the effective use
of com3 with them?





--- In , "mr_sallen" <stewart@n...> wrote:
> I'm trying to run a simple program that has a main idle loop and two
> tasks. One task reads from com3, stores some variables and
> Debug.prints the results. The other just lights some leds
> periodically. However, running the com3 reading loop in a separate
> task seems to lead to corruption of variables, lockups on either the
> task or the entire chip or the resetting of the chip. Running the
> com3 loop in the main loop fixes this (mostly).

What is the size of the stack that you are using for the task? I
suspect that it might be too small which would result in the task
corrupting data that follows the stack bytes in memory.





--- In , "Don Kinzer" <dkinzer@e...> wrote:
>
> --- In , "mr_sallen" <stewart@n...> wrote:
> > I'm trying to run a simple program that has a main idle loop and two
> > tasks. One task reads from com3, stores some variables and
> > Debug.prints the results. The other just lights some leds
> > periodically. However, running the com3 reading loop in a separate
> > task seems to lead to corruption of variables, lockups on either the
> > task or the entire chip or the resetting of the chip. Running the
> > com3 loop in the main loop fixes this (mostly).
>
> What is the size of the stack that you are using for the task? I
> suspect that it might be too small which would result in the task
> corrupting data that follows the stack bytes in memory.

I was using 120. How do you determine the size?

thanks





--- In , "mr_sallen" <stewart@n...> wrote:
> > What is the size of the stack that you are using for the task? I
> > suspect that it might be too small which would result in the task
> > corrupting data that follows the stack bytes in memory.
>
> I was using 120. How do you determine the size?

Unless you are using a lot of strings, have a lot of local data or
are making deeply nested calls, task stack space is probably not the
problem. If you had said that it was 25, that would be a different
story.

As far as determining stack size, mostly you have to guess and then
test your application fully ensuring that you exercise it so that its
maximum stack depth is utilized. I created a program to statically
analyze source code to estimate stack usage but it is based on
incomplete information. Still, I found it useful, especially for
figuring out how to reduce stack usage.

For more information on the program, look toward the bottom of this
page:
http://www.kinzers.com/don/BX24