00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <string.h>
00041
00042 #include <arch/arm/lpc2xxx.h>
00043 #include <dev/debug.h>
00044
00045 #include <sys/device.h>
00046 #include <sys/file.h>
00047
00048 static NUTFILE dbgfile;
00049
00057 int DebugIOCtl(NUTDEVICE * dev, int req, void *conf)
00058 {
00059 return -1;
00060 }
00061
00069 int DebugInit(NUTDEVICE * dev)
00070 {
00071 if (dev->dev_name[4] == '0') {
00072 U0LCR = _BV(7);
00073 U0DLL = 0x08;
00074 U0DLM = 0x00;
00075 U0LCR = 0x03;
00076 U0IER = 0x00;
00077 U0FCR = 0x00;
00078
00079 PINSEL0 |= 0x00000005;
00080
00081 } else if (dev->dev_name[4] == '1') {
00082 U1LCR = _BV(7);
00083 U1DLL = 0x08;
00084 U1DLM = 0x00;
00085 U1LCR = 0x03;
00086 U1IER = 0x00;
00087 U1FCR = 0x00;
00088
00089 PINSEL0 |= 0x00050000;
00090 }
00091
00092 return 0;
00093 }
00094
00101 void DebugPut0(char ch)
00102 {
00103 while ((U0LSR & U0LSR_THRE) == 0);
00104 U0THR = ch;
00105
00106 if(ch == '\n')
00107 DebugPut0('\r');
00108 }
00109
00116 void DebugPut1(char ch)
00117 {
00118 while ((U1LSR & U1LSR_THRE) == 0);
00119 U1THR = ch;
00120
00121 if(ch == '\n')
00122 DebugPut1('\r');
00123 }
00124
00133 int DebugWrite(NUTFILE * fp, CONST void *buffer, int len)
00134 {
00135 int c = len;
00136 CONST char *cp = buffer;
00137 NUTDEVICE *dev = fp->nf_dev;
00138
00139 if (dev->dev_name[4] == '0') {
00140 while(c--)
00141 DebugPut0(*cp++);
00142 } else if (dev->dev_name[4] == '1') {
00143 while(c--)
00144 DebugPut1(*cp++);
00145 }
00146
00147 return len;
00148 }
00149
00155 NUTFILE *DebugOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc)
00156 {
00157 dbgfile.nf_next = 0;
00158 dbgfile.nf_dev = dev;
00159 dbgfile.nf_fcb = 0;
00160
00161 return (&dbgfile);
00162 }
00163
00169 int DebugClose(NUTFILE * fp)
00170 {
00171 return (0);
00172 }
00173
00177 NUTDEVICE devDebug0 = {
00178 0,
00179 {'u', 'a', 'r', 't', '0', 0, 0, 0, 0},
00180 0,
00181 0xFFFD0000,
00182 0,
00183 0,
00184 0,
00185 DebugInit,
00186 DebugIOCtl,
00187 0,
00188 DebugWrite,
00189 DebugOpen,
00190 DebugClose,
00191 0
00192 };
00193
00197 NUTDEVICE devDebug1 = {
00198 0,
00199 {'u', 'a', 'r', 't', '1', 0, 0, 0, 0},
00200 0,
00201 0xFFFCC000,
00202 0,
00203 0,
00204 0,
00205 DebugInit,
00206 DebugIOCtl,
00207 0,
00208 DebugWrite,
00209 DebugOpen,
00210 DebugClose,
00211 0
00212 };