debug_lpc2xxx.c

Go to the documentation of this file.
00001 /****************************************************************************
00002 *  This file is part of the Ethernut port for the LPC2XXX
00003 *
00004 *  Copyright (c) 2005 by Michael Fischer. All rights reserved.
00005 *
00006 *  Redistribution and use in source and binary forms, with or without 
00007 *  modification, are permitted provided that the following conditions 
00008 *  are met:
00009 *  
00010 *  1. Redistributions of source code must retain the above copyright 
00011 *     notice, this list of conditions and the following disclaimer.
00012 *  2. Redistributions in binary form must reproduce the above copyright
00013 *     notice, this list of conditions and the following disclaimer in the 
00014 *     documentation and/or other materials provided with the distribution.
00015 *  3. Neither the name of the author nor the names of its contributors may 
00016 *     be used to endorse or promote products derived from this software 
00017 *     without specific prior written permission.
00018 *
00019 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00020 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00021 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
00022 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00023 *  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
00024 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
00025 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
00026 *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
00027 *  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
00028 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
00029 *  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00030 *  SUCH DAMAGE.
00031 *
00032 ****************************************************************************
00033 *
00034 *  History:
00035 *
00036 *  24.09.05  mifi   First Version
00037 *                   The CrossWorks for ARM toolchain will be used.
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 };

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/