I think "busy" is a red herring here, since the compiler optimizes it away
completely.  The bug is that it doesn't respect the sequence points in the
statement list.  It improperly moves the bic.b before the read of P4IN even
though the writes to P4OUT and the read of P4IN are all volatile operations
separated by sequence points.

Offhand, I think it's a bug in mspgcc4.  Marking busy volatile simply
changes the code enough to obscure the bug.

Sigh.   If you'd be so kind as to file it on the mspgcc4 tracker site to
remind me, I'll take a look this weekend.

Peter

On Fri, Jul 30, 2010 at 12:33 PM, Todd Allen <[email protected]> wrote:

> <sorry if this is a duplicate, problems with "from" address>
>
> I've got a device driver that I've been using for an HD44780 LCD display.
> It's been working under mspgcc for quite a while, but it stopped working
> when I upgraded to mspgcc4.
>
> There's some code that polls the "busy" flag, which is on the DB7 pin.
> Basically you bring the E pin high, read the busy flag, then bring the E
> pin
> low again.  A simplified version of the code follows:
>
> bool busy;
> do {
>    P4OUT |= E_PIN;
>    busy = P4IN & DB7_PIN;
>    P4OUT &= ~E_PIN;
> } while (busy);
>
> There are some nops for timing as well, plus a bit of code so that it
> doesn't wait forever, but that's the basic idea.
>
> I finally discovered that the compiler had reordered things so that the E
> pin was brought high, then low, then it checked the DB7 pin, which was too
> late. (Just to confuse things, if I put a scope probe on this pin, the
> capacitance slowed it down just enough to make it work occasionally.)
>
> The solution of course was to use the "volatile" keyword for "busy".  My
> question is this:  If P4IN is already marked volatile, why would busy have
> to be volatile too?  The "busy" variable isn't really volatile anyway, it's
> the input port that's volatile.
>
> Anyone have any insight about this?
>
> Todd
>
>
> ------------------------------------------------------------------------------
> The Palm PDK Hot Apps Program offers developers who use the
> Plug-In Development Kit to bring their C/C++ apps to Palm for a share
> of $1 Million in cash or HP Products. Visit us here for more details:
> http://p.sf.net/sfu/dev2dev-palm
> _______________________________________________
> Mspgcc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>
>

Reply via email to