Nut/OS  4.10.3
API Reference
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$
00036  * Revision 1.6  2008/08/11 06:59:07  haraldkipp
00037  * BSD types replaced by stdint types (feature request #1282721).
00038  *
00039  * Revision 1.5  2006/10/08 16:48:07  haraldkipp
00040  * Documentation fixed
00041  *
00042  * Revision 1.4  2006/04/07 12:08:18  haraldkipp
00043  * Compiler warning fixed.
00044  *
00045  * Revision 1.3  2005/10/24 17:59:19  haraldkipp
00046  * Use correct header file, arm, not gba.
00047  *
00048  * Revision 1.2  2005/08/02 17:46:45  haraldkipp
00049  * Major API documentation update.
00050  *
00051  * Revision 1.1  2005/07/26 18:02:26  haraldkipp
00052  * Moved from dev.
00053  *
00054  * Revision 1.3  2005/04/05 17:50:46  haraldkipp
00055  * Use register names in gba.h.
00056  *
00057  * Revision 1.2  2004/11/08 18:11:49  haraldkipp
00058  * Support for carriage return added.
00059  *
00060  * Revision 1.1  2004/10/03 18:39:12  haraldkipp
00061  * GBA debug output on screen
00062  *
00063  */
00064 
00065 #include <dev/debug.h>
00066 #include <arch/arm.h>
00067 
00068 #include <sys/device.h>
00069 #include <sys/file.h>
00070 
00075 
00076 #define PALRAM_BASE     0x05000000
00077 #define VIDRAM_BASE     0x06000000
00078 
00079 #define LCD_COLS    30  /* Visible display columns */
00080 #define LCD_ROWS    20  /* Visible display rows */
00081 
00082 #define LCD_MCOLS   32  /* Buffer memory columns */
00083 #define LCD_MROWS   64  /* Buffer memory rows */
00084 
00085 static uint16_t pos_x;       /* Current column */
00086 static uint16_t pos_y;       /* Current row */
00087 static uint16_t pos_vofs;    /* Vertical offset */
00088 
00089 static NUTFILE dbgfile;
00090 
00091 /* 8x8 character font, ASCII 32..127. */
00092 static uint8_t font8x8[]= {
00093     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00094     0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x00,
00095     0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00096     0x28, 0x28, 0xFE, 0x28, 0xFE, 0x28, 0x28, 0x00,
00097     0x10, 0x7C, 0x80, 0x7C, 0x02, 0x7C, 0x10, 0x00,
00098     0xC2, 0xC4, 0x08, 0x10, 0x20, 0x46, 0x86, 0x00,
00099     0x60, 0x90, 0x60, 0x90, 0x88, 0x84, 0x7A, 0x00,
00100     0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00101     0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00,
00102     0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00,
00103     0x44, 0x28, 0x10, 0xFE, 0x10, 0x28, 0x44, 0x00,
00104     0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00,
00105     0x00, 0x00, 0x00, 0x00, 0x18, 0x08, 0x10, 0x00,
00106     0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00,
00107     0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00,
00108     0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00,
00109     0x7C, 0x86, 0x8A, 0x92, 0xA2, 0xC2, 0x7C, 0x00,
00110     0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00,
00111     0x7C, 0x82, 0x04, 0x08, 0x10, 0x20, 0xFE, 0x00,
00112     0x7C, 0x82, 0x02, 0x3C, 0x02, 0x82, 0x7C, 0x00,
00113     0x40, 0x40, 0x84, 0x84, 0xFE, 0x04, 0x04, 0x00,
00114     0xFE, 0x80, 0x80, 0xFC, 0x02, 0x82, 0x7C, 0x00,
00115     0x10, 0x20, 0x40, 0xFC, 0x82, 0x82, 0x7C, 0x00,
00116     0xFE, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x00,
00117     0x7C, 0x82, 0x82, 0x7C, 0x82, 0x82, 0x7C, 0x00,
00118     0x7C, 0x82, 0x82, 0x7E, 0x04, 0x08, 0x10, 0x00,
00119     0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00,
00120     0x00, 0x00, 0x10, 0x00, 0x10, 0x10, 0x20, 0x00,
00121     0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x00,
00122     0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0x00, 0x00,
00123     0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0x00,
00124     0x7C, 0x82, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00,
00125     0x7C, 0x82, 0xBE, 0xA2, 0xBE, 0x80, 0x7E, 0x00,
00126     0x10, 0x28, 0x44, 0x82, 0xFE, 0x82, 0x82, 0x00,
00127     0xFC, 0x82, 0x82, 0xFC, 0x82, 0x82, 0xFC, 0x00,
00128     0x7C, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7C, 0x00,
00129     0xFC, 0x82, 0x82, 0x82, 0x82, 0x82, 0xFC, 0x00,
00130     0xFE, 0x80, 0x80, 0xFC, 0x80, 0x80, 0xFE, 0x00,
00131     0xFE, 0x80, 0x80, 0xFC, 0x80, 0x80, 0x80, 0x00,
00132     0x7C, 0x82, 0x80, 0x8E, 0x82, 0x82, 0x7E, 0x00,
00133     0x82, 0x82, 0x82, 0xFE, 0x82, 0x82, 0x82, 0x00,
00134     0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00,
00135     0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x7C, 0x00,
00136     0x82, 0x8C, 0xB0, 0xC0, 0xB0, 0x8C, 0x82, 0x00,
00137     0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xFE, 0x00,
00138     0x82, 0xC6, 0xAA, 0x92, 0x82, 0x82, 0x82, 0x00,
00139     0x82, 0xC2, 0xA2, 0x92, 0x8A, 0x86, 0x82, 0x00,
00140     0x7C, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7C, 0x00,
00141     0xFC, 0x82, 0x82, 0xFC, 0x80, 0x80, 0x80, 0x00,
00142     0x7C, 0x82, 0x82, 0x82, 0x82, 0x84, 0x7A, 0x00,
00143     0xFC, 0x82, 0x82, 0xFC, 0x88, 0x84, 0x82, 0x00,
00144     0x7C, 0x82, 0x80, 0x7C, 0x02, 0x82, 0x7C, 0x00,
00145     0xFE, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
00146     0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7C, 0x00,
00147     0x82, 0x82, 0x82, 0x82, 0x44, 0x28, 0x10, 0x00,
00148     0x82, 0x82, 0x82, 0x92, 0x92, 0x54, 0x28, 0x00,
00149     0x82, 0x44, 0x28, 0x10, 0x28, 0x44, 0x82, 0x00,
00150     0x82, 0x82, 0x44, 0x28, 0x10, 0x10, 0x10, 0x00,
00151     0xFE, 0x04, 0x08, 0x10, 0x20, 0x40, 0xFE, 0x00,
00152     0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00,
00153     0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
00154     0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00,
00155     0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
00156     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00,
00157     0x20, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
00158     0x00, 0x00, 0x7E, 0x82, 0x82, 0x86, 0x7A, 0x00,
00159     0x80, 0x80, 0xFC, 0x82, 0x82, 0x82, 0xFC, 0x00,
00160     0x00, 0x00, 0x7E, 0x80, 0x80, 0x80, 0x7E, 0x00,
00161     0x02, 0x02, 0x7E, 0x82, 0x82, 0x82, 0x7E, 0x00,
00162     0x00, 0x00, 0x7C, 0x82, 0xFE, 0x80, 0x7C, 0x00,
00163     0x0E, 0x10, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x00,
00164     0x00, 0x00, 0x7E, 0x82, 0x7E, 0x02, 0x7C, 0x00,
00165     0x80, 0x80, 0xFC, 0x82, 0x82, 0x82, 0x82, 0x00,
00166     0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00,
00167     0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x70, 0x00,
00168     0x80, 0x80, 0x86, 0x98, 0xE0, 0x98, 0x86, 0x00,
00169     0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00,
00170     0x00, 0x00, 0xEC, 0x92, 0x92, 0x92, 0x82, 0x00,
00171     0x00, 0x00, 0xBC, 0xC2, 0x82, 0x82, 0x82, 0x00,
00172     0x00, 0x00, 0x7C, 0x82, 0x82, 0x82, 0x7C, 0x00,
00173     0x00, 0x00, 0xFC, 0x82, 0xFC, 0x80, 0x80, 0x00,
00174     0x00, 0x00, 0x7E, 0x82, 0x7E, 0x02, 0x02, 0x00,
00175     0x00, 0x00, 0xBE, 0xC0, 0x80, 0x80, 0x80, 0x00,
00176     0x00, 0x00, 0x7E, 0x80, 0x7C, 0x02, 0xFC, 0x00,
00177     0x10, 0x10, 0x7C, 0x10, 0x10, 0x10, 0x0C, 0x00,
00178     0x00, 0x00, 0x82, 0x82, 0x82, 0x86, 0x7A, 0x00,
00179     0x00, 0x00, 0x82, 0x82, 0x44, 0x28, 0x10, 0x00,
00180     0x00, 0x00, 0x92, 0x92, 0x92, 0x92, 0x6C, 0x00,
00181     0x00, 0x00, 0x82, 0x44, 0x38, 0x44, 0x82, 0x00,
00182     0x00, 0x00, 0x82, 0x82, 0x7E, 0x02, 0x7C, 0x00,
00183     0x00, 0x00, 0xFE, 0x0C, 0x30, 0xC0, 0xFE, 0x00,
00184     0x0C, 0x10, 0x10, 0x20, 0x10, 0x10, 0x0C, 0x00,
00185     0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
00186     0x60, 0x10, 0x10, 0x08, 0x10, 0x10, 0x60, 0x00,
00187     0x34, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
00188     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
00189 };
00190 
00198 int DebugIOCtl(NUTDEVICE * dev, int req, void *conf)
00199 {
00200     return -1;
00201 }
00202 
00208 int DebugInit(NUTDEVICE * dev)
00209 {
00210     register uint8_t ch;
00211     uint_fast16_t i;
00212     uint_fast16_t j;
00213     uint_fast16_t k;
00214     uint16_t *pal;
00215     uint16_t *vid;
00216 
00217     outw(REG_DISPCNT, 0x0400);
00218     outw(REG_BG2CNT, 0xA880);
00219 
00220     pal = (uint16_t *)PALRAM_BASE;
00221     for (i = 1; i < 256; i++) {
00222         pal[i] = 0x7FFF;
00223     }
00224     pal[0] = 0;
00225 
00226     vid = (uint16_t *)VIDRAM_BASE + 1024;
00227     for(i = 0; i < 96; i++) {
00228         for (j = 0; j < 8; j++) {
00229             ch = font8x8[i * 8 + j];
00230             for(k = 0; k < 4; k++) {
00231                 *vid++ = ((ch & 0x80) ? 1 : 0) | ((ch & 0x40) ? 0x0100 : 0);
00232                 ch *= 4;
00233             }
00234         }
00235     }
00236 
00237     return 0;
00238 }
00239 
00244 static void DebugPut(char ch)
00245 {
00246     uint8_t i;
00247     uint16_t *vid = (uint16_t *)(VIDRAM_BASE + 0x4000);
00248     uint16_t pos = 0;
00249 
00250     if (ch == '\r') {
00251         pos_x = 0;
00252     }
00253     else if (pos_x == LCD_COLS || ch == '\n') {
00254         pos_x = 0;
00255         pos_y++;
00256         if ((pos_y - pos_vofs) == LCD_ROWS) {
00257             pos_vofs++;
00258             outw(REG_BG2VOFS, (pos_vofs & (LCD_MROWS - 1)) * 8);
00259             if (pos_vofs >= LCD_MROWS && pos_y >= LCD_MROWS) {
00260                 pos_vofs -= LCD_MROWS;
00261                 pos_y -= LCD_MROWS;
00262             }
00263         }
00264         pos = (pos_y & (LCD_MROWS - 1)) * LCD_MCOLS;
00265         for(i = 0; i < LCD_COLS; i++) {
00266             vid[pos + i] = 32;
00267         }
00268     }
00269     else {
00270         pos = (pos_y & (LCD_MROWS - 1)) * LCD_MCOLS;
00271     }
00272     if (ch >= 32 && ch <= 127) {
00273         vid[pos + pos_x++] = ch;
00274     }
00275 }
00276 
00285 int DebugWrite(NUTFILE * fp, CONST void *buffer, int len)
00286 {
00287     int c = len;
00288     CONST char *cp = buffer;
00289 
00290     while(c--) {
00291         DebugPut(*cp++);
00292     }
00293     return len;
00294 }
00295 
00301 NUTFILE *DebugOpen(NUTDEVICE * dev, CONST char *name, int mode, int acc)
00302 {
00303     dbgfile.nf_next = 0;
00304     dbgfile.nf_dev = dev;
00305     dbgfile.nf_fcb = 0;
00306 
00307     return &dbgfile;
00308 }
00309 
00315 int DebugClose(NUTFILE * fp)
00316 {
00317     return 0;
00318 }
00319 
00323 NUTDEVICE devDebug0 = {
00324     0,                          
00325     {'c', 'o', 'n', 0, 0, 0, 0, 0, 0},      
00326     0,                          
00327     0,                          
00328     0,                          
00329     0,                          
00330     0,                          
00331     DebugInit,                  
00332     DebugIOCtl,                 
00333     0,                          
00334     DebugWrite,                 
00335     DebugOpen,                  
00336     DebugClose,                 
00337     0                           
00338 };
00339