00001
00007
00008
00009 #include <kernel.h>
00010 #include <proc.h>
00011 #include <device.h>
00012 #include <uart.h>
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include <stdlib.h>
00016
00017 local uartStat(ushort, ushort, ushort, ushort);
00018
00028 command xsh_uartstat(ushort stdin, ushort stdout, ushort stderr,
00029 ushort nargs, char *args[])
00030 {
00031 ushort dev;
00032 char n;
00033
00034
00035 if (nargs == 2 && strncmp(args[1],"--help",6) == 0)
00036 {
00037 fprintf(stdout, "Usage: uartstat UARTNUM\n");
00038 fprintf(stdout, "Displays statistics for uart UARTNUM.\n");
00039 fprintf(stdout, "\t--help\t display this help and exit\n");
00040 return OK;
00041 }
00042
00043
00044 if (nargs < 2)
00045 {
00046 for ( n = 0; n < NUART; n++ )
00047 { uartStat( stdin, stdout, stderr, n ); }
00048
00049 return OK;
00050 }
00051
00052 if (nargs > 2)
00053 {
00054 fprintf(stderr, "uartstat: too many arguments\n");
00055 fprintf(stderr, "Try 'uartstat --help' for more information\n");
00056 return SYSERR;
00057 }
00058
00059
00060 dev = (ushort)atol(args[1]);
00061 if ( dev >= NUART )
00062 {
00063 fprintf(stderr, "uartstat: (%d) No such uart\n",dev);
00064 return SYSERR;
00065 }
00066
00067 uartStat( stdin, stdout, stderr, dev );
00068
00069 return OK;
00070 }
00071
00072 local uartStat(ushort stdin, ushort stdout, ushort stderr, ushort dev)
00073 {
00074 struct uart *uptr;
00075 struct uart_csreg *ucptr;
00076 char *label[2] = { "OFF", "ON " };
00077
00078
00079 uptr = &uarttab[dev];
00080 ucptr = uptr->csr;
00081
00082 fprintf(stdout, "uart%d:\n", dev);
00083
00084
00085 fprintf(stdout, "\tSTATISTICS:\n");
00086 fprintf(stdout, "\t------------------------------------------\n");
00087 fprintf(stdout, "\t%8d Characters Output\n", uptr->cout);
00088 fprintf(stdout, "\t%8d Characters Input\n", uptr->cin);
00089 fprintf(stdout, "\t%8d Characters Overrun\n", uptr->ovrrn);
00090 fprintf(stdout, "\t%8d Receiver Error Count\n", uptr->lserr);
00091 fprintf(stdout, "\t%8d Output IRQ Count\n", uptr->oirq);
00092 fprintf(stdout, "\t%8d Input IRQ Count\n", uptr->iirq);
00093
00094
00095 int enabled;
00096 fprintf(stdout, "\n\tINTERRUPT ENABLE:\n");
00097 fprintf(stdout, "\t------------------------------------------\n");
00098
00099 enabled = (ucptr->ier & UART_IER_ERBFI) ? 1 : 0;
00100 fprintf(stdout, "\t%s Receiver FIFO Reached Trigger Level\n",
00101 label[enabled]);
00102
00103 enabled = (ucptr->ier & UART_IER_ETBEI) ? 1 : 0;
00104 fprintf(stdout, "\t%s Transmitter FIFO Empty\n", label[enabled]);
00105
00106 enabled = (ucptr->ier & UART_IER_ELSI) ? 1 : 0;
00107 fprintf(stdout, "\t%s Receiver Error or BREAK\n", label[enabled]);
00108
00109 enabled = (ucptr->ier & UART_IER_EMSI) ? 1 : 0;
00110 fprintf(stdout, "\t%s Modem Status", label[enabled]);
00111
00112 fprintf(stdout, "\n");
00113 return OK;
00114 }