Pumpkin, Inc.

Pumpkin User Forums

Why does OS_Delay() cause problems ?

If you have a general question or comment regarding Salvo, post it here.

Why does OS_Delay() cause problems ?

Postby aek » Thu Apr 06, 2006 12:22 am

quote:
2) In the preamble of the task (before the infinite loop) you can do the init with OS_Delay() calls.

I tried this, but had the same results.


As long as OS_Xyz() calls are made only at the task level, it doesn't matter where they are in the task, so it will work.
quote:
If I use this call
OSCreateTask(Task_One, TASK_1, OSDONT_START_TASK |2);

does it chew up memory, or it is only at the time when I call OSStartTask(TASK_1);


Yes, because each tcb is a static block of memory, and is associated with a particular task at all times.

But note that you can redefine which task a particular tcb is associated with. So, say as an example, you have two tasks -- one to initialize the LCD, and another which takes LCD strings as messages and displays them. You can initially create the LCD init task, and at its end (i.e. when it's done), it creates the LCD "working task" using the same tcb, i.e. the same TCBP(i). If at a later time you need to re-init the LCD, then you stop the working task, (re-)create the initializing task using that same tcb, and let it run.

Put another way, a tcb "chews up memory" all the time (since it's statically allocated). Its contents are valid whenever it's holding a task, i.e. after a call to OSCreateTask(). But it can always be (re-)initialized to hold a different task. Just make sure that when you "re-use" a tcb, you do it in a manner that doesn't kill a task you still want running.

The Reference chapter of the User Manual has some non-trivial examples of task creation, stopping, starting, etc.

------------------

[This message has been edited by aek (edited April 06, 2006).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Why does OS_Delay() cause problems ?

Postby seulater » Thu Apr 06, 2006 7:53 am

i have 4 tasks tasks running. all work just fine. I have added a new routine to initialize my LCD which uses the SPI port.
in one of the 4 threads I have done this.

when I add the InitLCD(); to the following thread it wiggs out.

further testing showed that when I would go into the InitLCD(); routine and comment out all the OS_Delay() calls its works fine then.

any ideas why ?


void Task_Three (void)
{
static char t=0;

for (;
{
InitLCD();

while(1)
{
spiCommand(t++);

c++;
OS_Delay(2);
}

}
}

seulater
 
Posts: 24
Joined: Tue May 10, 2005 11:00 pm
Location: Buffalo Grove, IL, USA

Re: Why does OS_Delay() cause problems ?

Postby aek » Thu Apr 06, 2006 8:04 am

... because OS_Delay() can only be called from a task, not from an underlying function.

Salvo's context switches (like OS_Delay()) can only occur at the task level. That's one thing that allows Salvo to not require individual task stacks ...

------------------

[This message has been edited by aek (edited April 06, 2006).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Why does OS_Delay() cause problems ?

Postby seulater » Thu Apr 06, 2006 8:11 am

Yes, I remember reading this the other day,

So, let me understand this fully. if I am in a task, & make a call to another function outside this task and use a OS_Delay in there thats a no-no...

if that is the case then help me think outside the box. in my example I wish to start this task but before it get caught in the for loop I need to initialize my LCD.
there will be delays in that init routine so how does one accomplish this task using Salvo is I cannot use OS_Delay outside a task ? I dont want to use a for-next loop delay that would defeat the whole RTOS purpose?

seulater
 
Posts: 24
Joined: Tue May 10, 2005 11:00 pm
Location: Buffalo Grove, IL, USA

Re: Why does OS_Delay() cause problems ?

Postby aek » Thu Apr 06, 2006 9:32 am

Your understanding is correct.

1) You can create a macro and use that in the task. The macro would be a multi-line macro that has calls to OS_Delay().

2) In the preamble of the task (before the infinite loop) you can do the init with OS_Delay() calls. This could also be a macro. An alternative is to #include some .c source code if you need to make the task look nicer.

3) You could have a task that runs as the first task, and it does stuff like init the LCD, using delays. It can then simply stop, or destroy itself, or things like that. There's an example in the Salvo User Manual of exactly this sort of thing -- initializing a Hitachi LED controller with delays. Once it's finished, it launches the other tasks. IOW, a task can create and start new tasks. In your case, after doing I/O init would be a good time to start the "runtime" tasks.

------------------

[This message has been edited by aek (edited April 06, 2006).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Why does OS_Delay() cause problems ?

Postby seulater » Thu Apr 06, 2006 9:55 am

>2) In the preamble of the task (before the infinite loop) you can do the init with OS_Delay() calls.

I tried this, but had the same results.

I am unclear on the Macro idea, I am looking in the manual now.

seulater
 
Posts: 24
Joined: Tue May 10, 2005 11:00 pm
Location: Buffalo Grove, IL, USA

Re: Why does OS_Delay() cause problems ?

Postby seulater » Thu Apr 06, 2006 10:07 am

I understand your #3 suggestion, but what if I need to reset the LCD at some later point in time. I would need to restart that init_lcd task from within another task.

No big deal there, however this is a small example. what if there are several routines that are like this. I cannot see have dozens of created tasks just sitting there taking up memory.

if I use this call
OSCreateTask(Task_One, TASK_1, OSDONT_START_TASK |2);

does it chew up memory, or it is only at the time when I call OSStartTask(TASK_1); ?

seulater
 
Posts: 24
Joined: Tue May 10, 2005 11:00 pm
Location: Buffalo Grove, IL, USA


Return to General

Who is online

Users browsing this forum: No registered users and 2 guests

cron