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   if(ch == '\n') {
00104           while ((U0LSR & U0LSR_THRE) == 0);
00105           U0THR = '\r';
00106   }
00107   while ((U0LSR & U0LSR_THRE) == 0);
00108   U0THR = ch;
00109 }
00110 
00117 void DebugPut1(char ch)
00118 {
00119   if(ch == '\n') {
00120           while ((U1LSR & U1LSR_THRE) == 0);
00121           U1THR = '\r';
00122   }
00123   while ((U1LSR & U1LSR_THRE) == 0);
00124   U1THR = ch;
00125 }
00126 
00135 int DebugWrite(NUTFILE * fp, CONST void *buffer, int len)
00136 {
00137   int         c   = len;
00138   CONST char *cp  = buffer;
00139   NUTDEVICE  *dev = fp->nf_dev;
00140 
00141   if        (dev->dev_name[4] == '0') {
00142     while(c--)
00143       DebugPut0(*cp++);
00144   } else if (dev->dev_name[4] == '1') {
00145     while(c--)
00146       DebugPut1(*cp++);
00147   }
00148 
00149   return len;
00150 }
00151 
00157 NUTFILE *DebugOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc)
00158 {
00159   dbgfile.nf_next = 0;
00160   dbgfile.nf_dev = dev;
00161   dbgfile.nf_fcb = 0;
00162 
00163   return (&dbgfile);
00164 }
00165 
00171 int DebugClose(NUTFILE * fp)
00172 {
00173   return (0);
00174 }
00175 
00179 NUTDEVICE devDebug0 = {
00180   0,                          
00181   {'u', 'a', 'r', 't', '0', 0, 0, 0, 0},      
00182   0,                          
00183   0xFFFD0000,                 
00184   0,                          
00185   0,                          
00186   0,                          
00187   DebugInit,                  
00188   DebugIOCtl,                 
00189   0,                          
00190   DebugWrite,                 
00191   DebugOpen,                  
00192   DebugClose,                 
00193   0                           
00194 };
00195 
00199 NUTDEVICE devDebug1 = {
00200   0,                          
00201   {'u', 'a', 'r', 't', '1', 0, 0, 0, 0},      
00202   0,                          
00203   0xFFFCC000,                 
00204   0,                          
00205   0,                          
00206   0,                          
00207   DebugInit,                  
00208   DebugIOCtl,                 
00209   0,                          
00210   DebugWrite,                 
00211   DebugOpen,                  
00212   DebugClose,                 
00213   0                           
00214 };