debug_at91.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2006 by egnite Software GmbH
00003  * Copyright (C) 2010 by egnite GmbH
00004  *
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. Neither the name of the copyright holders nor the names of
00017  *    contributors may be used to endorse or promote products derived
00018  *    from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00027  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00028  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00030  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * For additional information see http://www.ethernut.de/
00034  */
00035 
00045 #include <arch/arm/debug_at91.h>
00046 
00047 #include <dev/debug.h>
00048 #include <sys/timer.h>
00049 
00050 
00055 
00063 uint32_t At91BaudRateDiv(uint32_t baud)
00064 {
00065     return (NutArchClockGet(NUT_HWCLK_PERIPHERAL) / (8 * baud) + 1) / 2;
00066 }
00067 
00075 int At91DevDebugIOCtl(NUTDEVICE * dev, int req, void *conf)
00076 {
00077     if(req == UART_SETSPEED) {
00078         outr(dev->dev_base + US_BRGR_OFF, At91BaudRateDiv(*((uint32_t *)conf)));
00079         return 0;
00080     }
00081     return -1;
00082 }
00083 
00090 static void DebugPut(CONST NUTDEVICE * dev, char ch)
00091 {
00092     if (ch == '\n') {
00093         while ((inr(dev->dev_base + US_CSR_OFF) & US_TXRDY) == 0);
00094         outr(dev->dev_base + US_THR_OFF, '\r');
00095     }
00096     while ((inr(dev->dev_base + US_CSR_OFF) & US_TXRDY) == 0);
00097     outr(dev->dev_base + US_THR_OFF, ch);
00098 }
00099 
00108 int At91DevDebugWrite(NUTFILE * fp, CONST void *buffer, int len)
00109 {
00110     int c = len;
00111     CONST char *cp = buffer;
00112 
00113     while (c--) {
00114         DebugPut(fp->nf_dev, *cp++);
00115     }
00116     return len;
00117 }
00118 
00124 NUTFILE *At91DevDebugOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc)
00125 {
00126     NUTFILE *fp = (NUTFILE *) (dev->dev_dcb);
00127 
00128     fp->nf_next = 0;
00129     fp->nf_dev = dev;
00130     fp->nf_fcb = 0;
00131 
00132     return fp;
00133 }
00134 
00140 int At91DevDebugClose(NUTFILE * fp)
00141 {
00142     return 0;
00143 }
00144 

© 2000-2010 by contributors - visit http://www.ethernut.de/