From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 3/8] sandbox: gpio: Add basic driver for simulating GPIOs
Date: Tue, 21 Feb 2012 11:04:13 -0500 [thread overview]
Message-ID: <201202211104.13950.vapier@gentoo.org> (raw)
In-Reply-To: <CAPnjgZ2=YRkrJ99Njs1DM885PAZ3EFuPBGQx7aBntyAnbMsE4Q@mail.gmail.com>
On Tuesday 21 February 2012 01:27:31 Simon Glass wrote:
> On Mon, Feb 20, 2012 at 10:11 PM, Mike Frysinger wrote:
> > --- a/drivers/gpio/sandbox.c
> > +++ b/drivers/gpio/sandbox.c
> >
> > /* Access routines for GPIO state */
> > -static u8 *get_gpio(unsigned gp)
> > +static u8 *get_gpio_flags(unsigned gp)
> > {
> > - assert(gp < CONFIG_SANDBOX_GPIO_COUNT);
> > + if (gp >= ARRAY_SIZE(state)) {
> > + static u8 invalid_flags;
> > + printf("sandbox_gpio: error: invalid gpio %u\n", gp);
> > + return &invalid_flags;
> > + }
> > +
>
> I think we want to die / fail the test here, but since we don't have
> any tests I suppose this is ok for now. I like assert() because it
> halts.
the problem is that assert() is disabled by default, so by default, we get
memory corruption :). i tend to agree with your previous statements (in
another thread) that the sandbox should, by default, do arg checking since the
sandbox env is expected to be tested/developed under.
extending that logic, i think it makes more sense to get output that includes
errors but "works" so people can play around more on the command line without
interrupting things. after all, i'd rather see an error message if i was in
the middle of typing "gpio ..." on the command line but fat fingered the gpio
number and typed "gpio set 199" instead of "gpio set 19".
> > /* set GPIO port 'gp' as an input */
> > int gpio_direction_input(unsigned gp)
> > {
> > - debug("%s: gp = %d\n", __func__, gp);
> > + debug("%s: gp:%u\n", __func__, gp);
> > +
> > if (check_reserved(gp, __func__))
> > return -1;
> > - set_gpio_flag(gp, GPIOF_OUTPUT, 0);
> >
> > - return 0;
> > + return sandbox_gpio_set_direction(gp, 0);
>
> Ick, we shouldn't call that function here - it is in the test code. Same
> below.
>
> The idea is that this state has two completely separate sides to it -
> by calling the 'test' functions from the 'U-Boot' functions I think
> you are going to confuse people a lot.
the way i see it is we have the pin state ("state"), we have direct accessor
functions with no error checking so other things can directly manipulate that
state (sandbox_gpio_xxx), and we have the generic gpio api (gpio_xxx). i
don't think both API's should get to directly manipulate the state ... it's
more logical (to me) that the generic gpio api be built off the hardware state
api rather than grubbin' around directly.
the only place that gets confusing is when we have one structure that ends up
storing the hardware state (pin direction/levels) along side the generic gpio
state (pin reservation and friendly label names). although, thinking a little
more, we should be able to split that out easily enough -- have an array of
labels and if a gpio's label is NULL, we know the pin is not reserved.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120221/109902bf/attachment.pgp>
next prev parent reply other threads:[~2012-02-21 16:04 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-15 23:51 [U-Boot] [PATCH v4 1/8] sandbox: fdt: Add support for CONFIG_OF_CONTROL Simon Glass
2012-02-15 23:51 ` [U-Boot] [PATCH v4 2/8] sandbox: config: Enable fdt and snprintf() options Simon Glass
2012-02-16 6:03 ` Mike Frysinger
2012-02-15 23:51 ` [U-Boot] [PATCH v4 3/8] sandbox: gpio: Add basic driver for simulating GPIOs Simon Glass
2012-02-21 6:11 ` Mike Frysinger
2012-02-21 6:27 ` Simon Glass
2012-02-21 16:04 ` Mike Frysinger [this message]
2012-02-21 21:55 ` Simon Glass
2012-02-21 22:13 ` Mike Frysinger
2012-02-21 22:21 ` Simon Glass
2012-02-22 5:08 ` [U-Boot] [PATCH v5] " Mike Frysinger
2012-02-22 5:45 ` Simon Glass
2012-02-22 18:31 ` Mike Frysinger
2012-02-15 23:51 ` [U-Boot] [PATCH v4 4/8] sandbox: Enable GPIO driver Simon Glass
2012-02-15 23:51 ` [U-Boot] [PATCH v4 5/8] sandbox: Add concept of sandbox state Simon Glass
2012-02-15 23:51 ` [U-Boot] [PATCH v4 6/8] sandbox: Allow processing instead of or before main loop Simon Glass
2012-02-15 23:51 ` [U-Boot] [PATCH v4 7/8] sandbox: Add flags for open() call Simon Glass
2012-02-16 6:09 ` Mike Frysinger
2012-02-21 4:32 ` Simon Glass
2012-02-15 23:51 ` [U-Boot] [PATCH v4 8/8] sandbox: Add basic command line parsing Simon Glass
2012-02-26 21:04 ` Mike Frysinger
2012-02-27 2:50 ` Simon Glass
2012-02-27 4:08 ` Mike Frysinger
2012-02-27 4:33 ` Simon Glass
2012-02-27 4:42 ` Mike Frysinger
2012-02-27 5:43 ` Simon Glass
2012-02-27 18:32 ` Mike Frysinger
2012-02-27 20:55 ` Simon Glass
2012-02-16 6:03 ` [U-Boot] [PATCH v4 1/8] sandbox: fdt: Add support for CONFIG_OF_CONTROL Mike Frysinger
2012-02-16 10:50 ` Marek Vasut
2012-02-16 19:16 ` Simon Glass
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=201202211104.13950.vapier@gentoo.org \
--to=vapier@gentoo.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox