2002-04-20 23:01:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "sh7034.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2002-04-30 19:43:54 +00:00
|
|
|
#include "config.h"
|
2002-04-20 23:01:30 +00:00
|
|
|
|
|
|
|
char debugmembuf[100];
|
|
|
|
char debugbuf[200];
|
|
|
|
|
2002-05-06 11:25:44 +00:00
|
|
|
#ifndef SIMULATOR /* allow non archos platforms to display output */
|
2002-04-30 19:43:54 +00:00
|
|
|
|
2002-05-17 19:48:27 +00:00
|
|
|
void debug_init(void)
|
|
|
|
{
|
|
|
|
/* Clear it all! */
|
|
|
|
SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER);
|
|
|
|
|
|
|
|
/* This enables the serial Rx interrupt, to be able to exit into the
|
|
|
|
debugger when you hit CTRL-C */
|
|
|
|
SCR1 |= 0x40;
|
|
|
|
SCR1 &= ~0x80;
|
|
|
|
IPRE |= 0xf000; /* Set to highest priority */
|
|
|
|
}
|
|
|
|
|
2002-04-20 23:01:30 +00:00
|
|
|
static int debug_tx_ready(void)
|
|
|
|
{
|
2002-05-02 11:44:15 +00:00
|
|
|
return (SSR1 & SCI_TDRE);
|
2002-04-20 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_tx_char(char ch)
|
|
|
|
{
|
|
|
|
while (!debug_tx_ready())
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write data into TDR and clear TDRE
|
|
|
|
*/
|
|
|
|
TDR1 = ch;
|
|
|
|
SSR1 &= ~SCI_TDRE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_handle_error(char ssr)
|
|
|
|
{
|
|
|
|
SSR1 &= ~(SCI_ORER | SCI_PER | SCI_FER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int debug_rx_ready(void)
|
|
|
|
{
|
|
|
|
char ssr;
|
|
|
|
|
|
|
|
ssr = SSR1 & ( SCI_PER | SCI_FER | SCI_ORER );
|
|
|
|
if ( ssr )
|
|
|
|
debug_handle_error ( ssr );
|
|
|
|
return SSR1 & SCI_RDRF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char debug_rx_char(void)
|
|
|
|
{
|
|
|
|
char ch;
|
|
|
|
char ssr;
|
|
|
|
|
|
|
|
while (!debug_rx_ready())
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
ch = RDR1;
|
|
|
|
SSR1 &= ~SCI_RDRF;
|
|
|
|
|
|
|
|
ssr = SSR1 & (SCI_PER | SCI_FER | SCI_ORER);
|
|
|
|
|
|
|
|
if (ssr)
|
|
|
|
debug_handle_error (ssr);
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char hexchars[] = "0123456789abcdef";
|
|
|
|
|
|
|
|
static char highhex(int x)
|
|
|
|
{
|
|
|
|
return hexchars[(x >> 4) & 0xf];
|
|
|
|
}
|
|
|
|
|
|
|
|
static char lowhex(int x)
|
|
|
|
{
|
|
|
|
return hexchars[x & 0xf];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void putpacket (char *buffer)
|
|
|
|
{
|
|
|
|
register int checksum;
|
|
|
|
|
|
|
|
char *src = buffer;
|
2002-04-23 13:41:18 +00:00
|
|
|
|
|
|
|
/* Special debug hack. Shut off the Rx IRQ during I/O to prevent the debug
|
|
|
|
stub from interrupting the message */
|
|
|
|
SCR1 &= ~0x40;
|
|
|
|
|
2002-04-20 23:01:30 +00:00
|
|
|
debug_tx_char ('$');
|
|
|
|
checksum = 0;
|
|
|
|
|
|
|
|
while (*src)
|
|
|
|
{
|
|
|
|
int runlen;
|
|
|
|
|
|
|
|
/* Do run length encoding */
|
|
|
|
for (runlen = 0; runlen < 100; runlen ++)
|
|
|
|
{
|
|
|
|
if (src[0] != src[runlen])
|
|
|
|
{
|
|
|
|
if (runlen > 3)
|
|
|
|
{
|
|
|
|
int encode;
|
|
|
|
/* Got a useful amount */
|
|
|
|
debug_tx_char (*src);
|
|
|
|
checksum += *src;
|
|
|
|
debug_tx_char ('*');
|
|
|
|
checksum += '*';
|
|
|
|
checksum += (encode = runlen + ' ' - 4);
|
|
|
|
debug_tx_char (encode);
|
|
|
|
src += runlen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug_tx_char (*src);
|
|
|
|
checksum += *src;
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
debug_tx_char ('#');
|
|
|
|
debug_tx_char (highhex(checksum));
|
|
|
|
debug_tx_char (lowhex(checksum));
|
|
|
|
|
|
|
|
/* Wait for the '+' */
|
|
|
|
debug_rx_char();
|
2002-04-23 13:41:18 +00:00
|
|
|
|
|
|
|
/* Special debug hack. Enable the IRQ again */
|
|
|
|
SCR1 |= 0x40;
|
2002-04-20 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* convert the memory, pointed to by mem into hex, placing result in buf */
|
|
|
|
/* return a pointer to the last char put in buf (null) */
|
|
|
|
static char *mem2hex (char *mem, char *buf, int count)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ch;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
ch = *mem++;
|
|
|
|
*buf++ = highhex (ch);
|
|
|
|
*buf++ = lowhex (ch);
|
|
|
|
}
|
|
|
|
*buf = 0;
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
2002-05-02 14:05:51 +00:00
|
|
|
static void debug(char *msg)
|
2002-04-20 23:01:30 +00:00
|
|
|
{
|
|
|
|
debugbuf[0] = 'O';
|
|
|
|
|
|
|
|
mem2hex(msg, &debugbuf[1], strlen(msg));
|
|
|
|
putpacket(debugbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void debugf(char *fmt, ...)
|
|
|
|
{
|
2002-05-02 14:05:51 +00:00
|
|
|
#ifdef DEBUG
|
2002-04-20 23:01:30 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2002-05-02 11:44:15 +00:00
|
|
|
vsnprintf(debugmembuf, sizeof(debugmembuf), fmt, ap);
|
2002-04-20 23:01:30 +00:00
|
|
|
va_end(ap);
|
|
|
|
debug(debugmembuf);
|
2002-05-02 14:05:51 +00:00
|
|
|
#endif
|
2002-04-20 23:01:30 +00:00
|
|
|
}
|
2002-04-30 19:43:54 +00:00
|
|
|
|
2002-05-06 11:25:44 +00:00
|
|
|
#else /* SIMULATOR code coming up */
|
2002-04-30 19:43:54 +00:00
|
|
|
|
2002-05-17 19:48:27 +00:00
|
|
|
void debug_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-04-30 19:43:54 +00:00
|
|
|
void debugf(char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start( ap, fmt );
|
2002-05-02 11:44:15 +00:00
|
|
|
vsnprintf( debugmembuf, sizeof(debugmembuf), fmt, ap );
|
2002-04-30 19:43:54 +00:00
|
|
|
va_end( ap );
|
2002-05-06 11:25:44 +00:00
|
|
|
printf( "%s", debugmembuf );
|
2002-04-30 19:43:54 +00:00
|
|
|
}
|
|
|
|
#endif
|