00001
00007
00008
00009 #include <kernel.h>
00010 #include <gpio.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013
00024 command xsh_gpiostat(ushort stdin, ushort stdout, ushort stderr,
00025 ushort nargs, char *args[])
00026 {
00027 struct gpio_csreg *pgcsr;
00028 uchar p;
00029 ulong offset;
00030
00031
00032 if (nargs == 2 && strncmp(args[1],"--help",6) == 0)
00033 {
00034 fprintf(stdout, "Usage: gpiostat\n");
00035 fprintf(stdout, "Displays statitics for general purpose ");
00036 fprintf(stdout, "input/output pins.\n");
00037 fprintf(stdout, "\t--help\t display this help and exit\n");
00038 return SYSERR;
00039 }
00040
00041
00042 if (nargs > 1)
00043 {
00044 fprintf(stderr, "gpiostat: too many arguments\n");
00045 fprintf(stderr, "Try 'gpiostat --help' for more information.\n");
00046 return SYSERR;
00047 }
00048
00049
00050 pgcsr = (struct gpio_csreg *)GPIO_BASE;
00051
00052
00053 offset = 0;
00054
00055 fprintf(stdout, "PIN MODE INPUT OUTPUT CONTROL\n");
00056 fprintf(stdout, "--- ------ ------- ------- -------\n");
00057 for (p = 0; p < GPIO_PIN_COUNT; p++)
00058 {
00059 offset = 1 << p;
00060 fprintf(stdout, "%2d ", p);
00061 if (pgcsr->enable & offset)
00062 { fprintf(stdout, " Output "); }
00063 else
00064 { fprintf(stdout, " Input "); }
00065 fprintf(stdout, " %1d ", (pgcsr->input & offset) >> p);
00066 fprintf(stdout, " %1d ", (pgcsr->output & offset) >> p);
00067 fprintf(stdout, " %1d ", (pgcsr->control & offset) >> p);
00068 fprintf(stdout, "\n");
00069 }
00070
00071 return OK;
00072 }