public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [RFC] gpio command: return value on write, additional actions
@ 2011-07-05 16:59 Andreas Pretzsch
  2011-07-05 17:44 ` Mike Frysinger
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Pretzsch @ 2011-07-05 16:59 UTC (permalink / raw)
  To: u-boot

As of today (2011.06), the generic gpio command (common/cmd_gpio.c)
	gpio <input|set|clear|toggle> <port><pin>
	    - input/set/clear/toggle the specified pin (e.g. PF10)
always returns the value read or set.

While this is sensible for read (input) and maybe (questionable) for
toggle, I don't see an usage for write (set/clear).

Also, this leads to unexpected side effects with complex constructs,
e.g. consider this environment:
	setA=gpio set PF1
	setB=gpio clear PF2
	setAB_separate=env run setA ; env run setB
	setAB_concatenated=env run setA setB
	setBA_concatenated=env run setB setA

While executing "setAB_separate" and "setBA_concatenated" work as
expected, "setAB_concatenated" will only run setA, but not setB, as setA
"failed" (ret=1). [1]
The same would apply to e.g. && constructs.

As it works this way in the release and hence the behaviour is
essentially fixed, changing the return value is probably not an option.
OTOH, the breakage here might be negligible, at least for set/clear.
But in any case, it should be documented.

Beside this, I'd like to extend the gpio command with the additional
actions "0" and "1", always returning 0 (given the write was
successful):
	gpio <input|set|clear|toggle|0|1> <port><pin>

As a nice benefit, it would strip down constructs like
	if test ${LED_x} -eq 0;then gpio set PF1;else gpio clear PF1;fi
to a simple "gpio ${LED_x} PF1".


Any comments or objections before I submit a patch ?


[1] http://www.denx.de/wiki/DULG/CommandLineParsing "General rules"

-- 

carpe noctem engineering
Ingenieurbuero fuer Hard- & Software-Entwicklung Andreas Pretzsch
Dipl.-Ing. (FH) Andreas Pretzsch          Tel. +49-(0)731-5521572
Hahnengasse 3                             Fax: +49-(0)731-5521573
89073 Ulm, Germany                        email: apr at cn-eng.de

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-07-20 18:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-05 16:59 [U-Boot] [RFC] gpio command: return value on write, additional actions Andreas Pretzsch
2011-07-05 17:44 ` Mike Frysinger
2011-07-05 19:15   ` Andreas Pretzsch
2011-07-05 19:33     ` Mike Frysinger
2011-07-06  8:33     ` Detlev Zundel
2011-07-06 10:36       ` Wolfgang Denk
2011-07-07 10:15         ` Detlev Zundel
2011-07-20 18:22           ` Andreas Pretzsch
2011-07-14 20:07         ` Mike Frysinger
2011-07-15  7:39           ` Detlev Zundel
2011-07-18 18:08             ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox