debug_gba.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2004 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /*
00035  * $Log: debug_gba.c,v $
00036  * Revision 1.5  2006/10/08 16:48:07  haraldkipp
00037  * Documentation fixed
00038  *
00039  * Revision 1.4  2006/04/07 12:08:18  haraldkipp
00040  * Compiler warning fixed.
00041  *
00042  * Revision 1.3  2005/10/24 17:59:19  haraldkipp
00043  * Use correct header file, arm, not gba.
00044  *
00045  * Revision 1.2  2005/08/02 17:46:45  haraldkipp
00046  * Major API documentation update.
00047  *
00048  * Revision 1.1  2005/07/26 18:02:26  haraldkipp
00049  * Moved from dev.
00050  *
00051  * Revision 1.3  2005/04/05 17:50:46  haraldkipp
00052  * Use register names in gba.h.
00053  *
00054  * Revision 1.2  2004/11/08 18:11:49  haraldkipp
00055  * Support for carriage return added.
00056  *
00057  * Revision 1.1  2004/10/03 18:39:12  haraldkipp
00058  * GBA debug output on screen
00059  *
00060  */
00061 
00062 #include <dev/debug.h>
00063 #include <arch/arm.h>
00064 
00065 #include <sys/device.h>
00066 #include <sys/file.h>
00067 
00072 
00073 #define PALRAM_BASE     0x05000000
00074 #define VIDRAM_BASE     0x06000000
00075 
00076 #define LCD_COLS    30  /* Visible display columns */
00077 #define LCD_ROWS    20  /* Visible display rows */
00078 
00079 #define LCD_MCOLS   32  /* Buffer memory columns */
00080 #define LCD_MROWS   64  /* Buffer memory rows */
00081 
00082 static u_short pos_x;       /* Current column */
00083 static u_short pos_y;       /* Current row */
00084 static u_short pos_vofs;    /* Vertical offset */
00085 
00086 static NUTFILE dbgfile;
00087 
00088 /* 8x8 character font, ASCII 32..127. */
00089 static u_char font8x8[]= {
00090     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00091     0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00,
00092     0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00093     0x28, 0x28, 0xFE, 0x28, 0xFE, 0x28, 0x28, 0x00,
00094     0x10, 0x7C, 0x80, 0x7C, 0x02, 0x7C, 0x10, 0x00,
00095     0xC2, 0xC4, 0x08, 0x10, 0x20, 0x46, 0x86, 0x00,
00096     0x60, 0x90, 0x60, 0x90, 0x88, 0x84, 0x7A, 0x00,
00097     0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00098     0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00,
00099     0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00,
00100     0x44, 0x28, 0x10, 0xFE, 0x10, 0x28, 0x44, 0x00,
00101     0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00,
00102     0x00, 0x00, 0x00, 0x00, 0x18, 0x08, 0x10, 0x00,
00103     0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00,
00104     0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00,
00105     0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00,
00106     0x7C, 0x86, 0x8A, 0x92, 0xA2, 0xC2, 0x7C, 0x00,
00107     0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00,
00108     0x7C, 0x82, 0x04, 0x08, 0x10, 0x20, 0xFE, 0x00,
00109     0x7C, 0x82, 0x02, 0x3C, 0x02, 0x82, 0x7C, 0x00,
00110     0x40, 0x40, 0x84, 0x84, 0xFE, 0x04, 0x04, 0x00,
00111     0xFE, 0x80, 0x80, 0xFC, 0x02, 0x82, 0x7C, 0x00,
00112     0x10, 0x20, 0x40, 0xFC, 0x82, 0x82, 0x7C, 0x00,
00113     0xFE, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x00,
00114     0x7C, 0x82, 0x82, 0x7C, 0x82, 0x82, 0x7C, 0x00,
00115     0x7C, 0x82, 0x82, 0x7E, 0x04, 0x08, 0x10, 0x00,
00116     0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
00117     0x00, 0x00, 0x10, 0x00, 0x10, 0x10, 0x20, 0x00,
00118     0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x00,
00119     0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0x00, 0x00,
00120     0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0x00,
00121     0x7C, 0x82, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00,
00122     0x7C, 0x82, 0xBE, 0xA2, 0xBE, 0x80, 0x7E, 0x00,
00123     0x10, 0x28, 0x44, 0x82, 0xFE, 0x82, 0x82, 0x00,
00124     0xFC, 0x82, 0x82, 0xFC, 0x82, 0x82, 0xFC, 0x00,
00125     0x7C, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7C, 0x00,
00126     0xFC, 0x82, 0x82, 0x82, 0x82, 0x82, 0xFC, 0x00,
00127     0xFE, 0x80, 0x80, 0xFC, 0x80, 0x80, 0xFE, 0x00,
00128     0xFE, 0x80, 0x80, 0xFC, 0x80, 0x80, 0x80, 0x00,
00129     0x7C, 0x82, 0x80, 0x8E, 0x82, 0x82, 0x7E, 0x00,
00130     0x82, 0x82, 0x82, 0xFE, 0x82, 0x82, 0x82, 0x00,
00131     0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00,
00132     0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x7C, 0x00,
00133     0x82, 0x8C, 0xB0, 0xC0, 0xB0, 0x8C, 0x82, 0x00,
00134     0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xFE, 0x00,
00135     0x82, 0xC6, 0xAA, 0x92, 0x82, 0x82, 0x82, 0x00,
00136     0x82, 0xC2, 0xA2, 0x92, 0x8A, 0x86, 0x82, 0x00,
00137     0x7C, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7C, 0x00,
00138     0xFC, 0x82, 0x82, 0xFC, 0x80, 0x80, 0x80, 0x00,
00139     0x7C, 0x82, 0x82, 0x82, 0x82, 0x84, 0x7A, 0x00,
00140     0xFC, 0x82, 0x82, 0xFC, 0x88, 0x84, 0x82, 0x00,
00141     0x7C, 0x82, 0x80, 0x7C, 0x02, 0x82, 0x7C, 0x00,
00142     0xFE, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
00143     0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7C, 0x00,
00144     0x82, 0x82, 0x82, 0x82, 0x44, 0x28, 0x10, 0x00,
00145     0x82, 0x82, 0x82, 0x92, 0x92, 0x54, 0x28, 0x00,
00146     0x82, 0x44, 0x28, 0x10, 0x28, 0x44, 0x82, 0x00,
00147     0x82, 0x82, 0x44, 0x28, 0x10, 0x10, 0x10, 0x00,
00148     0xFE, 0x04, 0x08, 0x10, 0x20, 0x40, 0xFE, 0x00,
00149     0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00,
00150     0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
00151     0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00,
00152     0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
00153     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00,
00154     0x20, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
00155     0x00, 0x00, 0x7E, 0x82, 0x82, 0x86, 0x7A, 0x00,
00156     0x80, 0x80, 0xFC, 0x82, 0x82, 0x82, 0xFC, 0x00,
00157     0x00, 0x00, 0x7E, 0x80, 0x80, 0x80, 0x7E, 0x00,
00158     0x02, 0x02, 0x7E, 0x82, 0x82, 0x82, 0x7E, 0x00,
00159     0x00, 0x00, 0x7C, 0x82, 0xFE, 0x80, 0x7C, 0x00,
00160     0x0E, 0x10, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x00,
00161     0x00, 0x00, 0x7E, 0x82, 0x7E, 0x02, 0x7C, 0x00,
00162     0x80, 0x80, 0xFC, 0x82, 0x82, 0x82, 0x82, 0x00,
00163     0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00,
00164     0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x70, 0x00,
00165     0x80, 0x80, 0x86, 0x98, 0xE0, 0x98, 0x86, 0x00,
00166     0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00,
00167     0x00, 0x00, 0xEC, 0x92, 0x92, 0x92, 0x82, 0x00,
00168     0x00, 0x00, 0xBC, 0xC2, 0x82, 0x82, 0x82, 0x00,
00169     0x00, 0x00, 0x7C, 0x82, 0x82, 0x82, 0x7C, 0x00,
00170     0x00, 0x00, 0xFC, 0x82, 0xFC, 0x80, 0x80, 0x00,
00171     0x00, 0x00, 0x7E, 0x82, 0x7E, 0x02, 0x02, 0x00,
00172     0x00, 0x00, 0xBE, 0xC0, 0x80, 0x80, 0x80, 0x00,
00173     0x00, 0x00, 0x7E, 0x80, 0x7C, 0x02, 0xFC, 0x00,
00174     0x10, 0x10, 0x7C, 0x10, 0x10, 0x10, 0x0C, 0x00,
00175     0x00, 0x00, 0x82, 0x82, 0x82, 0x86, 0x7A, 0x00,
00176     0x00, 0x00, 0x82, 0x82, 0x44, 0x28, 0x10, 0x00,
00177     0x00, 0x00, 0x92, 0x92, 0x92, 0x92, 0x6C, 0x00,
00178     0x00, 0x00, 0x82, 0x44, 0x38, 0x44, 0x82, 0x00,
00179     0x00, 0x00, 0x82, 0x82, 0x7E, 0x02, 0x7C, 0x00,
00180     0x00, 0x00, 0xFE, 0x0C, 0x30, 0xC0, 0xFE, 0x00,
00181     0x0C, 0x10, 0x10, 0x20, 0x10, 0x10, 0x0C, 0x00,
00182     0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
00183     0x60, 0x10, 0x10, 0x08, 0x10, 0x10, 0x60, 0x00,
00184     0x34, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00185     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
00186 };
00187 
00195 int DebugIOCtl(NUTDEVICE * dev, int req, void *conf)
00196 {
00197     return -1;
00198 }
00199 
00205 int DebugInit(NUTDEVICE * dev)
00206 {
00207     register u_char ch;
00208     u_short i;
00209     u_short j;
00210     u_short k;
00211     u_short *pal;
00212     u_short *vid;
00213 
00214     outw(REG_DISPCNT, 0x0400);
00215     outw(REG_BG2CNT, 0xA880);
00216 
00217     pal = (u_short *)PALRAM_BASE;
00218     for (i = 1; i < 256; i++) {
00219         pal[i] = 0x7FFF;
00220     }
00221     pal[0] = 0;
00222 
00223     vid = (u_short *)VIDRAM_BASE + 1024;
00224     for(i = 0; i < 96; i++) {
00225         for (j = 0; j < 8; j++) {
00226             ch = font8x8[i * 8 + j];
00227             for(k = 0; k < 4; k++) {
00228                 *vid++ = ((ch & 0x80) ? 1 : 0) | ((ch & 0x40) ? 0x0100 : 0);
00229                 ch *= 4;
00230             }
00231         }
00232     }
00233 
00234     return 0;
00235 }
00236 
00241 static void DebugPut(char ch)
00242 {
00243     u_char i;
00244     u_short *vid = (u_short *)(VIDRAM_BASE + 0x4000);
00245     u_short pos = 0;
00246 
00247     if (ch == '\r') {
00248         pos_x = 0;
00249     }
00250     else if (pos_x == LCD_COLS || ch == '\n') {
00251         pos_x = 0;
00252         pos_y++;
00253         if ((pos_y - pos_vofs) == LCD_ROWS) {
00254             pos_vofs++;
00255             outw(REG_BG2VOFS, (pos_vofs & (LCD_MROWS - 1)) * 8);
00256             if (pos_vofs >= LCD_MROWS && pos_y >= LCD_MROWS) {
00257                 pos_vofs -= LCD_MROWS;
00258                 pos_y -= LCD_MROWS;
00259             }
00260         }
00261         pos = (pos_y & (LCD_MROWS - 1)) * LCD_MCOLS;
00262         for(i = 0; i < LCD_COLS; i++) {
00263             vid[pos + i] = 32;
00264         }
00265     }
00266     else {
00267         pos = (pos_y & (LCD_MROWS - 1)) * LCD_MCOLS;
00268     }
00269     if (ch >= 32 && ch <= 127) {
00270         vid[pos + pos_x++] = ch;
00271     }
00272 }
00273 
00282 int DebugWrite(NUTFILE * fp, CONST void *buffer, int len)
00283 {
00284     int c = len;
00285     CONST char *cp = buffer;
00286 
00287     while(c--) {
00288         DebugPut(*cp++);
00289     }
00290     return len;
00291 }
00292 
00298 NUTFILE *DebugOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc)
00299 {
00300     dbgfile.nf_next = 0;
00301     dbgfile.nf_dev = dev;
00302     dbgfile.nf_fcb = 0;
00303 
00304     return &dbgfile;
00305 }
00306 
00312 int DebugClose(NUTFILE * fp)
00313 {
00314     return 0;
00315 }
00316 
00320 NUTDEVICE devDebug0 = {
00321     0,                          
00322     {'c', 'o', 'n', 0, 0, 0, 0, 0, 0},      
00323     0,                          
00324     0,                          
00325     0,                          
00326     0,                          
00327     0,                          
00328     DebugInit,                  
00329     DebugIOCtl,                 
00330     0,                          
00331     DebugWrite,                 
00332     DebugOpen,                  
00333     DebugClose,                 
00334     0                           
00335 };
00336 

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