Nut/OS  4.10.3
API Reference
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   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 };