ARM: Add command to control coloured led from the console
PATCH 1/1 ARM: Add command to control coloured led from the console
This patch allows any board implementing the coloured LED API to control the LEDs from the console.
led [green | yellow | red | all ] [ on | off ]
or
led [ 1 | 2 | 3 | all ] [ on | off ]
Adds configuration item CONFIG_CMD_LED enabling the command.
The coloured led API is available as part of the status_led API. Not every board with the coloured LED support implements the status led, so the coloured LED API is separated out from include/status_led. h to "include/coloured_led.h".
-------------------------------------------------------------------------------
Patch [1/1] Updates to include/asm-arm/arch.at91rm9200
[1/5] AFFECTS
common/cmd_led.c
common/Makefile
include/coloured_led.h
include/status_led.h
---
diff -urN u-boot-2009.01-0rig//common/cmd_led.c u-boot-2009.01/common/cmd_led.c
--- u-boot-2009.01-0rig//common/cmd_led.c 1970-01-01 01:00:00.000000000
+0100
+++ u-boot-2009.01/common/cmd_led.c 2009-01-03 23:39:57.000000000 +0100
@@ -0,0 +1,84 @@
+/*
+ * (C) Copyright 2008
+ * Ulf Samuelsson <[email protected]>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * This file provides a shell like 'test' function to return
+ * true/false from an integer or string compare of two memory
+ * locations or a location and a scalar/literal.
+ * A few parts were lifted from bash 'test' command
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <coloured_led.h>
+
+int do_led ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] ) +{
+ int led;
+ /* Validate arguments */
+ if ((argc != 3)){
+ printf("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+ if (strcmp(argv[1], "1") == 0) {
+ led = (1 << 0);
+ } else if (strcmp(argv[1], "2") == 0) {
+ led = (1 << 1);
+ } else if (strcmp(argv[1], "3") == 0) {
+ led = (1 << 2);
+ } else if (strcmp(argv[1], "green") == 0) {
+ led = (1 << 0);
+ } else if (strcmp(argv[1], "yellow") == 0) {
+ led = (1 << 1);
+ } else if (strcmp(argv[1], "red") == 0) {
+ led = (1 << 2);
+ } else if (strcmp(argv[1], "all") == 0) {
+ led = 7;
+ } else {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ if (strcmp(argv[2], "off") == 0) {
+ if(led & 1) green_LED_off();
+ if(led & 2) yellow_LED_off();
+ if(led & 4) red_LED_off();
+ } else if (strcmp(argv[2], "on") == 0) {
+ if(led & 1) green_LED_on();
+ if(led & 2) yellow_LED_on();
+ if(led & 4) red_LED_on();
+ } else {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ return 0;
+}
+
+U_BOOT_CMD(
+ led, 3, 1, do_led,
+ "led\t- [1|2|3|green|yellow|red|all] [on|off]\n",
+ "led [1|2|3|green|yellow|red|all] [on|off] sets /clears led 1,2,3\n"
+);
+
diff -urN u-boot-2009.01-0rig//common/Makefile u-boot-2009.01/common/Makefile
--- u-boot-2009.01-0rig//common/Makefile 2009-01-02 21:18:24.000000000
+0100
+++ u-boot-2009.01/common/Makefile 2009-01-03 23:41:53.000000000 +0100
@@ -99,6 +99,7 @@
COBJS-$(CONFIG_CMD_IRQ) += cmd_irq.o COBJS-$(CONFIG_CMD_ITEST) += cmd_itest.o COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o
+COBJS-$(CONFIG_CMD_LED) += cmd_led.o
COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o
COBJS-y += cmd_load.o
COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o
diff -urN u-boot-2009.01-0rig//include/coloured_led.h u-boot-2009.01/include/coloured_led.h
--- u-boot-2009.01-0rig//include/coloured_led.h 1970-01-01
01:00:00.000000000 +0100
+++ u-boot-2009.01/include/coloured_led.h 2009-01-03 23:39:19.000000000
+0100
@@ -0,0 +1,62 @@
+/*
+ * (C) Copyright 2008
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * The purpose of this code is to signal the operational status of a
+ * target which usually boots over the network; while running in
+ * PCBoot, a status LED is blinking. As soon as a valid BOOTP reply
+ * message has been received, the LED is turned off. The Linux
+ * kernel, once it is running, will start blinking the LED again,
+ * with another frequency.
+ */
+
+#ifndef _COLOURED_LED_H_
+#define _COLOURED_LED_H_
+
+#ifdef CONFIG_COLOURED_LED
+
+/*
+ * Coloured LEDs API
+ */
+#ifndef __ASSEMBLY__
+extern void coloured_LED_init (void);
+extern void red_LED_on(void);
+extern void red_LED_off(void);
+extern void green_LED_on(void);
+extern void green_LED_off(void);
+extern void yellow_LED_on(void);
+extern void yellow_LED_off(void);
+#else
+ .extern LED_init
+ .extern red_LED_on
+ .extern red_LED_off
+ .extern yellow_LED_on
+ .extern yellow_LED_off
+ .extern green_LED_on
+ .extern green_LED_off
+#endif
+
+#endif /* CONFIG_COLOURED_LED */
+
+#endif /* _STATUS_COLOURED_H_ */
+
diff -urN u-boot-2009.01-0rig//include/status_led.h u-boot-2009.01/include/status_led.h
--- u-boot-2009.01-0rig//include/status_led.h 2008-12-16
23:48:27.000000000 +0100
+++ u-boot-2009.01/include/status_led.h 2009-01-03 23:44:40.000000000
+0100
@@ -383,27 +383,6 @@
# include <asm/status_led.h> #endif
-/*
- * Coloured LEDs API
- */
-#ifndef __ASSEMBLY__
-extern void coloured_LED_init (void);
-extern void red_LED_on(void);
-extern void red_LED_off(void);
-extern void green_LED_on(void);
-extern void green_LED_off(void);
-extern void yellow_LED_on(void);
-extern void yellow_LED_off(void);
-#else
- .extern LED_init
- .extern red_LED_on
- .extern red_LED_off
- .extern yellow_LED_on
- .extern yellow_LED_off
- .extern green_LED_on
- .extern green_LED_off
-#endif
-
#endif /* CONFIG_STATUS_LED */
#endif /* _STATUS_LED_H_ */
Best Regards
Ulf Samuelsson
PATCH 1/1 ARM: Add command to control coloured led from the console
Quoted 10 lines · Ulf Samuelsson
This patch allows any board implementing the coloured LED API to control the LEDs from the console.
led [green | yellow | red | all ] [ on | off ]
or
led [ 1 | 2 | 3 | all ] [ on | off ]
Quoted 7 lines
Adds configuration item
CONFIG_CMD_LEDenabling the command.The coloured led API is available as part of the
status_ledAPI. Not every board with the coloured LED support implements the status led, so the coloured LED API is separated out frominclude/status_led. h to "include/coloured_led.h".
From
Quoted 10 lines
-------------------------------------------------------------------------------
Patch [1/1] Updates toinclude/asm-arm/arch.at91rm9200[1/5] AFFECTS
common/cmd_led.c
common/Makefile
include/coloured_led.h
include/status_led.h
to here should be after the ---
please use git format-patch to generate the patch also
Quoted 37 lines
Signed-off-by Ulf Samuelsson <[email protected]>---
diff -urNu-boot-2009.01-0rig//common/cmd_led.cu-boot-2009.01/common/cmd_led.c
---u-boot-2009.01-0rig//common/cmd_led.c1970-01-01 01:00:00.000000000
+0100
+++u-boot-2009.01/common/cmd_led.c2009-01-03 23:39:57.000000000 +0100(quoted diff) +26
-0@@ -0,0 +1,84 @@ +/* + * (C) Copyright 2008 + * Ulf Samuelsson <[email protected]> + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +/* + * This file provides a shell like 'test' function to return + * true/false from an integer or string compare of two memory
Review line 36
Quoted 10 lines
(quoted diff) +10
-0+ * locations or a location and a scalar/literal. + * A few parts were lifted from bash 'test' command + */ + +#include <common.h> +#include <config.h> +#include <command.h> +#include <coloured_led.h> + +int do_led ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
please use thie
int do_led(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
Review line 38
Quoted 2 lines
(quoted diff) +2
-0+{ + int led;
please add an empty line
Review line 40
Quoted 2 lines
(quoted diff) +2
-0+ /* Validate arguments */ + if ((argc != 3)){
please add a spece before '{'
Quoted 14 lines
(quoted diff) +14
-0+ printf("Usage:\n%s\n", cmdtp->usage); + return 1; + } + if (strcmp(argv[1], "1") == 0) { + led = (1 << 0); + } else if (strcmp(argv[1], "2") == 0) { + led = (1 << 1); + } else if (strcmp(argv[1], "3") == 0) { + led = (1 << 2); + } else if (strcmp(argv[1], "green") == 0) { + led = (1 << 0); + } else if (strcmp(argv[1], "yellow") == 0) { + led = (1 << 1); + } else if (strcmp(argv[1], "red") == 0) {
Review line 64
Quoted 10 lines
(quoted diff) +10
-0+ led = (1 << 2); + } else if (strcmp(argv[1], "all") == 0) { + led = 7; + } else { + printf ("Usage:\n%s\n", cmdtp->usage); + return 1; + } + + if (strcmp(argv[2], "off") == 0) { + if(led & 1) green_LED_off();
please use switch
Review line 68
Quoted 4 lines
(quoted diff) +4
-0+ if(led & 2) yellow_LED_off(); + if(led & 4) red_LED_off(); + } else if (strcmp(argv[2], "on") == 0) { + if(led & 1) green_LED_on();
please use switch
Quoted 91 lines
(quoted diff) +16
-0+ if(led & 2) yellow_LED_on(); + if(led & 4) red_LED_on(); + } else { + printf ("Usage:\n%s\n", cmdtp->usage); + return 1; + } + + return 0; +} + +U_BOOT_CMD( + led, 3, 1, do_led, + "led\t- [1|2|3|green|yellow|red|all] [on|off]\n", + "led [1|2|3|green|yellow|red|all] [on|off] sets /clears led 1,2,3\n" +); +diff -urN u-boot-2009.01-0rig//common/Makefile
u-boot-2009.01/common/Makefile
--- u-boot-2009.01-0rig//common/Makefile 2009-01-02 21:18:24.000000000
+0100
+++ u-boot-2009.01/common/Makefile 2009-01-03 23:41:53.000000000 +0100(quoted diff) +1
-0@@ -99,6 +99,7 @@ COBJS-$(CONFIG_CMD_IRQ) += cmd_irq.o COBJS-$(CONFIG_CMD_ITEST) += cmd_itest.o COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o +COBJS-$(CONFIG_CMD_LED) += cmd_led.o COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o COBJS-y += cmd_load.o COBJS-$(CONFIG_LOGBUFFER) += cmd_log.odiff -urN
u-boot-2009.01-0rig//include/coloured_led.hu-boot-2009.01/include/coloured_led.h
---u-boot-2009.01-0rig//include/coloured_led.h1970-01-01
01:00:00.000000000 +0100
+++u-boot-2009.01/include/coloured_led.h2009-01-03 23:39:19.000000000
+0100(quoted diff) +30
-0@@ -0,0 +1,62 @@ +#ifndef _COLOURED_LED_H_ +#define _COLOURED_LED_H_ + +#ifdef CONFIG_COLOURED_LED + +/* + * Coloured LEDs API + */ +#ifndef __ASSEMBLY__ +extern void coloured_LED_init (void); +extern void red_LED_on(void); +extern void red_LED_off(void); +extern void green_LED_on(void); +extern void green_LED_off(void); +extern void yellow_LED_on(void); +extern void yellow_LED_off(void); +#else + .extern LED_init + .extern red_LED_on + .extern red_LED_off + .extern yellow_LED_on + .extern yellow_LED_off + .extern green_LED_on + .extern green_LED_off +#endif + +#endif /* CONFIG_COLOURED_LED */ + +#endif /* _STATUS_COLOURED_H_ */ +diff -urN
u-boot-2009.01-0rig//include/status_led.hu-boot-2009.01/include/status_led.h
---u-boot-2009.01-0rig//include/status_led.h2008-12-16
23:48:27.000000000 +0100
+++u-boot-2009.01/include/status_led.h2009-01-03 23:44:40.000000000
+0100(quoted diff) +0
-14@@ -383,27 +383,6 @@ # include <asm/status_led.h> #endif -/* - * Coloured LEDs API - */ -#ifndef __ASSEMBLY__ -extern void coloured_LED_init (void); -extern void red_LED_on(void); -extern void red_LED_off(void); -extern void green_LED_on(void); -extern void green_LED_off(void); -extern void yellow_LED_on(void); -extern void yellow_LED_off(void); -#else - .extern LED_init - .extern red_LED_on
Review line 388
Quoted 10 lines
(quoted diff) +0
-7- .extern red_LED_off - .extern yellow_LED_on - .extern yellow_LED_off - .extern green_LED_on - .extern green_LED_off -#endif - #endif /* CONFIG_STATUS_LED */ #endif /* _STATUS_LED_H_ */
after ---
Quoted 3 lines
Best Regards
Ulf Samuelsson
please add a READMRE too
Best Regards,
J.