From: Jerry Van Baren <gerald.vanbaren@ge.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] Spartan FPGA patch
Date: Wed, 07 Nov 2007 16:07:29 -0500 [thread overview]
Message-ID: <47322911.5050902@ge.com> (raw)
In-Reply-To: <20071107194809.D7CE4248D3@gemini.denx.de>
Wolfgang Denk wrote:
> Dear Matthias,
>
> in message <200711071529.49762.matthias.fuchs@esd-electronics.com> you wrote:
>> when copying val from 'data[bytecount++]' it is common practice that val
>> if of the same type as the array elements. So val should be unsigned char.
>
> Maybe. But what's the difference?
>
>> I changed the sign check into a 'val & 0x80', which I think is fine an clean.
>
> If it is indeed intended to be a test for a negative number, then
> this is neither nice nor clean.
>
> Best regards,
>
> Wolfgang Denk
Hi Wolfgang,
You are missing the point of signed vs. unsigned because you got sucked
into the wrong argument. The problematic code is:
512 val = data [bytecount ++];
513 i = 8;
514 do {
515 /* Deassert the clock */
516 (*fn->clk) (FALSE, TRUE, cookie);
517 CONFIG_FPGA_DELAY ();
518 /* Write data */
519 (*fn->wr) ((val < 0), TRUE, cookie); <-------- BAD
520 CONFIG_FPGA_DELAY ();
521 /* Assert the clock */
522 (*fn->clk) (TRUE, TRUE, cookie);
523 CONFIG_FPGA_DELAY ();
524 val <<= 1;
525 i --;
526 } while (i > 0);
As you can see, the code is looking at the MSB of the 8 bit value to see
if it must program a '1' or a '0' and it is shifting the byte left by 1
bit each time.
The problem is that it is using a *signed character test* (val < 0)
where it *should be* using an bit ANDing operation to isolate the MSBit
of the 8 bit "char" (and I would leave the char as a char, since it is
immaterial whether it is signed or unsigned *if the correct test were
used*). This is what Angelos recommended:
<http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/33116>
Obviously, I agree with him and recommend that the
(val < 0)
be changed to
(val & 0x80)
rather than the original fix (which also works, but is fixing the
problem in the wrong way IMHO).
Best regards,
gvb
prev parent reply other threads:[~2007-11-07 21:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-30 15:51 [U-Boot-Users] Spartan FPGA patch Aggelos Manousarides
2007-11-03 21:46 ` Wolfgang Denk
2007-11-05 12:58 ` Aggelos Manousarides
2007-11-05 19:21 ` Wolfgang Denk
2007-11-07 11:43 ` Aggelos Manousarides
2007-11-07 13:33 ` Wolfgang Denk
2007-11-07 16:49 ` Andreas Schweigstill
2007-11-07 19:51 ` Wolfgang Denk
2007-11-14 12:05 ` Aggelos Manousarides
2007-11-14 19:46 ` Wolfgang Denk
2007-11-07 14:29 ` Matthias Fuchs
2007-11-07 19:48 ` Wolfgang Denk
2007-11-07 21:07 ` Jerry Van Baren [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47322911.5050902@ge.com \
--to=gerald.vanbaren@ge.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.