00001
00007
00008
00009 #include <kernel.h>
00010 #include <gpio.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013
00023 command xsh_led(ushort stdin, ushort stdout, ushort stderr,
00024 ushort nargs, char *args[])
00025 {
00026 ulong led;
00027
00028
00029 if (nargs == 2 && strncmp(args[1],"--help",6) == 0)
00030 {
00031 fprintf(stdout, "Usage:led DESCRIPTOR STATE\n");
00032 fprintf(stdout, "Turns a specified led on or off.\n");
00033 fprintf(stdout, "\tDESCRIPTOR: dmz, wlan, power, ciscow, ciscoo\n");
00034 fprintf(stdout, "\tSTATE: on, off\n");
00035 fprintf(stdout, "\t--help\t display this help and exit\n");
00036 return OK;
00037 }
00038
00039
00040 if (nargs < 3)
00041 {
00042 fprintf(stderr,"led: missing operand\n");
00043 fprintf(stderr,"Try 'led --help' for more information\n");
00044 return SYSERR;
00045 }
00046 if (nargs > 3)
00047 {
00048 fprintf(stderr,"led: too many arguments\n");
00049 fprintf(stderr,"Try 'led --help' for more information\n");
00050 return SYSERR;
00051 }
00052
00053
00054 if (strncmp(args[1],"dmz",3) == 0) { led = GPIO_LED_DMZ; }
00055 else if (strncmp(args[1],"wlan",4) == 0) { led = GPIO_LED_WLAN; }
00056 else if (strncmp(args[1],"power",5) == 0) { led = GPIO1; }
00057 else if (strncmp(args[1],"ciscow",6) == 0) { led = GPIO_LED_CISCOWHT; }
00058 else if (strncmp(args[1],"ciscoo",6) == 0) { led = GPIO_LED_CISCOONG; }
00059 else
00060 {
00061 fprintf(stderr,"led: invalid DESCRIPTOR\n");
00062 fprintf(stderr,"Try 'led --help' for more information\n");
00063 }
00064
00065
00066 if (strncmp(args[2],"on",2) == 0) { GPIO_CTRL_LED_ON(led); }
00067 else if (strncmp(args[2],"off",3) == 0) { GPIO_CTRL_LED_OFF(led); }
00068 else
00069 {
00070 fprintf(stderr,"led: invalid STATE\n");
00071 fprintf(stderr,"Try 'led --help' for more information\n");
00072 }
00073
00074 return OK;
00075 }