Page 1 of 1

Would like to yield during getchar().

PostPosted: Fri May 09, 2008 4:25 am
by Philip Boulton
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?


Re: Would like to yield during getchar().

PostPosted: Tue May 20, 2008 3:07 am
by Dave Hohl
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.


Re: Would like to yield during getchar().

PostPosted: Mon Jun 02, 2008 4:37 am
by Philip Boulton
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.