Pumpkin, Inc.

Pumpkin User Forums

Would like to yield during getchar().

If you can't make Salvo do what you want it to do, post it here.

Would like to yield during getchar().

Postby Philip Boulton » Fri May 09, 2008 4:25 am

I am using Salvo Lite for MSP430, v4.

The manual helpfully warns:

quote:
Warning A Salvo context switch at a call ... return level below that of the task (e.g. within a subroutine called by the task) will cause unpredictable behavior.

What I would like to do is use a gets() function, which, through a series of calls repeatedly invokes a low-level getchar() function that I have written. I would like for the other tasks to be able to run while gets() is waiting for characters, and have the gets() check for characters when it is yielded to. I only invoke gets() and hence getchar from one task.

Here's what I have:

code:

void TaskTerminal(void)
{
char str [80];
....
while (1) {
....
printf ("Terminal task ready! Command me!
");
gets (str);
....
}
}

And within the low-level getchar(), I have:

code:

int getchar()
{
int character;
....
/* IFG2.URXIFG1 is set when a new character has been received. */
while (!(IFG2 & URXIFG1))
{
/* Spin in a loop, waiting for char to arrive */
OS_Yield();
}
character = U1RXBUF;
....
}

Obviously, this violates the rule about context-switching at different call/return levels from the task definition. And sure enough, it doesn't work.

Is there a way to make Salvo do what I want?

Philip Boulton
 
Posts: 2
Joined: Thu May 08, 2008 11:00 pm
Location: Vancouver, BC, Canada

Re: Would like to yield during getchar().

Postby Dave Hohl » Tue May 20, 2008 3:07 am

I am not a Pumpkin rep, but I think I can safely say that you cannot do what you want via function calls.

However, if you are only doing this in one place, you could write your own gets() code (it should be fairly simple, and you might even have the source code available from your compiler vendor) and just include it inline in your task instead of calling it as a function.

Dave Hohl
 
Posts: 24
Joined: Wed Apr 02, 2008 11:00 pm
Location: Sunnyvale, CA, USA

Re: Would like to yield during getchar().

Postby Philip Boulton » Mon Jun 02, 2008 4:37 am

Thanks, Dave.

That is not a bad idea. I will see if IAR will be gracious enough to provide me with gets() source code.

Philip B.

Philip Boulton
 
Posts: 2
Joined: Thu May 08, 2008 11:00 pm
Location: Vancouver, BC, Canada


Return to Coding

Who is online

Users browsing this forum: No registered users and 4 guests

cron